RetrieverTool
The RetrieverTool component lets you turn a retriever (the part of your system that pulls in relevant information) into a tool that an AI can call. Once you set it up, the AI can ask questions and get answers that are pulled from your data sources.
How it Works
When you drop this component into your workflow, you give it a retriever, a name, a short description, and optionally a prefix prompt. The component then builds a BaseTool that the AI can use. Internally it calls create_retriever_tool_with_prefix
, which packages the retriever and the extra information into a tool that the AI can invoke. No external APIs are called by this component itself; it just prepares the tool for the AI.
Inputs
- Retriever: The retriever object that knows how to fetch relevant data from your sources.
- Prefix Prompt: A short sentence that will be added before every query the AI sends to the retriever.
- Description: A clear, concise explanation of what the tool does.
- Name: The name that the AI will use to refer to this tool.
Outputs
- Tool: A
BaseTool
object that can be plugged into an AI chain. Use this output as the tool input for any LangChain or Nappai component that accepts tools.
Usage Example
- Add a Retriever – Drag a Retriever component into the canvas and configure it to pull data from your database.
- Add a RetrieverTool – Connect the Retriever’s output to the Retriever input of the RetrieverTool.
- Set the Name and Description – Give the tool a friendly name like “Customer FAQ” and a description such as “Answers questions about product support.”
- Optional Prefix Prompt – Add “Here is the relevant information:” to help the AI frame its query.
- Use the Tool – Connect the Tool output to a Chat or LLM component that accepts tools. When the AI receives a user question, it will automatically call this tool and return the retrieved answer.
Related Components
- Retriever – The component that actually fetches data from your sources.
- Chat – A component that can use tools like the one created here to answer user queries.
- LLM – The language model that will call the tool.
Tips and Best Practices
- Keep the Description short but informative; the AI uses it to decide when to call the tool.
- Use a Prefix Prompt to give the AI a consistent context for every query.
- Test the tool with a few sample questions before deploying it to production.
- If you have multiple retrievers, give each tool a distinct name to avoid confusion.
Security Considerations
- The retriever controls what data can be accessed. Make sure it only pulls from trusted sources.
- The tool itself does not expose any credentials; it simply forwards queries to the retriever.
- Review the retriever’s permissions to ensure sensitive data is protected.