Created
January 27, 2025 23:23
-
-
Save jackbravo/520500b653d2ccdbafec61e37a84bf61 to your computer and use it in GitHub Desktop.
Export embeddings (vector) table from duckdb to sqlite (sqlite-vec)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| import duckdb | |
| from sqlite_vec import load, serialize_float32 | |
| duck = duckdb.connect(database="../esc-ai-chat/public.duckdb", read_only=True) | |
| lite = sqlite3.connect("public.sqlite", autocommit=True) | |
| lite.enable_load_extension(True) | |
| load(lite) | |
| lite.enable_load_extension(False) | |
| result = duck.execute("SELECT id, question, category, embedding FROM questions") | |
| while True: | |
| row = result.fetchone() | |
| if row is None: | |
| break | |
| id, question, category, embedding = row | |
| lite.execute( | |
| """ | |
| INSERT INTO questions (id, question, category, embedding) | |
| VALUES (?, ?, ?, ?) | |
| """, | |
| (id, question, category, serialize_float32(embedding)), | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment