Skip to content

RAG: Add citation tracking and attribution system #7

Description

@sfloess

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

Scope

Implement citation tracking that maps generated answer segments back to their source chunks, providing transparent attribution and verifiability.

Details

  • Parse LLM output to extract inline citation references
  • Map citations back to original source documents with metadata (filename, chunk index, similarity score)
  • Produce a structured citations list alongside the answer
  • Support citation formats: inline [Source: X] and appended bibliography
  • Track citation coverage: what percentage of the answer is grounded in retrieved sources

Output Structure

class RAGResult:
    answer: str                    # Generated answer text
    citations: List[Citation]      # Source attributions
    retrieval_scores: List[float]  # Per-chunk relevance scores
    coverage: float                # % of answer grounded in sources

class Citation:
    source: str        # e.g., "consensus-guide.md"
    chunk_index: int   # Which chunk in the source
    similarity: float  # Retrieval similarity score
    text_span: str     # The cited portion of the answer

Acceptance Criteria

  • Citations are extracted from LLM output and mapped to source chunks
  • Structured citation objects include source, score, and text span
  • Coverage metric indicates how well-grounded the answer is
  • Citations are deduplicated (same source referenced multiple times)
  • Unit tests for citation parsing, mapping, and coverage calculation

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