Home / Function/ test_create_retriever_tool() — langchain Function Reference

test_create_retriever_tool() — langchain Function Reference

Architecture documentation for the test_create_retriever_tool() function in test_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1b84a361_dc8d_d554_f735_e9db4152aa21["test_create_retriever_tool()"]
  8e7836ae_e72c_f670_72a5_4ca6d46e3555["test_tools.py"]
  1b84a361_dc8d_d554_f735_e9db4152aa21 -->|defined in| 8e7836ae_e72c_f670_72a5_4ca6d46e3555
  8d5bd17d_0055_b4e9_b44a_08c070f779ab["_get_relevant_documents()"]
  1b84a361_dc8d_d554_f735_e9db4152aa21 -->|calls| 8d5bd17d_0055_b4e9_b44a_08c070f779ab
  style 1b84a361_dc8d_d554_f735_e9db4152aa21 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/test_tools.py lines 2247–2296

def test_create_retriever_tool() -> None:
    class MyRetriever(BaseRetriever):
        @override
        def _get_relevant_documents(
            self, query: str, *, run_manager: CallbackManagerForRetrieverRun
        ) -> list[Document]:
            return [Document(page_content=f"foo {query}"), Document(page_content="bar")]

    retriever = MyRetriever()
    retriever_tool = tools.create_retriever_tool(
        retriever, "retriever_tool_content", "Retriever Tool Content"
    )
    assert isinstance(retriever_tool, BaseTool)
    assert retriever_tool.name == "retriever_tool_content"
    assert retriever_tool.description == "Retriever Tool Content"
    assert retriever_tool.invoke("bar") == "foo bar\n\nbar"
    assert retriever_tool.invoke(
        ToolCall(
            name="retriever_tool_content",
            args={"query": "bar"},
            id="123",
            type="tool_call",
        )
    ) == ToolMessage(
        "foo bar\n\nbar", tool_call_id="123", name="retriever_tool_content"
    )

    retriever_tool_artifact = tools.create_retriever_tool(
        retriever,
        "retriever_tool_artifact",
        "Retriever Tool Artifact",
        response_format="content_and_artifact",
    )
    assert isinstance(retriever_tool_artifact, BaseTool)
    assert retriever_tool_artifact.name == "retriever_tool_artifact"
    assert retriever_tool_artifact.description == "Retriever Tool Artifact"
    assert retriever_tool_artifact.invoke("bar") == "foo bar\n\nbar"
    assert retriever_tool_artifact.invoke(
        ToolCall(
            name="retriever_tool_artifact",
            args={"query": "bar"},
            id="123",
            type="tool_call",
        )
    ) == ToolMessage(
        "foo bar\n\nbar",
        artifact=[Document(page_content="foo bar"), Document(page_content="bar")],
        tool_call_id="123",
        name="retriever_tool_artifact",
    )

Domain

Subdomains

Frequently Asked Questions

What does test_create_retriever_tool() do?
test_create_retriever_tool() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/test_tools.py.
Where is test_create_retriever_tool() defined?
test_create_retriever_tool() is defined in libs/core/tests/unit_tests/test_tools.py at line 2247.
What does test_create_retriever_tool() call?
test_create_retriever_tool() calls 1 function(s): _get_relevant_documents.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free