الدليل الفني

Contextual Retrieval

Contextual retrieval is a RAG technique that prepends a short, document-aware explanation to each chunk before it is embedded and indexed for keyword search, so a chunk still makes sense when read on its own.

  • 4 دقائق قراءة
  • آخر تحديث
في هذه الصفحة4 دقائق قراءة
  1. نظرة عامة
  2. الغوص العميق
  3. التأثير الاستراتيجي
  4. The Future of Contextual Retrieval
  5. التنفيذ في العالم الحقيقي
  6. المخاطر والدرابزين
  7. خارطة طريق التنفيذ
  8. استمر في الاستكشاف
  9. الأسئلة المتداولة

نظرة عامة

It matters because chunks often lose key information when split from their document, such as which company, product or time period they refer to, and that loss causes the retriever to miss the right passage.

الغوص العميق

Standard RAG splits documents into chunks, embeds each chunk, and retrieves the chunks most similar to a question. The problem is that splitting strips context. A chunk that says "the company's revenue grew by 3%" does not say which company or which period, so neither semantic search nor keyword search can reliably match it to a question that names them. Anthropic described contextual retrieval in September 2024. For each chunk, a language model is given the whole document and the chunk, and asked to write a brief context (typically around 50 to 100 tokens) that situates the chunk within the document. That context is prepended to the chunk. The combined text is then used in two indexes: an embedding index (contextual embeddings) and a BM25 keyword index (contextual BM25). At query time, results from both are combined, and optionally a reranker reorders the top candidates. In Anthropic's reported experiments across several datasets, contextual embeddings plus contextual BM25 reduced the top-20 retrieval failure rate by about 49 percent compared with standard embeddings, and adding reranking brought the reduction to about 67 percent. Results on your own data can differ, so it is worth measuring. The cost is at indexing time: one model call per chunk, each including the full document. Prompt caching makes this much cheaper, because the document is cached once and reused across all its chunks. Misconceptions to avoid: the added context is used for retrieval, and you can choose whether to show it to the generator. It does not replace good chunking, and for small knowledge bases that fit in the model's context window, sending everything directly may be simpler than any retrieval pipeline.

التأثير الاستراتيجي

التكلفة والميزانية

تؤدي قرارات الهندسة المعمارية إلى زيادة الأداء وتكلفة التشغيل لسنوات.

قرارات أوضح

يساعد التعليم الفني الفرق على اختيار المجموعة المناسبة، وليس فقط المجموعة الأحدث.

مراقبة الجودة

تعمل الخيارات الهندسية الأفضل على تقليل حوادث الموثوقية في الإنتاج.

The Future of Contextual Retrieval

Contextual retrieval reflects a broader trend of spending more computation at indexing time to make query time more reliable. As model calls get cheaper and caching becomes standard, adding context to chunks is likely to become a default step in many RAG pipelines. Longer context windows reduce the need for retrieval in small collections but not in large ones, so techniques like this should stay relevant for big knowledge bases. Expect more combinations with metadata filtering, knowledge graphs and late-interaction retrieval, with teams choosing based on measured recall rather than fashion.

التنفيذ في العالم الحقيقي

A chunk from a quarterly report reads only "Revenue grew 3% over the previous quarter"; contextual retrieval prepends that it comes from a specific company's Q2 filing, so a search naming that company and quarter finds it.

In an employee handbook, a chunk saying "This applies after 90 days" gains a prefix explaining it is from the section on remote-work eligibility.

A software documentation assistant adds context noting that a configuration chunk belongs to version 3 of an API, reducing confusion with similar text from version 2.

A support knowledge base prefixes troubleshooting chunks with the product model they cover, so questions about one model stop retrieving steps for another.

المخاطر والدرابزين

  • يمكن أن يؤدي تحسين معيار واحد إلى إخفاء نقاط ضعف النظام الأوسع.

  • غالبًا ما يتم التقليل من تكاليف البنية التحتية والصيانة.

  • يمكن أن تنمو الفجوات الأمنية وقابلية المراقبة عندما تصبح الأنظمة أكثر تعقيدًا.

خارطة طريق التنفيذ

  1. تحديد الكمون والجودة وأهداف التكلفة قبل التنفيذ.

  2. المعيار في ظل ظروف التحميل والبيانات الواقعية.

  3. مراقبة الأدوات للأخطاء والانجراف وتأثير المستخدم.

  4. قم بإعداد مسارات التراجع والاستجابة للحوادث قبل القياس.

استمر في الاستكشاف

Free newsletter

Get the daily AI briefing

Three verified AI stories every weekday morning, written in plain English. Free forever, no ads.

One email each weekday. Unsubscribe in one click. We never sell or share your address.

Test yourself

Take the Contextual Retrieval quiz

Instant feedback on every answer, and a shareable certificate with a verifiable ID once you pass a course.

ابدأ الاختبار

Support free AI education. AI Understanding is a 501(c)(3) nonprofit — no ads, no paywall, ever. Make a donation

الأسئلة المتداولة

What is Contextual Retrieval?

Contextual retrieval is a RAG technique that prepends a short, document-aware explanation to each chunk before it is embedded and indexed for keyword search, so a chunk still makes sense when read on its own. It matters because chunks often lose key information when split from their document, such as which company, product or time period they refer to, and that loss causes the retriever to miss the right passage.

What problem does contextual retrieval solve?

Splitting removes surrounding context, so an isolated chunk may not mention the entity or period a question asks about.

How is the context for each chunk generated?

The model is given the full document and the chunk and returns a brief context that places the chunk within the document.

Which two indexes receive the contextualized chunk text in Anthropic's approach?

The method uses contextual embeddings and contextual BM25, then combines their results.

According to Anthropic's reported experiments, roughly how much did contextual embeddings plus contextual BM25 reduce top-20 retrieval failures?

Anthropic reported about a 49 percent reduction, rising to about 67 percent with reranking. Results on other data can differ.

Why does prompt caching make contextual retrieval cheaper?

Each chunk's call includes the full document; caching that shared prefix avoids paying full price repeatedly.