Skip to content

feat(knowledge): add sqlite-vec backend (sqlite_vec) with LlamaIndex adapter#169

Closed
esafwan wants to merge 9 commits into
developfrom
codex/implement-sqlite-vec-integration-for-rag
Closed

feat(knowledge): add sqlite-vec backend (sqlite_vec) with LlamaIndex adapter#169
esafwan wants to merge 9 commits into
developfrom
codex/implement-sqlite-vec-integration-for-rag

Conversation

@esafwan
Copy link
Copy Markdown
Contributor

@esafwan esafwan commented Feb 27, 2026

Motivation

  • Provide a third, portable vector backend using SQLite + sqlite-vec to enable zero-ops, per-source agent memory with SQL+vector queries for local/edge RAG use cases.
  • Preserve the existing ingestion, retrieval, and DocType-driven configuration patterns so UI, flows, and tools continue to work across backends.
  • Maintain parity with the existing zvec integration by offering a LlamaIndex-compatible adapter for reuse in LlamaIndex-based pipelines.

Description

  • Added SQLiteVecBackend implementing the KnowledgeBackend contract in huf/ai/knowledge/backends/sqlite_vec_backend.py, storing chunks in a chunks table and embeddings in a chunks_vec vec0 virtual table, with upsert-friendly indexing and search using sqlite-vec.
  • Added SQLiteVecVectorStore LlamaIndex adapter in huf/ai/knowledge/backends/sqlite_vec_llamaindex.py mirroring the zvec adapter to allow reuse in LlamaIndex flows.
  • Registered the new backend key sqlite_vec in the backend factory and updated the indexer to include embedding configuration for vector backends (zvec, sqlite_vec).
  • Updated Knowledge Source DocType (JSON/JS/Python) to add sqlite_vec to the knowledge_type select, show/require vector settings for both vector backends, and generalized server-side validation to cover all vector backends; also added sqlite-vec to pyproject.toml dependencies.

Testing

  • Ran python -m compileall on the new backend and LlamaIndex adapter and on the modified DocType/indexer modules, and compilation completed without syntax errors.
  • Per-file static sanity checks were performed to validate updated DocType JSON/JS fields and backend registration, and no import/parse errors were observed during compilation.

Codex Task

esafwan and others added 9 commits February 18, 2026 07:42
Introduce huf/ai/knowledge/embedding.py with LiteLLM-based
embedding generation:
- get_embedding() for single text embedding
- get_embeddings() for batch embedding with auto-chunking
- resolve_embedding_config() to read model/provider from
  Knowledge Source DocType and resolve API keys from AI Provider
Add huf/ai/knowledge/backends/zvec_backend.py implementing the
KnowledgeBackend ABC using Zvec (Alibaba Proxima-based engine):
- initialize(): create/open .zvec collection with typed schema
- add_chunks(): batch-embed text via embedding module, upsert docs
- delete_chunks(): filter-based deletion by input_id
- search(): embed query + approximate nearest-neighbor search
- clear(): drop and recreate collection
- get_stats(): doc count and on-disk size

Collections stored in /private/files/knowledge/ for portability.
Add huf/ai/knowledge/backends/zvec_llamaindex.py bridging Zvec
collections to LlamaIndex's BasePydanticVectorStore interface:
- add(): convert LlamaIndex BaseNode to zvec.Doc and upsert
- delete(): remove documents by ref_doc_id
- query(): translate VectorStoreQuery to zvec.VectorQuery

Optional adapter for LlamaIndex pipeline compatibility.
- Register 'zvec' backend type in get_backend() factory
- Add 'zvec' option to knowledge_type field in Knowledge Source JSON
- Add Vector Settings section with embedding_model, vector_dimension,
  and embedding_provider fields (visible only when knowledge_type=zvec)
- Add validate_zvec_settings() in knowledge_source.py
- Update knowledge_source.js: remove sqlite_fts-only restriction,
  add dynamic field visibility for vector settings
Add _build_backend_config() helper that constructs the config dict
for backend.initialize(). For zvec sources it includes embedding_model,
vector_dimension, and embedding_provider from the Knowledge Source doc.
Used in both process_knowledge_input() and rebuild_knowledge_index().
Zvec is the in-process vector database engine (based on Alibaba
Proxima) used by ZvecBackend for portable semantic search.
Alibaba's zvec only ships wheels for Python 3.10-3.12, which conflicts with Frappe 16's Python 3.13+ requirement. Switch to tridz-zvec, a fork of alibaba/zvec at github.com/tridz-dev/zvec that adds cp313 and cp314 wheel targets. The import name (import zvec) is unchanged.
@esafwan esafwan changed the base branch from feature/zvec-vectorDB-integration to develop February 27, 2026 02:41
@esafwan esafwan closed this Feb 27, 2026
@esafwan esafwan deleted the codex/implement-sqlite-vec-integration-for-rag branch February 27, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant