Deterministic
diagnostics
for RAG systems
RAG Doctor analyzes your retrieval-augmented generation pipelines, identifies architectural failures, and surfaces root-cause insights — without hallucination, without guesswork.
npm install -g rag-doctorAnalyzing 3 retrieved chunks across 1 query…
Running rule engine (pack: recommended)…
Root cause: low-retrieval-score → hallucination risk
3 findings · 1 critical · 2 warnings
The Problem
RAG failures are architectural problems, not model problems
Most teams blame the language model when RAG pipelines underperform. In reality, the problem is almost always upstream — bad retrieval, poor chunking, or context window mismanagement.
RAG Doctor exists to give teams the visibility they need to diagnose and fix these issues systematically, before they reach production.
RAG systems fail silently
Hallucinations don't come with stack traces. When your retrieval step returns low-quality chunks, the LLM confidently produces plausible-sounding nonsense — and your logs show nothing unusual.
Retrieval quality is invisible
Most teams have no systematic way to measure whether retrieved chunks are actually relevant. Relevance scores are often ignored or misunderstood until something goes wrong in production.
Duplicate context pollutes answers
Near-identical chunks from overlapping data sources fill the context window with redundant information, reducing diversity and wasting tokens on content the model has already seen.
No deterministic observability
Teams resort to ad-hoc logging, manual review, or prompt engineering workarounds instead of systematic architectural analysis. Problems recur because root causes are never identified.
Capabilities
Everything you need to diagnose RAG
Purpose-built tools for the full diagnostic lifecycle — from trace ingestion to root-cause reporting.
Deterministic Rule Engine
No probabilistic scoring or model-based guessing. Every finding is the result of strict, inspectable rules with defined thresholds and conditions.
Developer-First CLI
Run diagnostics from your terminal with a single command. Integrates naturally into CI pipelines, local development, and automated testing workflows.
Structured JSON Output
Machine-readable findings and diagnosis reports. Pipe results to dashboards, alerting systems, or test assertions without any parsing.
Root Cause Diagnosis
Go beyond surface findings. The diagnosis engine maps findings to primary causes, contributing factors, and actionable recommendations.
Configurable Rule Packs
Start with the recommended pack or switch to strict mode. Override individual rule thresholds to match your pipeline's specific requirements.
Embeddable Architecture
Import the analysis engine directly into your application or testing framework. Use it as a library, not just a CLI.
First-Class Documentation
Comprehensive docs covering architecture, rules, configuration, and contributing — written for engineers who want to understand the system deeply.
Open-Source Extensibility
Write custom rules, add new diagnostic heuristics, or build adapters for your trace format. The plugin architecture is designed for real-world extension.
Pipeline
How RAG Doctor works
A clean six-stage pipeline from raw trace to actionable insights, with no black boxes and no guesswork.
Trace Input
Provide a RAG trace — JSON file, object, or programmatic input. Supports LangChain, LlamaIndex, and custom formats.
Validation & Normalization
The ingestion layer validates trace structure, normalizes field names, and extracts queryable chunk data.
Rule Engine
Each active rule evaluates the normalized trace against its threshold conditions. Rules are stateless, composable, and inspectable.
Findings
Each triggered rule produces a structured finding: rule ID, severity, evidence, and affected chunk references.
Root Cause Diagnosis
The diagnostics engine maps findings to primary causes and contributing factors using a deterministic heuristic graph.
Structured Report
Output as human-readable text or structured JSON — ready for CI assertions, developer review, or dashboard ingestion.
CLI
Analyze from the terminal
RAG Doctor ships a powerful CLI for local development and CI workflows. One command. Structured output. Actionable insights.
analyzeRun the rule engine against a trace file and surface findings
diagnoseMap findings to root causes and generate a recommendation report
--jsonOutput machine-readable JSON for piping into CI assertions or dashboards
--configLoad a custom rule pack and threshold configuration
Install
# Install globally via npmnpm install -g rag-doctor # Or use directly with npxnpx rag-doctor --helpAnalyze
# Analyze a trace filerag-doctor analyze ./traces/session.json # Output as structured JSONrag-doctor analyze ./traces/session.json --json # Use a custom config filerag-doctor analyze ./traces/session.json --config .rag-doctor.jsonDiagnose
# Run root cause diagnosisrag-doctor diagnose ./traces/session.json # Diagnose with JSON output for CIrag-doctor diagnose ./traces/session.json --json | jq '.diagnosis.primaryCause'Config
// .rag-doctor.json{ "pack": "strict", "ruleOptions": { "duplicate-chunks": { "similarityThreshold": 0.85 }, "low-retrieval-score": { "minScore": 0.65 }, "oversized-chunk": { "maxTokens": 512 } }}Philosophy
Why deterministic > magical
Diagnostics tools should be more trustworthy than the systems they analyze. Using another LLM to evaluate your LLM pipeline is circular — and unreliable.
Architecture
Modular monorepo design
Each package has a single, clear responsibility. Embed only what you need, extend without forking.
@rag-doctor/types
Shared TypeScript types and interfaces. The single source of truth for trace shapes, findings, and diagnosis structures.
@rag-doctor/ingestion
Accepts raw trace objects, validates structure, and emits normalized internal representations.
@rag-doctor/rules
The rule library. Each rule is a pure function: context in, finding out. Built-in packs: recommended and strict.
@rag-doctor/core
Wires ingestion, rules, and reporters together. The public API for embedding analysis in your own application.
@rag-doctor/diagnostics
Aggregates findings and applies the heuristic graph to identify primary causes and generate recommendations.
@rag-doctor/reporters
Formats analysis output as structured JSON or human-readable text. Extensible for custom report formats.
rag-doctor
The command-line interface. Thin wrapper around @rag-doctor/core with argument parsing and terminal rendering.
Help shape the future of RAG tooling
RAG Doctor is open source and actively maintained. Whether you want to contribute rules, integrations, diagnostics, or documentation — your work directly improves the tool thousands of engineers depend on.
Custom Rules
Extend the rule engine with domain-specific analysis logic
Diagnostic Heuristics
Improve root cause mappings and recommendation quality
Trace Adapters
Add support for LangSmith, Weave, Phoenix, and more
Docs & Examples
Write guides, improve API docs, add real-world examples
Start diagnosing your RAG pipeline
Install in seconds. Get deterministic findings in minutes. Fix architectural problems before they reach your users.
npx rag-doctor analyze trace.json