Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

Retrieval-Augmented Generation

Also RAG

Retrieval-augmented generation (RAG) answers a query over a text larger than an LLM's context size by splitting the text into chunks, embedding them, retrieving the k chunks most similar to the query embedding, and passing only their text to the LLM with a suitable prompt.

Properties#

  • Motivation: context sizes are large (400k tokens for GPT-5, 1M for Gemini Pro), but many applications query texts larger than that. ES12: the transcripts of all lecture recordings exceed the context size of the provided LLM. Since only kk chunks enter the prompt, the text can be arbitrarily large.
  • Embedding method: a sum of word embeddings (ES11) is simplistic, because not every word is equally relevant. ES12 uses an embedding API (mixedbread-ai/mxbai-embed-large-v1) that computes one embedding per text (a dedicated embedding model, such as a sentence transformer).
  • Retrieval: a linear scan over all chunk embeddings suffices for ES12; real applications precompute a special data structure. With normalized embeddings, all similarities are one matrix-vector product (Cosine Similarity > Formula).
  • Tuning knobs: chunk size, overlap, the embedding model, kk and the system prompt (ES12: experiment with kk, chunk sizes and system prompts).
  • ES12 details: one chunk per subtitle paragraph (one paragraph per timestamp); remove the timestamps before embedding, as they carry no useful information.

Example#

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only