Closed Ajaypawar02 closed 11 months ago
🤖
Hello,
Thank you for reaching out with your question. It seems like you want to configure the OpenAiAgent in LangChain to access different vectorstores if the answer is not found in a particular vectorstore. This is indeed possible and can be achieved by using the VectorStoreRouterToolkit and the create_vectorstore_router_agent function.
Here is a code snippet that shows how to do this:
from langchain.agents.agent_toolkits import (
create_vectorstore_router_agent,
VectorStoreRouterToolkit,
VectorStoreInfo,
)
from langchain.vectorstores.pgvector import PGVector
from langchain.embeddings.openai import OpenAIEmbeddings
# Create the VectorStoreInfo instances
state_of_union_store = PGVector.from_existing_index(
connection_string="postgresql+psycopg2://user:password@localhost:5432/dbname",
embedding_function=OpenAIEmbeddings(),
collection_name="state_of_union_address",
)
ruff_store = PGVector.from_existing_index(
connection_string="postgresql+psycopg2://user:password@localhost:5432/dbname",
embedding_function=OpenAIEmbeddings(),
collection_name="ruff",
)
state_of_union_info = VectorStoreInfo(
name="state_of_union_address",
description="the most recent state of the Union adress",
vectorstore=state_of_union_store,
)
ruff_info = VectorStoreInfo(
name="ruff",
description="Information about the Ruff python linting library",
vectorstore=ruff_store,
)
# Create the VectorStoreRouterToolkit instance
router_toolkit = VectorStoreRouterToolkit(
vectorstores=[state_of_union_info, ruff_info], llm=llm
)
# Create the agent
agent_executor = create_vectorstore_router_agent(
llm=llm, toolkit=router_toolkit, verbose=True
)
In this example, the agent can route between two vectorstores: "state_of_union_address" and "ruff". When you run the agent with a question, it will route the question to the appropriate vectorstore based on the question's context.
You can find more information about this in the following documentation:
I hope this helps! If you have any other questions, feel free to ask.
Best, Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
yes but here one of the tool is search
Hi, @Ajaypawar02! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you were looking for a solution within the OpenAiAgent framework to allow access to different vectorstores if the answer is not found in a particular vectorstore. Dosubot suggested using the VectorStoreRouterToolkit and provided a code snippet as an example. You acknowledged the suggestion but mentioned that one of the tools is search.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project!
Issue you'd like to raise.
In my problem statement I am defining multiple tools which are all based on retrieval chain and I am using OpenAiAgent as the agent to call this tools. So when I am running a query it invokes to a single vectorstore. But I need my agent to access different vectorstores if the answer is not fetched from that particular vectorstore.I know the approach to get this working done by other agents.But I need this to be done by openaiAgent.
Suggestion:
No response