Skip to main content

Overview

TeaRAGs is an MCP server that orchestrates code vectorization, trajectory enrichment, and quality-aware retrieval. It sits between the AI agent and the vector database, managing the complexity of embedding, git metadata extraction, and reranking.

System Architecture

Component Layers

1. Agent Layer

The AI agent (Claude Code, Roo, Cursor, or custom) orchestrates the overall workflow:

  • Decides when to search code
  • Formulates natural language queries
  • Interprets search results
  • Verifies findings with grep (best practice)
  • Makes code generation decisions

The agent communicates with TeaRAGs via the MCP protocol (stdio or HTTP transport).

2. TeaRAGs MCP Server (Orchestration Engine)

TeaRAGs is the central orchestrator with six internal subsystems:

ComponentResponsibilityKey Details
Code IndexerScans codebase, performs AST-aware chunking via tree-sitterRespects .gitignore / .contextignore. Handles incremental updates (added/modified/deleted files)
Git EnricherExtracts metadata from git log and git blameComputes 19 signals: churn, volatility, authorship, bug-fix rates, task IDs. File-level and chunk-level granularity
Search EngineConverts queries to vectors, applies filters, executes searchQdrant filters (language, path, git metadata). Semantic search and hybrid search (BM25 + RRF)
RerankerRe-scores results using trajectory signalsComposable presets: hotspots, ownership, techDebt, stable, etc. Custom weight configs supported
Embedding PipelineBatches chunks for efficient embedding generationManages concurrency, retry logic, backpressure. Supports Ollama, OpenAI, Cohere, Voyage AI
MCP Tools HandlerExposes MCP tools, handles invocation and validationTools: index_codebase, search_code, semantic_search, reindex_changes

3. External Services

ServiceRoleDetails
QdrantVector databaseDense vectors (768–3072 dim), sparse vectors (BM25 for hybrid search), payload (19 git signals + file metadata). Cosine similarity search at scale
Embedding ServiceText → vector conversionOllama (local, recommended: jina-embeddings-v2-base-code), OpenAI (text-embedding-3-small/large), Cohere (embed-english-v3.0), Voyage AI (voyage-code-2)

4. Data Sources

SourcePurposeDetails
CodebaseSource files and documentationTypeScript, Python, Go, Ruby, Markdown, README. Respects .gitignore exclusion rules
Git RepositoryHistory for trajectory enrichmentCommit history, author metadata, timestamps. Task IDs from commit messages (JIRA, GitHub, Linear)
Cache Storage (~/.tea-rags-mcp/)Incremental indexing and performanceSnapshots — file hash snapshots. Git cache — L1 (memory) + L2 (disk) for git blame. Logs — debug logs (DEBUG=1)

Request Flow

A typical search request flows through six steps:

1. Agent Invocation

Agent: search_code "authentication logic" --rerank stable

2. Query Embedding

TeaRAGs sends the query to the Embedding Service:

"authentication logic" → [0.23, -0.41, 0.18, ...]

TeaRAGs queries Qdrant with:

  • Query vector
  • Optional filters (language, path, author, etc.)
  • Limit (default: 50 candidates)

4. Semantic Ranking

Qdrant returns top 50 chunks ranked by cosine similarity:

[
{"path": "src/auth/middleware.ts", "score": 0.91, "git": {...}},
{"path": "src/auth/jwt.ts", "score": 0.87, "git": {...}},
...
]

5. Trajectory Reranking

TeaRAGs re-scores results using git signals and the stable preset:

  • Boosts low-churn, low-bugfix code
  • Penalizes high-volatility code
  • Returns top 5 chunks

6. Agent Decision

Agent receives enriched results:

  • Reads candidate files
  • Verifies with grep (e.g., grep "function authenticate")
  • Uses actual identifiers in generated code

Key Principles

TeaRAGs as Orchestrator

TeaRAGs does not replace the agent's decision-making. It provides:

  • High-recall candidate selection (semantic search finds relevant code)
  • Quality signals (trajectory enrichment quantifies stability, ownership, risk)
  • Structured results (file paths, line numbers, metadata)

The agent still:

  • Decides which code to use
  • Verifies exact identifiers with grep
  • Generates final code

Separation of Concerns

ComponentResponsibility
AgentWorkflow orchestration, decision-making, verification
TeaRAGsIndexing, embedding, enrichment, reranking
QdrantVector storage, similarity search
Embedding ServiceText → vector conversion
GitSource of truth for code history

Data Flow Direction

Indexing:  Codebase + Git → TeaRAGs → Embedding Service → Qdrant
Searching: Agent → TeaRAGs → Qdrant (retrieve) → TeaRAGs (rerank) → Agent

Performance Characteristics

  • Indexing: Millions of LOC in minutes (see benchmarks)
  • Search: Near-instant (<1s for most queries)
  • Incremental updates: Only changed files re-indexed
  • Concurrency: Configurable batch sizes, parallel workers
  • Caching: Git metadata cached, embedding pipeline batched

Next Steps