O&O ConsultingBook a free call

Home / Insights / AI in Practice

Retrieval-Augmented Generation: Giving AI Your Own Knowledge

How to ground a language model's answers in your documents, and where such systems fail.

O&O Consulting · · 2 min read

Files and documents used as a knowledge source

A general model knows nothing about your latest price list or internal policy. Retrieval-augmented generation, or RAG, supplies that knowledge when it is needed. The term comes from a 2020 paper by Patrick Lewis and colleagues.

How it works

Documents are split into passages and each is converted to an embedding, a vector capturing meaning. When a question arrives, it is embedded too, and the closest passages are fetched. These are placed in the prompt with an instruction to answer from them and to say which were used.

Many systems combine meaning-based search with keyword search, since exact terms such as part numbers are easy to miss semantically, and then re-order candidates with a second model.

A retrieval-augmented generation pipelineIllustrative diagram, not data
Split documents into passagesIndex them by meaningRetrieve passages for a questionGive them to the modelAnswer with citations
Split documents into passagesIndex them by meaningRetrieve passages for a questionGive them to the modelAnswer with citations

Diagram by O&O Consulting.

Advantages

  • New or corrected documents take effect as soon as they are indexed.
  • Answers can point to a source a person can open.
  • Access rules can limit retrieval to documents a user is allowed to see.

Where failures come from

If the right passage is not retrieved, the model may answer from general knowledge or guess. Passages split in the wrong place lose their meaning. Outdated and current versions of a policy may both be retrieved. Even with correct passages, a model can misstate them.

Evaluate the stages separately: did retrieval find the evidence, and did the answer follow it?

Security

Retrieved text is untrusted input. A document containing instructions aimed at the model can try to change its behaviour, known as indirect prompt injection. Permission checks must be enforced by the system that retrieves documents, not left to the model.

Limitations and open questions

RAG struggles with questions that require combining facts across many documents, or totals across records, which a database query handles better. Citations can be attached to claims they do not actually support, so important answers still need verification.

References

  • Lewis, P. et al. (2020). "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks." arxiv.org/abs/2005.11401
  • Liu, N. F. et al. (2023). "Lost in the Middle: How Language Models Use Long Contexts." arxiv.org/abs/2307.03172
  • Greshake, K. et al. (2023). "Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection." arxiv.org/abs/2302.12173

This article is general information, not financial, legal or investment advice. AI research and rules change quickly; check the cited sources for the current position.