Research Agent¶
The ResearchAgent
is a built-in utility agent in the AI Refinery SDK for handling complex research queries. It retrieves information from web resources and generates comprehensive responses. For instance, if asked "How do interest rate changes by the Federal Reserve impact the stock market?", the ResearchAgent
will
- search predefined web sources,
- gather the relevant information,
- generate the answer based on the relevant information.
This documentation outlines the workflow and configurations needed to use the ResearchAgent.
Workflow Overview¶
The workflow of ResearchAgent
consists of six components:
-
Source selection: The
ResearchAgent
retrieves information related to a user query from one or more pre-selected sources (e.g., Google, vector database indices). These sources must be specified before project creation. TheResearchAgent
will then utilize all selected sources for its search. -
Query transformation: Directly using the user's query to search all selected sources may not be optimal, especially if the query is lengthy or complex. In such cases, the
ResearchAgent
splits the query into multiple, more manageable queries to ensure relevant results. Thus, theResearchAgent
transforms the user's query into one or more queries tailored for each selected source. -
Retrieval: The
ResearchAgent
sends transformed queries to the selected sources and retrieves relevant data, ensuring it aligns with the original user query. -
Reranking: After retrieval, the
ResearchAgent
uses the reranker API to reorder the retrieved documents based on their relevance to the user's query. This ensures that the most pertinent information is prioritized in the response. -
Compression: The
ResearchAgent
then utilizes the prompt compression API to reduce the size of the top-ranked documents while retaining essential information. This step optimizes the prompt length for efficient processing. -
Answer generation: After retrieving, reranking, and compressing data from all sources, the
ResearchAgent
aggregates the information into a coherent and concise response, which is then presented to the user.
Usage¶
As a built-in utility agent in the AI Refinery SDK, ResearchAgent
can be easily integrated into your project by adding the necessary configurations to your project YAML file. Specifically, ensure the following configurations are included:
- Add a utility agent with
agent_class: ResearchAgent
underutility_agents
. - Ensure the
agent_name
you chose for yourResearchAgent
is listed in theagent_list
underorchestrator
.
Quickstart¶
To quickly set up a project with a ResearchAgent
, use the following YAML configuration. This setup includes two retrievers (i.e., sources): one for web search (via Google) and another for vector search (over a specified vector database index). You can add more agents and retrievers as needed. Refer to the next section for a detailed overview of configurable options for ResearchAgent.
utility_agents:
- agent_class: ResearchAgent
agent_name: My Research Agent # A name that you choose for your research agent. This needs to be listed under orchestrator.
config:
reranker_top_k: 15 # Optional: Defines the top-k most relevant evidence pieces to retain post-reranking. Set to a negative value to skip reranking.
compression_rate: 0.4 # Optional: Specifies the compression rate for retrieved content. Lower values increase compression, discarding more information (default: 0.6). Set to 1 to retain all content with no compression.
retriever_config_list:
# The list of configurations of the retrievers i.e., sources used by your research agent to search for the relevant information related to a user query.
- retriever_name: "Internet Search" # A name you choose for your retriever
retriever_class: WebSearchRetriever # WebSearchRetriever is the type of retriever that performs web search via Google.
description: "This data source can collect the latest news / information from the open internet to answer any queries." # Optional. A description of the retrievar
- retriever_name: "Knowledge Brain" # A name you choose for your retriever
retriever_class: AzureAISearchRetriever # AzureAISearchRetriever is the type of retriever that performs web search via Google.
description: "Knowledge base for all Accenture internal documents and publications such as briefs, plans, and reports. This is expecially useful for studing previous marketing campaigns and Accenture-related topics." # Optional. A description of the retrievar
aisearch_config:
# The details of the vector database index that the `ResearchAgent` can search over
base_url: azure.com # base url of where your vector database index is hosted>
api_key: "xyz" # your azure api key for the vector database
index: "my-knowledge-brain-2024" # name of the vector database index
embedding_column: "outputMistralVector" # The column of the index you stored your embedded data that you want the `ResearchAgent` to search over
embedding_config:
model: "intfloat/e5-mistral-7b-instruct" # Embedding model for the retrieval, must match the config you used for embedding your data in the embedding_column
top_k: 5 # Number of documents to retrieve
content_column: "output" # The content that we are going to retrieve
orchestrator:
agent_list:
- agent_name: "My Research Agent" # The name you chose for your ResearchAgent above.
Template YAML Configuration of ResearchAgent
¶
In addition to the configurations mentioned for the example above, the ResearchAgent
supports several other configurable options. See the template YAML configuration below for all available settings.
agent_class: ResearchAgent
agent_name: <name of the agent> # A name that you choose for your research agent
agent_description: <description of the agent> #Optional
config:
reranker_top_k: <number of top k> # Optional: Specifies the number of top results you want from the reranked output.
compression_rate: <compression rate> # Optional: Defines the desired level of compression. Set to 1 to retain all content without any compression.
retriever_config_list:
# Required. Here, you list the configurations of the retrievers i.e., sources to be used by your ResearchAgent.
- retriever_name: <name of the retriever>
retriever_class: WebSearchRetriever # The retriever_class must be "WebSearchRetriever" if you want your research agent to search the web
description: <description of the retriever>
query_transformation_examples:
# Optional. Examples of how the research agent should convert the user query to a query or list of queries that is suitable for the web search
- user_query: <an example query from the user>
query:
- <transformed query 1>
- <transformed query 2>
source_weight: <a source weight> # The importance weight of the information retrieved by this particular retriever if you are using multiple retrievers.
- retriever_name: <name of the retriever>
retriever_class: AzureAISearchRetriever #Required. The retriever_class must be "AzureAISearchRetriever" if you want your research agent to perform vector search over an index hosted on Azure
description: <description of this retriever> #Optional.
aisearch_config:
# Required. Vector database index
base_url: <base url of where your vector database index is hosted>
api_key: <your azure api key for the vector database>
index: <name of the index you want your AzureAISearchRetriever to search>
# Required. Embedding column / model
embedding_column: <the column of the index you stored your embedded data that you want to search over>
embedding_config: # Embedding model for the retrieval, must match the config you used for embedding your data in the embedding_column
model: <name of the model>
top_k: <number of documents to retrieve> # Optional (top k, default 10)
# Required: Content that we are going to retrieve
content_column: <name of your content column>
# Optional:
# Each document can be chunked into multiple rows. The aggregate_column
# column stores the name of the document If aggregate_column is not
# specified, we will treat each chunk as a document
aggregate_column: <your aggregate column>
# Optional: meta data that we want to include besides the chunk column
meta_data:
- column_name: <"name of a column">
load_name: <"load name of the column">
query_transformation_examples:
# Optional. A list of examples of a query from the user and their transformed versions for efficient vector search.
- user_query: <an example query from the user>
query:
- <transformed query 1>
- <transformed query 2>
source_weight: <a source weight> # The importance weight of the information retrieved by this particular retriever if you are using multiple retrievers.
output_style: <"markdown" or "conversational" or "html"> # Optional field
contexts: # Optional field
- "date"
- "chat_history"
- "chat_summary"
llm_config:
# Optional. Customized llm config (if you want the research agent to use a different LLM than the on in your base config)
model: <model_name>