Skip to content

RAG: Build context assembly from retrieved chunks #5

Description

@sfloess

Part of #2: Add RAG (Retrieval Augmented Generation) with citations

Scope

Implement the context builder that takes reranked chunks and assembles them into a structured context window suitable for LLM consumption.

Details

  • Accept top-k reranked chunks with metadata (source, score, position)
  • Assemble chunks into a coherent context string with source attribution markers
  • Respect token budget constraints (configurable max context tokens)
  • Handle chunk overlap and deduplication (adjacent chunks from same document)
  • Preserve source metadata for downstream citation tracking
  • Order chunks by relevance score within the context window

Context Format

[Source: consensus-guide.md, chunk 3, score: 0.92]
Multi-model consensus uses 3+ AI models to validate outputs...

[Source: arbiter-pattern.md, chunk 1, score: 0.87]
The arbiter/worker pattern distributes tasks across workers...

Acceptance Criteria

  • Context builder produces structured context from ranked chunks
  • Token budget is enforced (truncation with priority to highest-scored chunks)
  • Duplicate/overlapping chunks from the same source are merged
  • Source attribution markers are embedded for citation extraction
  • Unit tests for context assembly, token budgeting, and deduplication

Metadata

Metadata

Assignees

No one assigned

    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