Skip to content

Wire live context-generator for Contextual-Retrieval (one Claude call per chunk) #608

Description

@mdheller

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions