Skip to content

Instantly share code, notes, and snippets.

@jackbravo
Created January 27, 2025 23:23
Show Gist options
  • Select an option

  • Save jackbravo/520500b653d2ccdbafec61e37a84bf61 to your computer and use it in GitHub Desktop.

Select an option

Save jackbravo/520500b653d2ccdbafec61e37a84bf61 to your computer and use it in GitHub Desktop.
Export embeddings (vector) table from duckdb to sqlite (sqlite-vec)
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