New in 3.9Rasa now supports Custom Information Retrievers to be used with the
EnterpriseSearchPolicy. This feature allows you to integrate your own custom search systems or vector stores with Rasa.Introduction
Rasa’s initial integration with vector stores, such as Qdrant and Milvus, laid the foundation for more advanced information retrieval capabilities. We recognized the need to provide a more flexible and extensible interface, leading to the creation of theInformationRetrieval interface. This interface
is a superset of vector stores and encompasses a broader range of information retrieval techniques.
The InformationRetrieval interface enables you to integrate not only vector stores but also custom
search systems, databases, or any other mechanism for retrieving relevant information. This
flexibility empowers you to customize and optimize your information retrieval strategies based
on your specific use cases and requirements.
Creating a Custom Information Retrieval Class
You can implement your own custom information retrieval component as a python class. A custom information retrieval class must subclassrasa.core.information_retrieval.InformationRetrieval
and implement connect and a search methods.
self.embeddings as a langchain.schema.embeddings.Embeddings object.
connect method
The connect method establishes a connection to the information retrieval system. It expects one parameter.
config: This is the endpoint configuration for the information retrieval component.config.kwargsis a python dictionary that can be used to access keys defined inendpoints.ymlundervector_store.
endpoints.yml
search method
The search method queries the information retrieval system for a document and returns a SearchResultList object
which is a list of documents that match the query.
The method expects the following parameters:
query: The query string. Typically the last user messagetracker_state: The current tracker state as a dictionary.threshold: The minimum similarity score to consider a document a match.
Tracker State
Tracker State python dictionary is a snapshot of Rasa Tracker and contains metadata about the rasa conversation. It can be used to get information about any conversation event. It has the following schema,tracker_state.get("slots", {}).get(SLOT_NAME)
SearchResultList dataclass
SearchResultList dataclass is defined with SearchResult dataclass. Both of these dataclasses are defined as,SearchResultList.from_document_list() to convert
from a Langchain Document object type.
Using the Custom Information Retrieval component
To configureEnterpriseSearchPolicy to use the custom component;
set the vector_store.type parameter in the config.yml file to the module path of the custom information retrieval class.
For example, for a custom information retrieval class called MyVectorStore saved in a file addons/custom_information_retrieval.py,
the module path would be addons.custom_information_retrieval.MyVectorStore, and the credentials could look like:
config.yml
Usage Ideas
The Custom Information Retrieval feature opens up a range of possibilities for customizing and enhancing your assistant. Here are some potential use cases:Traditional Search, Vector Search or Rerankers
You have the flexibility to connect to any search system, whether it’s a traditional BM25-based search engine, an open-source Elasticsearch instance, state-of-the-art vector stores, or even your favorite re-ranking models. This freedom allows you to stay at the forefront of IR innovations and leverage the latest advancements to enhance your conversational assistant.Slot-Based Retrieval
With custom information retrieval, you can leverage conversation context and slots provided by thetracker_state. This enables slot-based retrieval, allowing you to filter search results
based on the values of specific slots. For example, you could retrieve product recommendations
based on the user’s previously mentioned preferences or interests.
You could also add filters to the search systems based on a slot that defines user’s access level.