faiss, qdrant, and milvus
stores. Write your own when your search backend is none of those, or subclass a
built-in to change how it searches.
Mantle checks each
knowledge_stores: entry when you run rasa train, but it
does not query a knowledge store yet. The search_knowledge tool reads only the
local index built from references/. See What’s next. You can
write and register a knowledge store now so it is ready, but nothing calls its
search method yet.Before you start
Put your code in a package next toagent.yml: a folder named addons/ with an
empty __init__.py file. Start rasa from the project root so the package can
be imported.
Subclass KnowledgeStore
Import Document, KnowledgeStore, KnowledgeStoreSettings, SearchRequest,
SearchResult, and SearchResultList from rasa.api.knowledge.v1. Implement
connect and search. The base class keeps the embeddings client in
self.embeddings, so you do not need to override __init__.
addons/custom_knowledge_store.py
FAQ_DOCUMENTS with a load from your index. The example matches words and ignores
request.threshold. A vector store would use the threshold to drop weak matches.
Add an embeddings model group in integrations.yml and name it in the entry. The
group must be a text embeddings model:
integrations.yml
knowledge_stores: accepts exactly three keys: id, type,
and embeddings. Any other key fails validation, so a store that needs its own
connection settings cannot take them yet. Store ids must be unique.
Subclass the built-in FAISS store
To change how thefaiss store returns results and keep the rest, subclass
FAISSStore. This example returns at most three hits:
addons/custom_faiss_store.py
integrations.yml
type set to the class path, because the built-in name faiss selects the
built-in class. Unlike other stages, knowledge_stores has no key for settings
such as an index path. A built-in FAISS store that needs an index path cannot be
configured from integrations.yml yet.
Methods
Versioning
The importrasa.api.knowledge.v1 is the version. YAML names only the class. See
Custom integrations: Versioning.