mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
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:
parent
4ff165ae49
commit
745c3dd1e1
1 changed files with 12 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue