← All glossary terms

Retrieval-augmented generation

Retrieval-augmented generation, or RAG, is a technique where a model looks up relevant information from an external source before generating an answer, rather than relying only on what it learned during training. It grounds a response in specific, current, or private information the model was never trained on, which cuts down on confidently wrong answers.

An LLM's knowledge is frozen at training time and limited to whatever was in its training data, it has no access to a company's internal documentation, a codebase's actual structure, or anything that happened after training ended, unless that information is given to it directly. Asked about something outside that boundary, a model doesn't necessarily say it doesn't know, it can generate a plausible-sounding answer anyway, which is one of the mechanisms behind AI hallucination. RAG addresses that specific gap.

Before generating a response, the system searches a separate knowledge source, a document store, a codebase, a database, for content relevant to the question, retrieves the most relevant pieces, and includes them as context alongside the original question when prompting the model. The model then generates its answer grounded in that retrieved material, rather than relying purely on patterns memorized during training. The retrieval step is what makes the difference, it's the same underlying model, just given the specific material it actually needs to answer accurately, rather than guessing from general training.

A model asked to generate a test for a specific application performs very differently when it's actually given that application's real page structure, requirements documentation, or existing test cases to retrieve from, versus being asked to guess at what a typical application in that category probably looks like. Grounding a request this way is closely related to what prompt engineering is trying to achieve manually, RAG automates the process of finding and including the right grounding material rather than requiring someone to paste it in by hand every time.


How it actually works

  • A question or task comes in, and the system searches a separate knowledge source for relevant content.
  • The most relevant retrieved pieces get included as context alongside the original question.
  • The model generates its response grounded in that retrieved material, not just patterns from training.
  • The knowledge source can be updated independently of the model itself, keeping answers current without retraining.
  • Retrieval quality directly limits answer quality, irrelevant or missing retrieved content still produces a weak or ungrounded answer.

Where it shows up

  • Generating a test case grounded in an application's actual page structure and requirements, rather than a generic guess.
  • Answering a question about internal documentation or a private codebase an LLM was never trained on.
  • Keeping a chatbot's answers current by retrieving from an up-to-date knowledge base instead of retraining the model.
  • Summarizing why a test failed by retrieving the actual relevant logs and prior similar failures as context.

Benefits and challenges

BenefitChallenge
Grounds an answer in specific, current, or private information the model was never trained on, cutting down on confidently wrong answers. Answer quality is capped by retrieval quality, if the system retrieves the wrong or irrelevant content, the model still generates around it.
The knowledge source can be updated independently of the model, keeping answers current without an expensive retraining cycle. Adds real infrastructure, a search or retrieval system has to be built and maintained alongside the model itself.
Reduces, though doesn't eliminate, hallucination, since the model has real material to ground its answer in rather than relying purely on memory. A model can still misinterpret or ignore retrieved content, grounding reduces the risk, it doesn't guarantee a correct answer.

Frequently asked questions

Does RAG eliminate AI hallucination completely?

No, it reduces the risk but doesn't eliminate it. A model given relevant retrieved context is far more likely to produce a grounded, accurate answer, but it can still misinterpret that context or generate something not actually supported by it. RAG narrows the problem, it doesn't fully solve it.

How is RAG different from fine-tuning a model?

Fine-tuning changes the model itself by further training it on specific data, which is expensive and has to be redone as that data changes. RAG keeps the model as is and instead retrieves relevant information at the moment of answering, which is generally cheaper to update since only the knowledge source needs to change, not the model.

What makes retrieval quality good or bad?

It comes down to how well the system finds genuinely relevant content for a given question, not just content that superficially matches keywords. A retrieval system that returns the wrong or incomplete material gives the model a poor foundation to answer from, regardless of how capable the underlying model is.


How Klarent helps

Klarent's AI agents ground test generation in the actual application under test, retrieving its real structure and behavior rather than relying on a model's general assumptions about what a similar application probably looks like.


Ready to eliminate QA bottlenecks? Talk to our team for a personalised walkthrough.

Book a free 30 minute call