create_retriever_tool not returning results, but direct query works #25743
Replies: 1 comment
-
Hello there, @JamiltonQuintero! I found a similar issue where the Here is an example of how to correctly set up the retriever with # This will only get documents for paragraphs
retriever = self.vector_db.create_retriever_db().as_retriever(
search_type="similarity",
search_kwargs={
"k": 5,
"filter": {"type": "paragraph"}
}
) Make sure that the Additionally, ensure that the from langchain.tools.retriever import create_retriever_tool
retriever_tool = create_retriever_tool(
retriever,
"juan_ads_social_media_content",
"Search for information in Juan Ads' content. Use this for any questions about Juan Ads' videos, courses, YouTube videos, blogs, or specific content created by Juan Ads."
) If the issue persists, consider checking the integration of the from langchain_community.chat_message_histories import ChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
self.message_history = ChatMessageHistory()
self.agent_with_chat_history = RunnableWithMessageHistory(
self.agent_executor,
lambda session_id: self.message_history,
input_messages_key="input",
history_messages_key="chat_history",
) Invoke the wrapped agent with the correct configuration: response = await self.agent_with_chat_history.ainvoke(
{"input": user_input},
config={"configurable": {"session_id": session_id}}
) By ensuring that the retriever and the agent are correctly configured, you should be able to resolve the issue with the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'm experiencing an issue with create_retriever_tool in LangChain. When I use this tool within my agent, it doesn't return any results. However, when I query the vector store directly using the same search method, it successfully returns the expected results.
Here's the relevant code:
from langchain.tools import create_retriever_tool
class ChatbotManager:
def init(self, vector_db_url):
self.vector_db = LangChainVectorDBManager(connection_string=vector_db_url, collection_name="juan_ads_content")
self.retriever = self.vector_db.create_retriever_db()
async def search_similar_texts(self, query: str, level: str = 'video', k: int = 5) -> List[Dict[str, Any]]:
filter_dict = {"type": level}
results = await self.vector_store.asimilarity_search_with_relevance_scores(
query, k=k, filter=filter_dict
)
# ... process results ...
return processed_results
However, when the agent uses the tool created by create_retriever_tool, it doesn't return any results. I've verified that the vector store contains the expected documents and that the direct query method works.
I'm not sure why the tool isn't working within the agent context. Any insights or suggestions on how to debug this issue would be greatly appreciated.
System Info
langchain~=0.2.14
langchain_openai
python-dotenv~=1.0.1
langchain_google_genai
twilio~=9.2.3
fastapi~=0.112.1
pydantic~=2.8.2
uvicorn
langchain-postgres
psycopg-binary
psycopg
psycopg2
Beta Was this translation helpful? Give feedback.
All reactions