nemoguardrails.kb.kb
Module Contents
Classes
Data
API
Basic implementation of a knowledge base.
This class represents a knowledge base that can store and index documents for efficient retrieval. It utilizes an embedding search provider to build and search an index for relevant information.
Parameters:
- documents (List[str]): A list of documents to initialize the knowledge base.
- config (KnowledgeBaseConfig): Configuration for the knowledge base.
- get_embedding_search_provider_instance (Callable[[Optional[EmbeddingSearchProvider]], EmbeddingsIndex]): A callable function to get an instance of the embedding search provider.
Methods:
- init(): Initializes the knowledge base by splitting documents into topic chunks.
- build(): Builds the knowledge base index, utilizing the configured embedding search provider.
- search_relevant_chunks(text: str, max_results: int = 3): Searches the index for the most relevant chunks.
Attributes:
- documents (List[str]): The list of documents provided during initialization.
- chunks (List[dict]): A list of topic chunks extracted from the documents.
- index (EmbeddingsIndex): The knowledge base index used for searching.
- config (KnowledgeBaseConfig): Configuration for the knowledge base.
Example:
Note:
- The knowledge base supports markdown format documents.
- The index is built using an embedding search provider, and the result is cached for future use.
chunks
async
Builds the knowledge base index.
Initialize the knowledge base.
The initial data is loaded from the $kb_docs context key. The key is populated when
the model is loaded. Currently, only markdown format is supported.
async
Search the index for the most relevant chunks.