Skip to content

Add sqlite-vec ANN vector search to @ekai/memory#93

Merged
sm86 merged 3 commits into
mainfrom
vector-database-integration
Feb 26, 2026
Merged

Add sqlite-vec ANN vector search to @ekai/memory#93
sm86 merged 3 commits into
mainfrom
vector-database-integration

Conversation

@sm86
Copy link
Copy Markdown
Contributor

@sm86 sm86 commented Feb 26, 2026

Summary

  • Replace 200-row linear scan + JS cosine similarity with sqlite-vec ANN indexing via vec0 virtual tables with cosine distance metric
  • Vec tables created lazily on first embedding, dimension auto-detected from embedding model
  • Scoring accepts precomputed similarity from sqlite-vec instead of recomputing in JS
  • Graph traversal queries no longer select unused embedding column
  • README updated with new retrieval pipeline and data model

Known 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 key to vec0 tables — a single-session change.

Test plan

  • npm run build — all workspaces compile
  • npm test in memory/ — all 15 existing tests pass
  • Ingest, query, dedup, consolidation, agent isolation, delete paths all exercised

sm86 added 3 commits February 26, 2026 19:18
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.
@sm86 sm86 merged commit 5dd98ed into main Feb 26, 2026
1 check passed
@sm86 sm86 deleted the vector-database-integration branch February 26, 2026 14:18
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant