Skip to content

Commit 3266de4

Browse files
CopilotMte90
andauthored
Fix sqlite-vector extension not loading on subsequent connections (#15)
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 8eec013 commit 3266de4

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

db/vector_operations.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# Retry policy for DB-locked operations
2222
DB_LOCK_RETRY_COUNT = 6
2323
DB_LOCK_RETRY_BASE_DELAY = 0.05 # seconds, exponential backoff multiplier
24-
_sqlite_vector_loaded = False
2524

2625

2726
def connect_db(db_path: str, timeout: float = 30.0) -> sqlite3.Connection:
@@ -53,26 +52,19 @@ def load_sqlite_vector_extension(conn: sqlite3.Connection) -> None:
5352
CRITICAL: This function will ALWAYS crash the program if the extension fails to load.
5453
STRICT mode is mandatory and cannot be disabled.
5554
55+
NOTE: SQLite extensions are loaded per-connection, not per-process. This function must be
56+
called for each connection that needs vector operations.
57+
5658
Args:
5759
conn: SQLite database connection
5860
5961
Raises:
6062
RuntimeError: If the extension fails to load
6163
"""
62-
global _sqlite_vector_loaded
63-
64-
if _sqlite_vector_loaded:
65-
logger.debug("sqlite-vector: already loaded in-process, skipping load.")
66-
return
67-
6864
try:
6965
ext_path = importlib.resources.files(SQLITE_VECTOR_PKG) / SQLITE_VECTOR_RESOURCE
7066
conn.load_extension(str(ext_path))
71-
_sqlite_vector_loaded = True
72-
try:
73-
conn.enable_load_extension(False)
74-
except Exception:
75-
pass
67+
logger.debug(f"sqlite-vector extension loaded for connection {id(conn)}")
7668
# optional quick check: call vector_version()
7769
try:
7870
cur = conn.execute(f"SELECT {SQLITE_VECTOR_VERSION_FN}()")

0 commit comments

Comments
 (0)