Close Menu
    Trending
    • Understanding Context and Contextual Retrieval in RAG
    • The AI Bubble Has a Data Science Escape Hatch
    • Is the Pentagon allowed to surveil Americans with AI?
    • What Makes Quantum Machine Learning “Quantum”?
    • The Data Team’s Survival Guide for the Next Era of Data
    • The Black Box Problem: Why AI-Generated Code Stops Being Maintainable
    • How to Create Production-Ready Code with Claude Code
    • The AI Arms Race Has Real Numbers: Pentagon vs China 2026
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Understanding Context and Contextual Retrieval in RAG
    Artificial Intelligence

    Understanding Context and Contextual Retrieval in RAG

    ProfitlyAIBy ProfitlyAIMarch 7, 2026No Comments11 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    In my latest post, I how hybrid search will be utilised to considerably enhance the effectiveness of a RAG pipeline. RAG, in its fundamental model, utilizing simply semantic search on embeddings, will be very efficient, permitting us to utilise the facility of AI in our personal paperwork. Nonetheless, semantic search, as highly effective as it’s, when utilised in massive information bases, can typically miss precise matches of the consumer’s question, even when they exist within the paperwork. This weak spot of conventional RAG will be handled by including a key phrase search element within the pipeline, like BM25. On this method, hybrid search, combining semantic and key phrase search, results in way more complete outcomes and considerably improves the efficiency of a RAG system.

    Be that as it could, even when utilizing RAG with hybrid search, we will nonetheless typically miss essential data that’s scattered in several elements of the doc. This may occur as a result of when a doc is damaged down into textual content chunks, typically the context — that’s, the encompassing textual content of the chunk that kinds a part of its which means — is misplaced. This may particularly occur for textual content that’s complicated, with which means that’s interconnected and scattered throughout a number of pages, and inevitably can’t be wholly included inside a single chunk. Suppose, for instance, referencing a desk or a picture throughout a number of totally different textual content sections with out explicitly defining to which desk we’re refering to (e.g., “as proven within the Desk, earnings elevated by 6%” — which desk?). In consequence, when the textual content chunks are then retrieved, they’re stripped down of their context, typically ensuing within the retrieval of irrelevant chunks and era of irrelevant responses.

    This lack of context was a serious challenge for RAG techniques for a while, and a number of other not-so-successful options have been explored for bettering it. An apparent try for bettering this, is rising chunk dimension, however this typically additionally alters the semantic which means of every chunk and finally ends up making retrieval much less exact. One other strategy is rising chunk overlap. Whereas this helps to extend the preservation of context, it additionally will increase storage and computation prices. Most significantly, it doesn’t absolutely resolve the issue — we will nonetheless have essential interconnections to the chunk out of chunk boundaries. Extra superior approaches trying to unravel this problem embrace Hypothetical Document Embeddings (HyDE) or Document Summary Index. Nonetheless, these nonetheless fail to offer substantial enhancements.

    Finally, an strategy that successfully resolves this and considerably enhances the outcomes of a RAG system is contextual retrieval, originally introduced by Anthropic in 2024. Contextual retrieval goals to resolve the lack of context by preserving the context of the chunks and, due to this fact, bettering the accuracy of the retrieval step of the RAG pipeline.

    . . .

    What about context?

    Earlier than saying something about contextual retrieval, let’s take a step again and discuss a little bit bit about what context is. Positive, we’ve all heard concerning the context of LLMs or context home windows, however what are these about, actually?

    To be very exact, context refers to all of the tokens which might be out there to the LLM and primarily based on which it predicts the subsequent phrase — keep in mind, LLMs work by producing textual content by predicting it one phrase at a time. Thus, that would be the consumer immediate, the system immediate, directions, abilities, or every other tips influencing how the mannequin produces a response. Importantly, the a part of the ultimate response the mannequin has produced thus far can also be a part of the context, since every new token is generated primarily based on every part that got here earlier than it.

    Apparently, totally different contexts result in very totally different mannequin outputs. For instance:

    • ‘I went to a restaurant and ordered a‘ may output ‘pizza.‘
    • ‘I went to the pharmacy and acquired a‘ may output ‘medication.‘

    A basic limitation of LLMs is their context window. The context window of an LLM is the utmost variety of tokens that may be handed directly as enter to the mannequin and be taken into consideration to provide a single response. There are LLMs with bigger or smaller context home windows. Fashionable frontier fashions can deal with lots of of 1000’s of tokens in a single request, whereas earlier fashions typically had context home windows as small as 8k tokens.

    In an ideal world, we’d wish to simply cross all the data that the LLM must know within the context, and we’d probably get superb solutions. And that is true to some extent — a frontier mannequin like Opus 4.6 with a 200k token context window corresponds to about 500-600 pages of textual content. If all the data we have to present suits this dimension restrict, we will certainly simply embrace every part as is, as an enter to the LLM and get an ideal reply.

    The difficulty is that for many of real-world AI use instances, we have to make the most of some form of information base with a dimension that’s a lot past this threshold — assume, for example, authorized libraries or manuals of technical tools. Since fashions have these context window limitations, we sadly can not simply cross every part to the LLM and let it magically reply — now we have to somwhow decide what is crucial data that needs to be included in our restricted context window. And that’s primarily what the RAG methodology is all about — selecting the suitable data from a big information base in order to successfully reply a consumer’s question. Finally, this emerges as an optimization/ engineering drawback — context engineering — figuring out the suitable data to incorporate in a restricted context window, in order to provide the very best responses.

    That is essentially the most essential a part of a RAG system — ensuring the suitable data is retrieved and handed over as enter to the LLM. This may be executed with semantic search and key phrase search, as already defined. Nonetheless, even when bringing all semantically related chunks and all precise matches, there’s nonetheless a very good likelihood that some essential data could also be left behind.

    However what sort of data would this be? Since now we have coated the which means with semantic search and the precise matches with key phrase search, what different kind of knowledge is there to think about?

    Totally different paperwork with inherently totally different meanings might embrace elements which might be comparable and even an identical. Think about a recipe e-book and a chemical processing guide each instructing the reader to ‘Warmth the combination slowly’. The semantic which means of such a textual content chunk and the precise phrases are very comparable — an identical. On this instance, what kinds the which means of the textual content and permit us to separate between cooking and chemnical engineering is what we’re reffering to as context.

    Thus, that is the form of additional data we goal to protect. And that is precisely what contextual retrieval does: preserves the context — the encompassing which means — of every textual content chunk.

    . . .

    What about contextual retrieval?

    So, contextual retrieval is a strategy utilized in RAG aiming to protect the context of every chunk. On this method, when a bit is retrieved and handed over to the LLM as enter, we’re in a position to protect as a lot of its preliminary which means as attainable — the semantics, the key phrases, the context — all of it.

    To attain this, contextual retrieval means that we first generate a helper textual content for every chunk — particularly, the contextual textual content — that permits us to situate the textual content chunk within the authentic doc it comes from. In observe, we ask an LLM to generate this contextual textual content for every chunk. To do that, we offer the doc, together with the precise chunk, in a single request to an LLM and immediate it to “present the context to situate the precise chunk within the doc“. A immediate for producing the contextual textual content for our Italian Cookbook chunk would look one thing like this:

    <doc> 
    the whole doc Italian Cookbook doc the chunk comes from
    </doc> 
    
    Right here is the chunk we wish to place throughout the context of the complete doc.
    
    <chunk> 
    the precise chunk
    </chunk> 
    
    Present a quick context that situates this chunk throughout the total 
    doc to enhance search retrieval. Reply solely with the concise 
    context and nothing else.

    The LLM returns the contextual textual content which we mix with our preliminary textual content chunk. On this method, for every chunk of our preliminary textual content, we generate a contextual textual content that describes how this particular chunk is positioned in its guardian doc. For our instance, this may be one thing like:

    Context: Recipe step for simmering do-it-yourself tomato pasta sauce.
    Chunk: Warmth the combination slowly and stir sometimes to stop it from sticking.

    Which is certainly much more informative and particular! Now there is no such thing as a doubt about what this mysterious combination is, as a result of all the data wanted for identiying whether or not we’re speaking about tomato sauce or laboratory starch options is conveniently included throughout the identical chunk.

    From this level on, we take care of the preliminary chunk textual content and the contextual textual content as an unbreakable pair. Then, the remainder of the steps of RAG with hybrid search are carried out primarily in the identical method. That’s, we create embeddings which might be saved in a vector search and the BM25 index for every textual content chunk, prepended with its contextual textual content.

    This strategy, so simple as it’s, ends in astonishing enhancements within the retrieval efficiency of RAG pipelines. In line with Anthropic, Contextual Retrieval improves the retrieval accuracy by an impressive 35%.

    . . .

    Decreasing price with immediate caching

    I hear you asking, “However isn’t this going to break the bank?“. Surprisingly, no.

    Intuitively, we perceive that this setup goes to considerably enhance the price of ingestion for a RAG pipeline — primarily double it, if no more. In spite of everything we now added a bunch of additional calls to the LLM, didn’t we? That is true to some extent — certainly now, for every chunk, we make an extra name to the LLM with a view to situate it inside its supply doc and get the contextual textual content.

    Nonetheless, this can be a price that we’re solely paying as soon as, on the stage of doc ingestion. In contrast to different methods that try and protect context at runtime — resembling Hypothetical Doc Embeddings (HyDE) — contextual retrieval performs the heavy work throughout the doc ingestion stage. In runtime approaches, extra LLM calls are required for each consumer question, which may rapidly scale latency and operational prices. In distinction, contextual retrieval shifts the computation to the ingestion section, which means that the improved retrieval high quality comes with no extra overhead throughout runtime. On prime of those, extra methods can be utilized for additional lowering the contextual retrieval price. Extra exactly, caching can be utilized for producing the abstract of the doc solely as soon as after which situating every chunk towards the produced doc abstract.

    . . .

    On my thoughts

    Contextual retrieval represents a easy but highly effective enchancment to conventional RAG techniques. By enriching every chunk with contextual textual content, pinpointing its semantic place inside its supply doc, we dramatically scale back the anomaly of every chunk, and thus enhance the standard of the data handed to the LLM. Mixed with hybrid search, this system permits us to protect semantics, key phrases, and context concurrently.


    Cherished this submit? Let’s be buddies! Be a part of me on:

    📰Substack 💌 Medium 💼LinkedIn ☕Buy me a coffee!

    All photographs by the creator, besides talked about in any other case.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleThe AI Bubble Has a Data Science Escape Hatch
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    The AI Bubble Has a Data Science Escape Hatch

    March 7, 2026
    Artificial Intelligence

    What Makes Quantum Machine Learning “Quantum”?

    March 6, 2026
    Artificial Intelligence

    The Data Team’s Survival Guide for the Next Era of Data

    March 6, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Testa och jämför Google Nano Banana på LMArena mot andra bild-verktyg

    September 16, 2025

    How to Facilitate Effective AI Programming

    December 29, 2025

    Microsoft kommer automatiskt att installera Copilot AI på Windows 10/11 enheter

    September 25, 2025

    What is Universality in LLMs? How to Find Universal Neurons

    September 2, 2025

    Remembering Professor Emerita Jeanne Shapiro  Bamberger, a pioneer in music education | MIT News

    October 15, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    Googles framtidsvision är att Gemini utför googling åt användarna

    May 23, 2025

    Can We Use Chess to Predict Soccer?

    June 18, 2025

    Hybrid AI-modell CausVid skapar högkvalitativa videor på sekunder

    May 7, 2025
    Our Picks

    Understanding Context and Contextual Retrieval in RAG

    March 7, 2026

    The AI Bubble Has a Data Science Escape Hatch

    March 7, 2026

    Is the Pentagon allowed to surveil Americans with AI?

    March 6, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.