Custom retriever
The Multi-Agent Orchestrator System allows you to create custom retrievers by extending the abstract Retriever class. This flexibility enables you to integrate various data sources and retrieval methods into your agent system. In this guide, we’ll walk through the process of creating a custom retriever, provide an example using OpenSearch Serverless, and explain how to set the retriever for a BedrockLLMAgent.
Steps to Create a Custom Retriever
- Create a new class that extends the
Retriever
abstract class. - Implement the required abstract methods:
retrieve
,retrieveAndCombineResults
, andretrieveAndGenerate
. - Add any additional methods or properties specific to your retriever.
- Create a new class that inherits from the
Retriever
abstract base class. - Implement the required abstract methods:
retrieve
,retrieve_and_combine_results
, andretrieve_and_generate
. - Add any additional methods or properties specific to your retriever.
Example: OpenSearchServerless Retriever
Here’s an example of a custom retriever that uses OpenSearch Serverless:
Install Opensearch npm package:
Install required Python packages:
Using the Custom Retriever with BedrockLLMAgent
To use your custom OpenSearchServerlessRetriever:
In this example, we create an instance of our custom OpenSearchServerlessRetriever
and then pass it to the BedrockLLMAgent
constructor using the retriever
field. This allows the agent to use your custom retriever for enhanced knowledge retrieval during request processing.
How BedrockLLMAgent Uses the Retriever
When a BedrockLLMAgent processes a request and a retriever is set, it typically follows these steps:
- The agent receives a user query through the
processRequest
method. - Before sending the query to the language model, the agent calls the retriever’s
retrieveAndCombineResults
method with the user’s query. - The retriever fetches relevant information from its data source (in this case, OpenSearch Serverless).
- The retrieved information is combined and added to the context sent to the language model.
- The language model then generates a response based on both the user’s query and the additional context provided by the retriever.
This process allows the agent to leverage external knowledge sources, potentially improving the accuracy and relevance of its responses.
By adapting this example as a CustomRetriever for OpenSearch Serverless, you can seamlessly incorporate your pre-built Opensearch Serverless clusters into the Multi-Agent Orchestrator System, enhancing your agents’ knowledge retrieval capabilities.