Add sqlite-vec ANN vector search to @ekai/memory#93
Merged
Conversation
Add sqlite-vec extension to @ekai/memory, replacing the 200-row linear scan + JS cosine similarity with proper ANN indexing via vec0 virtual tables with cosine distance metric. - Add sqlite-vec dependency, load extension on construction - Create vec0 virtual tables (memory_vec, procedural_vec, semantic_vec, reflective_vec) lazily on first embedding - Insert into vec tables alongside main tables on write path - Replace getCandidatesForSector 200-row scan with two-step KNN: ANN query on vec table, then filter via main table - Replace findDuplicate linear scans with vec KNN queries - Update scoreRowPBWM to accept precomputed similarity - Make embedding optional on record types (query results no longer carry full embedding arrays) - Stop selecting embedding in semantic graph traversal queries - Clean up vec tables on delete operations
Embedding is always present on write and never read on query path (similarity is precomputed by sqlite-vec). Graph traversal methods now return Omit<SemanticMemoryRecord, 'embedding'> since they are structural queries that don't select the embedding column.
Shriiii01
pushed a commit
to Shriiii01/ekai-gateway
that referenced
this pull request
Mar 7, 2026
Add sqlite-vec ANN vector search to @ekai/memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
vec0virtual tables with cosine distance metricKnown limitation
KNN runs globally across all agents, post-filtered by agent_id. At current scale (few agents) k=50 provides sufficient headroom. When multi-tenant isolation matters, the fix is adding
integer partition keyto vec0 tables — a single-session change.Test plan
npm run build— all workspaces compilenpm testin memory/ — all 15 existing tests pass