You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
importastimportrefromlangchain.agents.agent_toolkitsimportcreate_retriever_toolfromlangchain_community.vectorstoresimportFAISSfromlangchain_core.example_selectorsimportSemanticSimilarityExampleSelector# Create a vector store from the combined list of artists and albumsvector_db_f=FAISS.from_texts(names1, embeddings)
# Create a retriever from the vector store, retrieving the top 5 similar itemsretriever_f=vector_db_f.as_retriever(search_kwargs={"k": 1})
# Description for the retriever tooldescription="""As an AI agent, your task is to match human query text with entries in the vector database. Use word cardinality to compare the frequency of each word in both texts, selecting the most similar proper nouns based on approximate spelling. Ensure accuracy by double-checking each word. Replace the human-given string with the best matches from the vector database, keeping the overall sentence structure intact."""# Create the retriever tool with the specified name and descriptionretriever_tool=create_retriever_tool(
retriever_f,
name="search_proper_nouns",
description=description,
)
Description
Can I have sample code either from Langgraph or Langchain by using above tool to replace my user query?
My objective is 'user query' need to be replaced by vector search before it goes to LLM. The code snippet I have here is below. Now I like to tie with either agent or langgraph. Please help.
import ast
import re
from langchain.agents.agent_toolkits import create_retriever_tool
from langchain_community.vectorstores import FAISS
from langchain_core.example_selectors import SemanticSimilarityExampleSelector
# Create a vector store from the combined list of artists and albums
vector_db_f = FAISS.from_texts(names1, embeddings)
# Create a retriever from the vector store, retrieving the top 5 similar items
retriever_f = vector_db_f.as_retriever(search_kwargs={"k": 1})
# Description for the retriever tool
description = """
As an AI agent, your task is to match human query text with entries in the vector database. Use word cardinality to compare the frequency of each word in both texts, selecting the most similar proper nouns based on approximate spelling. Ensure accuracy by double-checking each word. Replace the human-given string with the best matches from the vector database, keeping the overall sentence structure intact.
"""
# Create the retriever tool with the specified name and description
retriever_tool = create_retriever_tool(
retriever_f,
name="search_proper_nouns",
description=description,
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Checked other resources
Commit to Help
Example Code
Description
Can I have sample code either from Langgraph or Langchain by using above tool to replace my user query?
My objective is 'user query' need to be replaced by vector search before it goes to LLM. The code snippet I have here is below. Now I like to tie with either agent or langgraph. Please help.
System Info
Name: langchain
Version: 0.3.2
Beta Was this translation helpful? Give feedback.
All reactions