fix(db): use sqlite_vec.load(conn) instead of loadable_path()

loadable_path() returns a path without .dll extension on Windows,
causing vec0 extension loading to fail. Use sqlite_vec.load(conn)
which handles platform-specific paths correctly.
This commit is contained in:
LLLin000 2026-07-10 02:47:58 +08:00
parent 4ff165ae49
commit 745c3dd1e1

View file

@ -40,30 +40,19 @@ def ensure_vec_extension(conn: sqlite3.Connection) -> None:
Enables vec0 virtual table support for vector similarity search.
Gracefully no-ops when the extension is not installed.
Supports Python 3.12/3.13 (conn.load) and 3.14+ (conn.load_extension).
"""
try:
import sqlite_vec
conn.enable_load_extension(True)
# Python 3.12/3.13 API — searches system library path
try:
conn.load("vec0")
return
except AttributeError:
pass # conn.load removed in Python 3.14
# Python 3.14+ — use sqlite_vec convenience wrapper or direct path
try:
from sqlite_vec import loadable_path
conn.load_extension(str(loadable_path()))
except ImportError:
conn.load_extension("vec0")
except (sqlite3.OperationalError, AttributeError):
pass # extension not available
finally:
try:
conn.enable_load_extension(False)
except AttributeError:
pass
sqlite_vec.load(conn)
except Exception:
pass # extension not available
finally:
try:
conn.enable_load_extension(False)
except AttributeError:
pass
except ImportError:
pass # sqlite_vec not installed