Fix sqlite-vector extension not loading on subsequent connections #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SQLite extensions are per-connection, but
load_sqlite_vector_extension()used a process-wide flag to skip loading after the first call. This causedvector_initandvector_as_f32to fail with "no such function" errors on all connections created after the initial one.Changes
_sqlite_vector_loadedflag and early-return guardconn.enable_load_extension(False)call that prevented re-loadingBefore
After
Original prompt
2025-11-11 11:12:54,125 - main - INFO - Testing sqlite-vector extension loading...
2025-11-11 11:12:54,126 - main - INFO - ✓ sqlite-vector extension loaded successfully
2025-11-11 11:12:54,126 - main - INFO - ✓ debug enabled
2025-11-11 11:12:54,127 - main - INFO - FileWatcher initialized (debounce=5s, interval=10s, enabled=True)
2025-11-11 11:12:54,128 - main - INFO - Now watching project 932da221a287b498 at /home/mte90/Desktop/Prog/PicoCode
2025-11-11 11:12:54,129 - main - INFO - FileWatcher loop started
2025-11-11 11:12:54,129 - main - INFO - FileWatcher started
2025-11-11 11:12:54,129 - main - INFO - FileWatcher started successfully
2025-11-11 11:12:54,130 - main - INFO - Detected 1 changed file(s) in project 932da221a287b498
2025-11-11 11:13:00,998 - db.operations - INFO - Created project 932da221a287b498 at /home/mte90/.picocode/projects/932da221a287b498.db
2025-11-11 11:13:01,173 - ai.analyzer - INFO - Starting indexing for project at: /home/mte90/Desktop/Prog/PicoCode/
2025-11-11 11:13:01,173 - ai.analyzer - INFO - Collecting files to index...
2025-11-11 11:13:01,317 - ai.analyzer - INFO - Found 12335 files to process
2025-11-11 11:13:01,319 - ai.analyzer - INFO - Processing file (3/12335): copilot-instructions.md
2025-11-11 11:13:01,320 - ai.analyzer - INFO - Processing file (4/12335): REST_API.md
2025-11-11 11:13:01,322 - db.db_writer - INFO - DBWriter started for database: /home/mte90/.picocode/projects/932da221a287b498.db
2025-11-11 11:13:01,323 - ai.analyzer - INFO - Processing file (8/12335): README.md
2025-11-11 11:13:01,323 - ai.analyzer - INFO - Processing file (5/12335): main.py
2025-11-11 11:13:01,394 - ai.analyzer - INFO - Generating embeddings for REST_API.md: batch 1/1 (14 chunks)
2025-11-11 11:13:01,405 - ai.analyzer - INFO - Generating embeddings for copilot-instructions.md: batch 1/1 (7 chunks)
2025-11-11 11:13:01,405 - ai.analyzer - INFO - Generating embeddings for README.md: batch 1/1 (5 chunks)
2025-11-11 11:13:01,413 - ai.analyzer - INFO - Generating embeddings for main.py: batch 1/1 (9 chunks)
2025-11-11 11:13:01,758 - ai.analyzer.embedding - INFO - Embedding succeeded
2025-11-11 11:13:01,810 - ai.analyzer.embedding - INFO - Embedding succeeded
2025-11-11 11:13:01,812 - ai.analyzer.embedding - INFO - Embedding succeeded
2025-11-11 11:13:01,814 - ai.analyzer.embedding - INFO - Embedding succeeded
2025-11-11 11:13:01,860 - db.vector_operations - INFO - Initialized vector dimension: 4096
2025-11-11 11:13:01,860 - db.vector_operations - ERROR - vector_init failed: no such function: vector_init
Failed to insert chunk vector: vector_init failed: no such function: vector_init
Traceback:
Traceback (most recent call last):
File "/home/mte90/Desktop/Prog/PicoCode/db/vector_operations.py", line 163, in insert_chunk_vector_with_retry
conn.execute(f"SELECT vector_init('chunks', 'embedding', 'dimension={dim},type=FLOAT32,distance=COSINE')")
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such function: vector_init
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mte90/Desktop/Prog/PicoCode/ai/analyzer.py", line 304, in _process_file_sync
_insert_chunk_vector_with_retry(conn2, fid, rel_path, idx, emb)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mte90/Desktop/Prog/PicoCode/db/vector_operations.py", line 167, in insert_chunk_vector_with_retry
raise RuntimeError(f"vector_init failed: {e}") from e
RuntimeError: vector_init failed: no such function: vector_init
2025-11-11 11:13:01,864 - db.vector_operations - ERROR - Failed to insert chunk vector after 0 retries: no such function: vector_as_f32
Failed to insert chunk vector: Failed to INSERT chunk vector (vector_as_f32 call): no such function: vector_as_f32
Traceback:
Traceback (most recent call last):
File "/home/mte90/Desktop/Prog/PicoCode/db/vector_operations.py", line 180, in insert_chunk_vector_with_retry
cur.execute("INSERT INTO chunks (file_id, path, chunk_index, embedding) VALUES (?, ?, ?, vector_as_f32(?))",
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(file_id, path, chunk_index, q_vec))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such function: vector_as_f32
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mte90/Desktop/Prog/PicoCode/ai/analyzer.py", line 304, in _process_file_sync
_insert_chunk_vector_with_retry(conn2, fid, rel_path, idx, emb)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mte90/Desktop/Prog/PicoCode/db/vector_operations.py", line 196, in insert_chunk_vector_with_retry
raise RuntimeError(f"Failed to INSERT chunk vector (vector_as_f32 call): {e}") from e
RuntimeError...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.