Skip to content

Add RAG (Retrieval Augmented Generation) with citations #2

Description

@sfloess

Concept Proven in .claude Testing Ground

Source: claude-global-skills/shared/rag.py

What It Does

Query knowledge base → retrieve relevant chunks → generate answer with citations.

Critical for cross-session learning!

Components

  1. Hybrid search (semantic + keyword + RRF)
  2. Reranking (bi-encoder → cross-encoder)
  3. Context building (from retrieved chunks)
  4. Answer generation (LLM with context)
  5. Citation tracking (which sources used)

Example

from knowledge_ai import RAG

rag = RAG(collection='my-docs')

# Query
result = rag.query('How does multi-model consensus work?')

print(result.answer)
# "Multi-model consensus uses 3+ AI models..."

print(result.citations)
# [{"source": "consensus-guide.md", "similarity": 0.92}]

Without RAG

  • ✅ Store memories
  • ✅ Search memories
  • ❌ Generate answers FROM memories

With RAG

  • ✅ Store memories
  • ✅ Search memories
  • Generate answers FROM memories with citations

Benefits

Cross-Session Learning

Session A:

User: "Use arbiter/worker pattern for consensus"
→ Stored with embeddings

Session B:

User: "How should I validate with multiple AIs?"
→ RAG finds Session A memory
→ Responds: "Use arbiter/worker pattern..." [Citation: Session A]

Trust via Citations

  • Shows which sources were used
  • User can verify answer accuracy
  • Transparent retrieval process

Implementation

Add to knowledge-ai:

  • rag.py (Python core)
  • rag.js (JavaScript for Claude Code)
  • Integrate with existing:
    • VectorDB (retrieval)
    • Semantic search (hybrid + reranking)
    • Chunking (context building)
  • Add citation tracking
  • Add retrieval quality metrics

Architecture

Query → Hybrid Search → Rerank → Build Context → LLM Generate → Citations
         (semantic+keyword)  (precision)  (top-k chunks)   (with context)

Related

  • Tested in: claude-global-skills (GitLab)
  • Requires: vectordb-ai, semantic-search-ai
  • Use case: Cross-session AI learning
  • Citations: Build trust and transparency

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions