Skip to content

RAG Agent

RAG Agent answers questions using the information in your knowledge base. It searches the documents you connect, keeps the ones that really relate to the question, writes the answer citing where each fact comes from ([1], [2]… and at the end the Sources with the file name and page) and checks that it is backed by those documents and that it answers what was asked. If it finds no useful documents, it searches once more with other words and, if it still finds none, tells the user, in the language of their question, that it does not have that information, without making up an answer.

It uses 4 model calls per question with the default settings. In the 40-question test it got between 23 and 25 of the 36 answerable questions right (27–28 with Metadata Schema) and said “I don’t know” to the 4 that had no answer.

When to use it

  • An assistant that answers questions about manuals, internal policies or product sheets.
  • A customer service desk that answers from the company’s FAQs and documentation.
  • Giving another agent the ability to query your knowledge base, by connecting it as a tool.

Configuration

ConnectionWhat to connect
Retrievers (required)One or more searchers over your documents, for example the Retriever output of FAISS, PGVector or Qdrant, or that of Local Rerank. Without retrievers connected, the agent does not answer.
Model (required)The AI model that assesses the documents and writes the answer.
Web Search ToolOptional, only with Enable Web Search Fallback: a web search tool, such as Brave Search API Tool, that the agent uses as a fallback when your documents are not enough.
FieldWhat it does
QuestionThe question to answer, usually from Chat Input.
Agent NameThe agent’s name. Default: RAGAgent.
Agent DescriptionWhat the agent does. Useful when another agent uses it.
Additional InstructionsInstructions it follows when it answers: the tone, who it speaks for (company, product) or what to say when the documentation does not have the answer, for example “suggest writing to support@yourcompany.com”.

Advanced options

FieldWhat it does
Show SourcesCites the document of each fact in the answer ([1], [2]…) and adds the Sources at the end with the file name or title and page, in the language of the question. Default: on.
StreamShows the answer as it is being generated. Only the answer is shown; the sources arrive when it finishes. Default: off.
JSON Structured OutputReturns the answer in JSON format, with the answer text, the date, the documents used with their names and the result of the checks. Default: off.
Metadata SchemaDescribes the data that comes with your documents (for example brand, category or date) so the agent filters the search with it when the question mentions it. It uses the same format as Metadata Tagger: a JSON list with the name, type and description of each item, for example [{"name": "category", "type": "string", "description": "Topic: shipping, warranty, payments"}]. List the possible values in the description. If the filter finds nothing, it searches without it.
Use MemoryKeeps the conversation so the agent takes earlier messages into account: it understands follow-up questions such as “and how much does it cost?” after asking about a delivery. Default: off.
Enable Hallucination CheckChecks that every fact in the answer is in the documents; if not, it searches again. It shares one call with the next check. Default: on.
Enable Answer Quality CheckChecks that the answer really answers the question; if not, it searches again. Default: on.
Enable Document Relevance GradingScores the documents found in a single call and discards the useless ones. This is what lets it say “I don’t know” instead of guessing. Default: on.
Enable Web Search FallbackIf there are no useful documents, searches the internet with the tool connected to Web Search Tool. Without a search tool connected it does nothing. Default: off.

Using it as an agent tool

You can connect this component to an agent’s Tools input. In the Tool tab, Tool Name and Tool Description are the name and explanation the agent uses to recognise the tool and decide when to call it. By default they are search_information and “Search information from user request”. When it works as a tool, the answer is always delivered in JSON format with its sources.

Output

  • Response: the answer to the question as a message. Connect it to Chat Output or to any component that takes text.
  • Agent: the configured agent, so another agent can delegate to it.

Example

The insurer Hogar Seguro wants its support team to look up the terms of its policies:

  1. Load the general terms into a PGVector store and connect its Retriever output to Retrievers.
  2. Connect an AI model to Model and Chat Input to Question.
  3. Leave Enable Web Search Fallback off: they only want answers based on their own policies. In Additional Instructions they write: “Speak for Hogar Seguro and, if the terms do not say, suggest calling 900 000 000”.
  4. Connect Response to Chat Output.

When an agent asks “Does the basic policy cover water damage?”, the assistant answers with what the terms say and ends with “Sources: [1] general-terms.pdf, p. 12”. If they then ask “and in the full policy?”, with Use Memory on it understands they are still asking about water damage.

Good practices

  • Turn on web search only if you connect a search tool to Web Search Tool and accept answers that do not come from your documentation.
  • The checks cost a single call (under a second). In the test they did not change the result with a large model; keep them on with small models or when a wrong answer is expensive.
  • If your documents carry brand, product or date, fill in Metadata Schema: it was the biggest improvement in the test.
  • Start with 4 to 8 results per retriever (the vector database’s Number of Results).
  • For counts or relations spread over many documents (“how many incidents does … have?”), use a graph or a database: the agent searches once and only sees the top results.
  • To get the good results first, connect the Retriever output of Local Rerank to Retrievers instead of the vector database directly.

Video

This video builds a RAG Agent over the documentation of a coffee-machine repair service and asks it a question, a follow-up and one the documentation does not answer.

What you see in the video:

  1. Qdrant in Retriever mode, with 5 results, connected to Retrievers of the RAG Agent.
  2. The options: Additional Instructions, Metadata Schema with brand, type, month and codes, the three checks (Enable Document Relevance Grading, Enable Hallucination Check and Enable Answer Quality Check), Show Sources and Use Memory.
  3. Asked what error E07 means on the Vellani Aurora, it answers blocked flowmeter, part VL-1180 [1], and a real case [2], and lists the sources at the end: the Vellani Aurora manual and the July incident report.
  4. Asked how long that part takes to arrive, memory lets it understand it is the VL-1180, and it answers five to seven working days.
  5. Asked for the opening hours of the shop in Málaga, it says it cannot find that information.
  6. Each question takes about four model calls and about five seconds.
  • RetrieverTool: turns a search in your knowledge base into a tool for any agent.
  • Agent: NappAI’s main agent.
  • Local Rerank: reorders the results before they reach the agent.

To see when to use this agent and when an Agent with search tools, see The RAG agent in the RAG guide.