Problem
Vector search crashes with OperationalError: k value in knn query too large, provided 10100 and the limit is 4096 when a project has enough vector chunks that the computed k value exceeds sqlite-vec's hard limit.
Error
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) k value in knn query too large, provided 10100 and the limit is 4096
[SQL: WITH vector_matches AS (
SELECT rowid, distance FROM search_vector_embeddings
WHERE embedding MATCH ? AND k = ?)
SELECT c.entity_id, c.chunk_key, c.chunk_text, vector_matches.distance AS best_distance
FROM vector_matches JOIN search_vector_chunks c ON c.id = vector_matches.rowid
WHERE c.project_id = ? ORDER BY best_distance ASC LIMIT ?]
[parameters: (..., 10100, 2, 10100)]
Impact
- All vector search fails for projects with >4096 chunks
- This breaks
search_notes, which cascades to any tool that uses search (dashboard, memory_search, etc.)
- Triggered by normal project growth — our local project hit this today
Fix
The k value passed to sqlite-vec's knn query should be capped at 4096 (or whatever the sqlite-vec limit is). Something like:
k = min(num_chunks * multiplier, 4096)
Environment
- basic-memory 0.18.5 (dev build from main)
- sqlite-vec 0.1.6
- Project: ~10100 vector chunks
Problem
Vector search crashes with
OperationalError: k value in knn query too large, provided 10100 and the limit is 4096when a project has enough vector chunks that the computed k value exceeds sqlite-vec's hard limit.Error
Impact
search_notes, which cascades to any tool that uses search (dashboard, memory_search, etc.)Fix
The k value passed to sqlite-vec's knn query should be capped at 4096 (or whatever the sqlite-vec limit is). Something like:
Environment