Services

Resources

Company

/

Retrieval-augmented generation

RAG (retrieval-augmented generation)

Retrieval-augmented generation (RAG) is a technique where an application first retrieves relevant passages from its own data, then passes them to a large language model (LLM) together with the user's question. The model answers from that supplied context. RAG lets an LLM use private or recent information without retraining the model.

How it works

At ingest time, documents are split into chunks, each chunk is turned into an embedding, and the embeddings are stored in a vector database. At query time the pipeline has three steps:

  1. Embed the user's question.

  2. Search the vector store for the closest chunks.

  3. Send the question plus those chunks to the LLM to generate the answer.

For example, retrieving the top 4 chunks of 500 tokens each adds about 2,000 tokens of context to every request.

Why it matters in production

A RAG answer can be wrong because retrieval found the wrong chunks, even when the model works correctly. Each step adds latency and token cost. Teams need traces for each step and a measure of retrieval quality, such as similarity scores, to tell a retrieval problem from a generation problem.

See also

On the One2N blog

References

  1. Retrieval-augmented generation for knowledge-intensive NLP tasks (Lewis et al., 2020)

Retrieval-augmented generation in one diagram: at ingest, docs become chunks and embeddings in a vector DB. At query time, step 1 embeds the user question, step 2 searches the vector DB, and the top 4 chunks (4 x 500 = 2,000 tokens) go with the question to the LLM in step 3, which writes the answer. A red note says wrong chunks in, wrong answer out.

Putting this into practice?

Talk to One2N about our AI engineering services

Talk to One2N about our AI engineering services