---
title: "Contextual retrieval pattern for AI agents | Agentic Pattern Language"
description: "Before indexing, prepend to each chunk a short model-written note on where it sits in its document. Sourced from Merola and Singh, Anthropic, and Amazon Web Services."
url: https://agenticpatternlanguage.com/patterns/contextual-retrieval/
---

23 [One call](https://agenticpatternlanguage.com/#one-call)

# Contextual retrieval

Before indexing, prepend to each chunk a short model-written note on where it sits in its document.

![](https://agenticpatternlanguage.com/_astro/onyx.app.CizOlUK4_1f7fBW.webp) Merola and Singh, Anthropic, Amazon Web Services, Onyx

[How to read this](https://agenticpatternlanguage.com/notation/)

## Part of

* [Retrieval-augmented generation](https://agenticpatternlanguage.com/patterns/retrieval-augmented-generation/)

## The problem

Split into chunks, a passage can lose the context that says what it is about.

> In traditional RAG, documents are typically split into smaller chunks for efficient retrieval. While this approach works well for many applications, it can lead to problems when individual chunks lack sufficient context.

Anthropic [Contextual retrieval in AI systems](https://www.anthropic.com/engineering/contextual-retrieval) Sep 19, 2024

## Therefore

> Contextual Retrieval solves this problem by prepending chunk-specific explanatory context to each chunk before embedding (“Contextual Embeddings”) and creating the BM25 index (“Contextual BM25”).

Anthropic [Contextual retrieval in AI systems](https://www.anthropic.com/engineering/contextual-retrieval) Sep 19, 2024

> Contextual retrieval enhances traditional RAG by adding chunk-specific explanatory context to each chunk before generating embeddings.

Amazon Web Services [Contextual retrieval in Anthropic using Amazon Bedrock Knowledge Bases](https://aws.amazon.com/blogs/machine-learning/contextual-retrieval-in-anthropic-using-amazon-bedrock-knowledge-bases/) Jun 5, 2025

> Contextual retrieval preserves coherence by prepending LLM-generated context to chunks, while late chunking embeds entire documents to retain global context before segmenting.

Merola and Singh [Reconstructing Context: Evaluating Advanced Chunking Strategies for Retrieval-Augmented Generation](https://arxiv.org/abs/2504.19754)

## In use

Onyx

> An LLM adds a short, document-aware summary to each chunk. This improves retrieval for chunks that are ambiguous on their own.

![](https://agenticpatternlanguage.com/_astro/onyx.app.CizOlUK4_ZdplyK.webp) Onyx [Data Flows - Onyx Documentation](https://docs.onyx.app/security/architecture/data_flows)

## Where it breaks

It needs more computation than indexing the chunks alone.

> Our results indicate that contextual retrieval preserves semantic coherence more effectively but requires greater computational resources.

Merola and Singh [Reconstructing Context: Evaluating Advanced Chunking Strategies for Retrieval-Augmented Generation](https://arxiv.org/abs/2504.19754)

## Sources

1. [Reconstructing Context: Evaluating Advanced Chunking Strategies for Retrieval-Augmented Generation](https://arxiv.org/abs/2504.19754) Carlo Merola, Jaspinder Singh, Merola and Singh
2. [Contextual retrieval in AI systems](https://www.anthropic.com/engineering/contextual-retrieval) Anthropic, Sep 19, 2024
3. [Contextual retrieval in Anthropic using Amazon Bedrock Knowledge Bases](https://aws.amazon.com/blogs/machine-learning/contextual-retrieval-in-anthropic-using-amazon-bedrock-knowledge-bases/) Suheel Farooq, Sharon Li, Venkata Moparthi, Qingwei Li, Vinita Shadangi, Amazon Web Services, Jun 5, 2025
4. [Data Flows - Onyx Documentation](https://docs.onyx.app/security/architecture/data_flows) Onyx

Added Nov 14, 2026
