Client-Side Evaluation: Computes lexical token overlap and sentence matches locally in your browser JavaScript runtime without transmitting data to backend servers.

1. Purpose & Lexical Attribution Scope

Retrieval-Augmented Generation (RAG) is a widely adopted architecture for grounding large language model completions in retrieved enterprise documentation. However, generating reliable responses requires inspecting whether the model's assertions are actually anchored to the retrieved context chunks.

The RAG Retrieval Debugger provides a fast, deterministic, client-side attribution tool to analyze lexical overlap and sentence-level source attribution to identify potentially unsupported claims before shipping prompt changes or evaluation pipelines into production.

2. How to Use the Debugger

  1. Input Context Passages: Paste the text chunks retrieved by your vector database or search index that were supplied to the LLM context.
  2. Input Generated Response: Paste the response generated by the model under audit.
  3. Or Test Presets:
    • High Overlap: Demonstrates a well-anchored response where factual entities match source passages.
    • Contradictory Claim: Demonstrates why lexical overlap is not semantic truth: the response inverts the factual meaning while maintaining high keyword overlap.
    • Paraphrased: Demonstrates a vocabulary gap: the response is faithful but uses synonyms, resulting in lower lexical overlap.
    • Unsupported: Demonstrates extrinsic hallucination where fabricated concepts share near-zero overlap with source passages.
  4. Analyze: Click Analyze Overlap. The tool tokenizes both inputs, filters common stopwords, segments the response into sentences, and computes directional token containment ratios against the source text and individual source sentences.
  5. Review Breakdown: Inspect highlighted matched tokens, nearest source sentences, and flagged low-overlap sentences.

3. Scoring Methodology & Mathematical Definition

The tool implements directional lexical containment scoring:

  1. Normalization & Tokenization: Both passages ($D$) and response ($R$) are lowercased and stripped of punctuation. Common functional stopwords (articles, prepositions, auxiliary verbs) are filtered out to isolate content words: $$\text{Tokens}(T) = \{ w \in \text{split}(T) \mid w \notin \text{Stopwords} \land \text{len}(w) > 1 \}$$
  2. Sentence Segmentation: The response is split into individual sentences $S_1, S_2, \dots, S_n$ using boundary regexes.
  3. Sentence Overlap Ratio: For each sentence $S_i$, the overlap ratio $O(S_i)$ measures what fraction of its content tokens appear in the passage token set $V_D$: $$O(S_i) = \frac{|\text{Tokens}(S_i) \cap V_D|}{|\text{Tokens}(S_i)|}$$
  4. Source Sentence Matching: For each generated sentence $S_i$, the tool additionally checks containment against each individual source passage sentence $P_j$ to identify the closest source attribution candidate: $$P_{\text{match}}(S_i) = \arg\max_{P_j} |\text{Tokens}(S_i) \cap \text{Tokens}(P_j)|$$
  5. Attribution Threshold: Sentences where $O(S_i) \ge 0.40$ (40%) are classified as Attributed / Grounded. Sentences with $O(S_i) < 0.40$ are flagged as Potential Unsupported Claims.

4. Scope & Heuristic Limitations

Methodology Notice: Lexical Overlap vs Semantic Entailment

Lexical token overlap is an efficient surface-level diagnostic filter, not a complete Natural Language Inference (NLI) model or semantic proof:

  • Paraphrasing False Positives: If the model synthesizes the correct facts using high-level synonyms or abstract summaries, lexical overlap will be lower even though the answer is factually faithful.
  • Entity Inversion False Negatives: A model that says "Acme Vault does NOT encrypt data" maintains high token overlap with a passage stating "Acme Vault encrypts data", despite inverting the factual meaning.
  • For mission-critical production pipelines, use this heuristic tool as an initial triage layer alongside LLM-as-a-judge or NLI cross-encoder benchmarks.

5. Related Tools & Research