feat(knowledge): add sqlite-vec backend (sqlite_vec) with LlamaIndex adapter#169
Closed
esafwan wants to merge 9 commits into
Closed
feat(knowledge): add sqlite-vec backend (sqlite_vec) with LlamaIndex adapter#169esafwan wants to merge 9 commits into
esafwan wants to merge 9 commits into
Conversation
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.
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.
Motivation
zvecintegration by offering a LlamaIndex-compatible adapter for reuse in LlamaIndex-based pipelines.Description
SQLiteVecBackendimplementing theKnowledgeBackendcontract inhuf/ai/knowledge/backends/sqlite_vec_backend.py, storing chunks in achunkstable and embeddings in achunks_vecvec0virtual table, with upsert-friendly indexing and search using sqlite-vec.SQLiteVecVectorStoreLlamaIndex adapter inhuf/ai/knowledge/backends/sqlite_vec_llamaindex.pymirroring the zvec adapter to allow reuse in LlamaIndex flows.sqlite_vecin the backend factory and updated the indexer to include embedding configuration for vector backends (zvec,sqlite_vec).sqlite_vecto theknowledge_typeselect, show/require vector settings for both vector backends, and generalized server-side validation to cover all vector backends; also addedsqlite-vectopyproject.tomldependencies.Testing
python -m compileallon the new backend and LlamaIndex adapter and on the modified DocType/indexer modules, and compilation completed without syntax errors.Codex Task