MCPcopy
hub / github.com/langchain-ai/langchain / create_retriever_tool

Function create_retriever_tool

libs/core/langchain_core/tools.py:1006–1045  ·  view source on GitHub ↗

Create a tool to do retrieval of documents. Args: retriever: The retriever to use for the retrieval name: The name for the tool. This will be passed to the language model, so should be unique and somewhat descriptive. description: The description for the tool

(
    retriever: BaseRetriever,
    name: str,
    description: str,
    *,
    document_prompt: Optional[BasePromptTemplate] = None,
    document_separator: str = "\n\n",
)

Source from the content-addressed store, hash-verified

1004
1005
1006def create_retriever_tool(
1007 retriever: BaseRetriever,
1008 name: str,
1009 description: str,
1010 *,
1011 document_prompt: Optional[BasePromptTemplate] = None,
1012 document_separator: str = "\n\n",
1013) -> Tool:
1014 """Create a tool to do retrieval of documents.
1015
1016 Args:
1017 retriever: The retriever to use for the retrieval
1018 name: The name for the tool. This will be passed to the language model,
1019 so should be unique and somewhat descriptive.
1020 description: The description for the tool. This will be passed to the language
1021 model, so should be descriptive.
1022
1023 Returns:
1024 Tool class to pass to an agent
1025 """
1026 document_prompt = document_prompt or PromptTemplate.from_template("{page_content}")
1027 func = partial(
1028 _get_relevant_documents,
1029 retriever=retriever,
1030 document_prompt=document_prompt,
1031 document_separator=document_separator,
1032 )
1033 afunc = partial(
1034 _aget_relevant_documents,
1035 retriever=retriever,
1036 document_prompt=document_prompt,
1037 document_separator=document_separator,
1038 )
1039 return Tool(
1040 name=name,
1041 description=description,
1042 func=func,
1043 coroutine=afunc,
1044 args_schema=RetrieverInput,
1045 )
1046
1047
1048ToolsRenderer = Callable[[List[BaseTool]], str]

Callers 3

agent.pyFile · 0.85
chain.pyFile · 0.85
chain.pyFile · 0.85

Calls 2

ToolClass · 0.85
from_templateMethod · 0.45

Tested by

no test coverage detected