Follow-up to #607 (Contextual-Retrieval preprocessing).
#607 ships the preprocessing lane with a deterministic doc-summary stub as the default ContextGenerator so CI runs with no live LLM. This issue is to wire the live generator: for each chunk, one Claude call that returns the ~50–100 token situating blurb (the actual Anthropic pattern), prompt-cached against the whole document to keep cost down.
Scope
- Implement a
ContextGenerator backed by a Claude call (the situate-this-chunk prompt from the Anthropic cookbook), with the full document as cached context.
- Swap it into the
generate seam of buildContextualIndex / contextualizeChunks (agent-machine/lib/contextual-retrieval.ts), gated behind an env flag; fall back to docSummaryContext when the LLM is unavailable (same degrade-not-throw discipline as the embedder).
- Wire the preprocessor into
doc-store.ingestDocument between chunkTextWithSpans() and embedText().
- Cost/latency guardrails: prompt-cache the document, batch, cap tokens.
Out of scope (already landed in #607)
Refs #607 #604 #82
Follow-up to #607 (Contextual-Retrieval preprocessing).
#607 ships the preprocessing lane with a deterministic doc-summary stub as the default
ContextGeneratorso CI runs with no live LLM. This issue is to wire the live generator: for each chunk, one Claude call that returns the ~50–100 token situating blurb (the actual Anthropic pattern), prompt-cached against the whole document to keep cost down.Scope
ContextGeneratorbacked by a Claude call (the situate-this-chunk prompt from the Anthropic cookbook), with the full document as cached context.generateseam ofbuildContextualIndex/contextualizeChunks(agent-machine/lib/contextual-retrieval.ts), gated behind an env flag; fall back todocSummaryContextwhen the LLM is unavailable (same degrade-not-throw discipline as the embedder).doc-store.ingestDocumentbetweenchunkTextWithSpans()andembedText().Out of scope (already landed in #607)
Refs #607 #604 #82