Skip to content

feat: FAISS embedded knowledge backend (revives #234 as contract-compliant built-in) - #437

Closed
esafwan wants to merge 3 commits into
feat/weaviate-knowledge-backendfrom
feat/faiss-knowledge-backend
Closed

feat: FAISS embedded knowledge backend (revives #234 as contract-compliant built-in)#437
esafwan wants to merge 3 commits into
feat/weaviate-knowledge-backendfrom
feat/faiss-knowledge-backend

Conversation

@esafwan

@esafwan esafwan commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

feat: FAISS knowledge backend

Adds FAISS as a built-in embedded knowledge backend via llama-index-vector-stores-faiss + faiss-cpu (both compatible with llama-index-core 0.14.23 + Python 3.14). Revives the closed #234 on the current contract architecture.

Design

  • FaissBackend(LlamaIndexBackend, KnowledgeBackend) (~450 lines): HUF-side embeddings, per-source index under site private/files/knowledge/<source>_faiss/.
  • Persistence (the adapter is in-memory only): after every mutation the FAISS index is written via the adapter's persist convention plus a chunks.pkl sidecar (positional id → chunk data) — FAISS stores no text, so the sidecar powers search results and rebuilds.
  • Deletion without metadata filters (FAISS has none): delete_chunks(input_id) finds matches via the sidecar, rebuilds the index from surviving embeddings (no re-embedding cost), re-keys, persists, returns the real count.
  • Honest capability flags: supports_filters() -> False (search isolation is source-per-index; caller filters ignored with a debug log), supports_hybrid_search() -> False. Documented in docstring + schema help text.
  • get_advanced_config_schema(): faiss_index_type (flat/ivf), faiss_nlist with visible_when IVF.

Testing (bench 16_kbreg, Frappe 16.27, Python 3.14, faiss-cpu 1.14.3)

Test Status
Registry discovery as built-in
Advanced-config schema round-trip
Full cycle: text input → Gemini gemini-embedding-001 (3072-dim) → index → semantic search (0.605, L2-normalised) → stats (faiss_ntotal) → health → delete (rebuild) → 0
27 mocked unit tests + registry tests
ruff check / ruff format on touched files

Dependencies

esafwan added 2 commits July 26, 2026 04:25
In-process, file-persisted vector backend on the LlamaIndex FAISS
adapter (faiss.IndexFlatL2 / IndexIVFFlat), persisted under the site's
private files at private/files/knowledge/<source>_faiss/. Salvages the
private-files persistence idea from the closed PR #234 and adapts it to
the knowledge-backend contract.

FAISS has no metadata filtering and the adapter implements no delete,
so supports_filters() is False, search relies on source-per-index
isolation, and scoped delete_chunks rebuilds the index from the
surviving chunks kept in a pickled sidecar (chunks.pkl) that maps
FAISS positional ids to chunk text, metadata, and embeddings. Index
and sidecar are persisted after every mutation.

Registered as a built-in backend (registry, Knowledge Source options,
vector-type lists, hooks comment, contract) with llama-index-vector-
stores-faiss + faiss-cpu dependencies and 27 mocked unit tests.
…dge-backend

# Conflicts:
#	huf/ai/knowledge/backends/BACKEND_CONTRACT.md
#	huf/ai/knowledge/backends/__init__.py
#	huf/ai/knowledge/indexer.py
#	huf/hooks.py
#	huf/huf/doctype/knowledge_source/knowledge_source.js
#	huf/huf/doctype/knowledge_source/knowledge_source.json
#	huf/huf/doctype/knowledge_source/knowledge_source.py
@esafwan

esafwan commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by consolidated vector backend PR #467, now included in integration PR #468.

@esafwan esafwan closed this Jul 26, 2026
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