Skip to content

feat: replace vec0 with viant/sqlite-vec for vector search#49

Merged
MichielDean merged 1 commit into
mainfrom
feat/vec-integration
May 11, 2026
Merged

feat: replace vec0 with viant/sqlite-vec for vector search#49
MichielDean merged 1 commit into
mainfrom
feat/vec-integration

Conversation

@MichielDean
Copy link
Copy Markdown
Owner

Summary

Replaces the broken vec0 (asg017/sqlite-vec C extension) with viant/sqlite-vec (pure Go, compatible with modernc.org/sqlite). This fixes the long-standing issue where vector search was completely non-functional in Go builds.

Key changes

  • Replace vec0 with vec module: viant/sqlite-vec uses USING vec(doc_id, embedding float[N]) instead of USING vec0(...). No CGO, no shared libraries required.
  • Fix stale vtab cleanup: Databases created with vec0 have a memories_vec vtab registered under the vec0 module, which can't be dropped ("no such module: vec0"). Uses PRAGMA writable_schema to remove the stale entry from sqlite_master.
  • Fix connection pooling: vec.Register(db) registers the module globally but only on new connections. The PRAGMA calls in openDB create warm connections that lack the module. Close and reopen DB after registration.
  • Fix deadlock: viant/sqlite-vec creates shadow tables lazily on first query, causing deadlock with database/sql connection pooling. Eagerly create _vec_memories_vec, vector_storage, and vector_storage_locks upfront.
  • Fix search query: Use doc_id MATCH ? (not embedding MATCH ?) per viant's vtab schema (dataset_id, doc_id, match_score HIDDEN).
  • Go-managed shadow table sync: Add/Update/ Invalidate/ Delete now maintain the shadow table in Go code instead of SQL triggers.
  • Fix content-only Update: Update with content changes but no embedding change now updates the shadow table content column, preserving the existing embedding.

Known issues

  • Pre-existing test failures: TestIntrospectCmd_AutoFlags (removed flags) and TestSessionHookCoordinator_OnEndingWithIntrospect (source mismatch) — both unrelated to this PR.
  • internal/introspect build failure (IntrospectAuto undefined) — pre-existing, same as above.

Testing

  • All store tests pass
  • Verified vec search works against live database (648 embeddings synced)
  • llmem search returns semantically relevant results
  • dropLegacyVec0Objects successfully removes stale vec0 vtab entries via PRAGMA writable_schema

- Replace asg017/sqlite-vec (vec0) with viant/sqlite-vec (vec module)
- Pure Go, compatible with modernc.org/sqlite — no CGO or shared libraries
- Fix stale vec0 vtab cleanup: use PRAGMA writable_schema to remove entries
  when vec0 module is unavailable (common in Go-only builds)
- Fix connection pooling: vec.Register only applies to new connections,
  so close and reopen DB after registration to pick up the module
- Fix deadlock: eagerly create shadow table, vector_storage, and
  vector_storage_locks to prevent lazy-creation deadlock with database/sql
- Fix shadow table sync: Add/Update/Invalidate/Delete now maintain the
  _vec_memories_vec shadow table in Go code instead of SQL triggers
- Fix searchByEmbeddingVec: use doc_id MATCH (not embedding MATCH) per
  viant/sqlite-vec schema (dataset_id, doc_id, match_score HIDDEN)
- Fix Update sync: content-only updates preserve existing embedding instead
  of deleting the shadow table entry
- Fix SemanticOnly error: return clear error instead of duplicate returns
- Remove DisableVec field from MemoryStore, remove dropVecTriggers, remove
  reVecDimensions regex
- Eagerly populate shadow table from memories.embedding on startup
- Store test changes: update TestMigration_Vec0ObjectsDroppedBeforeMigration
  to test new dropLegacyVec0Objects behavior
@MichielDean MichielDean merged commit 863e601 into main May 11, 2026
0 of 4 checks passed
@MichielDean MichielDean deleted the feat/vec-integration branch May 11, 2026 18:19
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