> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Contextual RAG

> Prepend LLM-generated context to each chunk before embedding it.

Addresses the "lost in the middle" problem in retrieval. An LLM generates a
succinct piece of context for each document chunk, which is prepended to the
chunk before embedding, so a chunk carries enough surrounding meaning to be
retrieved for the right queries.

> [!NOTE]
>
> This example is a runnable notebook in the
> [vectordb-recipes](https://github.com/lancedb/vectordb-recipes) repository rather than a page here.

> [card] [Open in Colab](https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/Contextual-RAG/Anthropic_Contextual_RAG.ipynb)
>
> Run it end to end in the browser.

> [card] [View on GitHub](https://github.com/lancedb/vectordb-recipes/tree/main/examples/Contextual-RAG)
>
> Read the source.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.