What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Contextual Retrieval adds a short, chunk-specific description of where a passage belongs in its source document, then indexes that description with the passage for both semantic and lexical search. In a Spring AI application, this is an ingestion and indexing decision—not a substitute for the framework’s retrieval pipeline—and virtual threads are a separate option for dispatching Anthropic HTTP requests.
Why a RAG chunk can lose the answer’s context
A passage can be meaningful in its original document but ambiguous after splitting. Anthropic illustrates the problem with the question, “What was the revenue growth for ACME Corp in Q2 2023?” A chunk that says only “The company’s revenue grew by 3% over the previous quarter” omits the company and period needed to connect it reliably to that question.
As an Amazon Associate I earn from qualifying purchases.
Traditional retrieval splits documents into passages and searches them through lexical matching, semantic embeddings, or both. Splitting can separate a pronoun from its antecedent, a relative date from the date it refers to, or a technical term from the section that defines it. Anthropic describes Contextual Retrieval as a preprocessing technique: use the full document to generate brief context for each individual chunk, prepend that context, and use the resulting text for retrieval.
What Contextual Retrieval adds
For each chunk, a language model sees the full source document and the chunk, then produces concise text that situates that chunk in the document. The added context might identify the subject, time period, section, or surrounding argument. Anthropic says this text is usually 50–100 tokens; that range and its example prompt are starting points, not universal settings.
#1 Best Overall
The important distinction is that the context is specific to each chunk. Repeating the same generic document summary before every passage is a different approach; Anthropic reports that generic summaries produced limited gains in its evaluation. Chunk-specific context can supply information that is absent from the local passage while retaining the passage’s own content.
Anthropic’s method puts the contextualized text into both retrieval channels: it is used to create embeddings and to build the BM25 index. This lets semantic search and lexical search consider the added identifiers alongside the original words. It does not mean that the generated prefix should be mistaken for source text. Preserve the original passage and its provenance, and distinguish contextual metadata from source content when assembling material for the model’s final answer.
What Anthropic’s reported evaluations show
Anthropic’s 2024 engineering article reports average top-20 retrieval results across codebases, fiction, arXiv papers, and science papers, using the top-performing embedding configuration in its analysis. The reported failure rate is the rate at which retrieval failed to return the relevant chunk within the top 20:
Free tools Windows power users keep installed
One-click scans. No signup required.
| Approach in Anthropic’s evaluation | Top-20 retrieval failure rate | Reported change from baseline |
|---|---|---|
| Baseline | 5.7% | Baseline |
| Contextual Embeddings | 3.7% | 35% reduction |
| Contextual Embeddings plus Contextual BM25 | 2.9% | 49% reduction |
Anthropic’s separate 2024 Cookbook example concerns nine codebases, basic character-based splitting, and a dataset of 248 queries, each with a designated “golden chunk.” In that setup, Anthropic reports Pass@10 improving from about 87% to about 95% with Contextual Embeddings. Pass@10 is a different evaluation measure from the top-20 failure rates above; the figures should not be treated as one combined benchmark.
These are source-reported evaluations, not a guarantee for a different corpus. Chunk boundaries and overlap, domain terminology, embedding model, retrieval depth, and contextualizer prompt can all affect the outcome. Evaluate against representative questions from the target system and inspect whether retrieved chunks actually contain enough source material to answer them.
Account for preprocessing cost and update work
Anthropic’s 2024 article gives an illustrative one-time cost of $1.02 per million document tokens under specific assumptions: 800-token chunks, 8,000-token documents, 50 tokens of context instructions, 100 generated context tokens per chunk, and prompt caching. This is a historical estimate under those assumptions, not a current general provider price or a quote for a production workload.
Contextualization adds model work before retrieval. Estimate its impact using the actual document and chunk distributions, prompt and output token use, cache behavior, document update rate, and the cost of reprocessing changed documents and rebuilding affected indexes. A corpus that changes frequently may have a different operating trade-off from a static collection. Compare the added work with retrieval quality measured on your own evaluation set.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Fit the preprocessing into Spring AI’s RAG flow
Spring AI offers both a simpler advisor path and a modular RAG API. Its QuestionAnswerAdvisor queries a vector store and appends retrieved documents to the prompt; the documented dependency for that path is spring-ai-vector-store-advisor. The modular RetrievalAugmentationAdvisor, documented with spring-ai-rag, lets an application compose stages such as query transformation, retrieval, document joining, post-processing, and query augmentation.
Contextual Retrieval belongs in ingestion because it changes the text used to index each chunk. A practical flow is:
- Parse and split: retain the original document and record stable identifiers and provenance for each chunk.
- Generate per-chunk context: provide the full document and one chunk to the contextualizer, requesting concise text that situates that chunk.
- Keep source and context distinct: store the original chunk separately from the generated prefix, so downstream code can preserve provenance and avoid presenting generated context as quoted source.
- Index for retrieval: use the contextualized text for embedding generation and lexical indexing, including BM25 where the application uses that channel.
- Retrieve and assemble: use Spring AI’s chosen advisor or composed RAG stages to retrieve, join, and post-process documents, then augment the model prompt.
- Evaluate changes: test representative questions and retrieval outcomes when adjusting chunking, contextualization, or retrieval settings.
Spring AI’s ContextualQueryAugmenter is not the chunk-context generation step. It augments a user query with contextual data from documents that have already been retrieved. That is a query or prompt-stage operation, while Anthropic’s contextualization creates per-chunk text before indexing.
Use virtual threads for Anthropic HTTP dispatch—with lifecycle ownership
The Spring AI Anthropic integration reference documents a configurable dispatcher executor for synchronous and asynchronous streaming clients. Its example uses a virtual-thread-per-task executor:
AnthropicChatModel chatModel = AnthropicChatModel.builder()
.options(...)
.dispatcherExecutor(Executors.newVirtualThreadPerTaskExecutor())
.build();
Virtual threads are an option for high HTTP concurrency or Java 21-and-later workloads, not a performance guarantee. If the application supplies the executor, the application owns its lifecycle: Spring AI will not call shutdown() on it. Retain the executor and shut it down as part of the application’s managed lifecycle. If this option is omitted, Spring AI creates and cleans up its internal executor.
Best Value
This dispatcher setting is distinct from executor configuration for RAG retrieval. A Spring AI engineering example describes a modular RAG advisor whose per-query retrieval threads are non-daemon, keeping its command-line process alive after printing a response. In that example, passing Spring Boot’s auto-configured TaskExecutor through .taskExecutor(...) addresses the issue; the example says spring.threads.virtual.enabled=true enables virtual threads for that configuration. This is scoped to that advisor example and is not the Anthropic HTTP dispatcher setting.
The same engineering example warns that its illustrated flow makes two LLM calls before retrieval and one service call per retrieved chunk. Measure latency and cost for the actual flow rather than assuming that modular composition or virtual threads make these calls free.
Plan for streaming trace context
The Spring AI Anthropic reference says synchronous HTTP spans are nested under the model operation, but streaming HTTP spans may not be. It attributes this to the Anthropic Java SDK’s asynchronous implementation moving onto ForkJoinPool.commonPool() before calling Spring AI’s HTTP client, which can lose the calling thread’s observation context. The reference says traceparent is still propagated and suggests correlating okhttp.requests with the model operation by trace ID or timestamp range.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchCheck this behavior against the exact Spring AI and Anthropic SDK versions in use: asynchronous execution and instrumentation can change. When diagnosing a streaming request, inspect trace IDs and timestamps rather than assuming every HTTP span will appear as a child of the model span.
Choose and validate the retrieval design
Contextual Retrieval adds useful information at an engineering cost. The design decision is not simply whether to prepend text, but whether the improvement on the application’s own questions justifies contextualization, indexing, and update work.
- Choose the context strategy: compare no added text, a generic document summary, and per-chunk context generated from the full source.
- Choose retrieval channels: evaluate semantic embeddings and lexical BM25 separately as well as together where appropriate.
- Choose a relevant metric: report a defined retrieval measure, such as failure at a stated top-k or task-specific success, along with the corpus and evaluation set.
- Track preprocessing burden: measure contextualizer calls and tokens, cache behavior, document update cadence, and the index work required when sources change.
- Keep runtime responsibilities separate: manage the Anthropic dispatcher lifecycle independently from any RAG advisor executor, and verify tracing behavior for streaming requests.
Spring AI’s RAG reference displayed version 2.0.1 when accessed on October 7, 2026. Check the current documentation and the application’s Spring AI BOM before adopting version-specific dependencies or configuration. The Anthropic integration behavior, executor APIs, SDK caveats, and provider pricing can change over time.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




