02 Project

LLM ENGINEERING · INFORMATION RETRIEVAL · EVALUATION

RAG Benchmark

From Retrieval Quality to Grounded Answers

Research Question

“How do retrieval strategies, context size, and language model selection affect the reliability and efficiency of a RAG system?”

Designed and implemented a reproducible benchmarking pipeline to evaluate sparse and dense retrieval, local language models, and their impact on answer correctness, source grounding, and response latency.

Independent Project·September 2026
PythonQdrantBM25OllamaGranite 3B/8BBGE-small
100Test Queries
66.15%Top Recall@5
64%Top Grounding
RAG Benchmark project visual
LLM / RAG2026
RoleIndependent Project · September 2026
01 / THE CHALLENGE & CONTEXT

Finding Information vs. Answering Correctly

A reproducible document-grounded evaluation across retrieval strategies, chunking granularities, and local language models.

The Problem

Finding information is not the same as answering correctly

Retrieval-Augmented Generation enables language models to answer questions using information from external documents.

However, the quality of the final answer depends on several interconnected decisions: how documents are segmented, which retrieval method is used, how much context is supplied, and which language model generates the response.

A system may retrieve passages that appear relevant but fail to contain the information required to answer a question. Similarly, an LLM may produce an answer that resembles the expected response without providing reliable evidence from the retrieved documents.

This project investigates these trade-offs through controlled experiments across retrieval and generation configurations.
Context

A reproducible document-grounded evaluation

The benchmark uses two NIST AI governance documents as its knowledge corpus, processed into structured text with source metadata and token-aware chunks of 256 and 512 tokens.

A curated evaluation dataset contains 100 synthetic questions covering lexical, semantic, factual, definition, reasoning, and multi-chunk information needs.

Each question is associated with manually reviewed relevant passages, allowing retrieval configurations to be compared against explicit relevance judgments. A subset of 50 questions is used for generation experiments.

100 Retrieval Queries · 4 Retrieval Configurations · 4 Generation Configurations
02 / APPROACH

Evaluating Retrieval and Generation Independently

Decoupling search quality from synthesis fidelity to diagnose where failures actually originate.

Stage 01 · Retrieval Evaluation

Sparse vs. Dense Passage Search

BM25 lexical matching compared against dense retrieval using BGE-small embeddings stored in Qdrant, tested across 256-token and 512-token chunks over the full 100-query benchmark.

MethodsBM25 (Lexical) vs. BGE-small in Qdrant (Dense)
Granularity256 tokens vs. 512 tokens
MetricsPrecision@5, Recall@5, Mean Reciprocal Rank (MRR), Latency
Stage 02 · Generation Evaluation

Local Model Grounding & Context Size

The strongest retrieval configuration (Dense 512) supplies context to local Granite language models through Ollama, evaluating answer correctness, citation validity, and inference cost.

ModelsIBM Granite 3B & Granite 8B (via Ollama CPU)
Context SizeTop 3 Chunks vs. Top 5 Chunks
MetricsAnswer Correctness, Citation Grounding, Response Latency
03 / SYSTEM ARCHITECTURE

From PDF Documents to Evaluated Answers

Full end-to-end benchmarking pipeline illustrating document ingestion, decoupled retrieval testing, and model generation evaluation.

DOCUMENT INGESTION & PREPARATION
NIST AI GovernanceKnowledge corpus PDFs
Text ExtractionStructured text + metadata
Token-Aware Chunking256 / 512 tokens
PHASE 01 · RETRIEVAL BENCHMARK100 Queries
BM25 Lexical Index256 & 512 chunks
BGE-small in Qdrant256 & 512 chunks
Relevance Judgment ScoringPrec@5 · Recall@5 · MRR
PHASE 02 · GENERATION BENCHMARK50 Queries
Granite 3B (Top 3 / Top 5)Ollama CPU · Prompt Context
Granite 8B (Top 3 / Top 5)Ollama CPU · Prompt Context
Response EvaluationCorrectness · Grounding · Latency
Pipeline Transition: The evaluated generation branch strictly uses the top-performing Dense 512 configuration to feed context, rather than having all 4 retrieval configurations feed every generation experiment.
04 / RETRIEVAL RESULTS

How Much Does Retrieval Strategy Matter?

Four retrieval configurations evaluated using the exact 100-query benchmark dataset.

Recall@5 Comparison (Primary Coverage Metric)100 Test Queries
Dense 512
66.15%
Dense 256
58.15%
BM25 512
57.23%
BM25 256
50.87%
MethodChunk SizePrecision@5Recall@5MRRMean Retrieval Latency
BM25256 tokens20.80%50.87%0.54071.18 ms
BM25512 tokens21.40%57.23%0.55980.73 ms
Dense (BGE-small)256 tokens25.00%58.15%0.612583.11 ms
Dense (BGE-small)Top Config512 tokens26.00%66.15%0.716574.79 ms
Key Finding: Dense retrieval with 512-token chunks achieved the highest retrieval effectiveness, improving Recall@5 by approximately 8.9 percentage points compared with BM25 using the same chunk size, at a substantially higher measured retrieval latency (74.8 ms vs. 0.73 ms).
05 / GENERATION RESULTS

Does a Larger Language Model Produce Better Grounded Answers?

Evaluating answer correctness vs. source citation grounding across 4 model configurations (50 questions each).

01 · FASTER RESPONSES

Granite 3B Top 3

Achieved the shortest mean response time (19.87s) and highest measured answer correctness (68%), making it agile for rapid prototyping.

02 · BETTER GROUNDING

Granite 8B Top 3

Achieved a 64% citation-based grounding rate (vs. only 4% for Granite 3B), demonstrating far superior instruction adherence to source attribution.

03 · CONTEXT TRADE-OFF

More Context ≠ Better

Increasing context from 3 to 5 chunks lengthened latency significantly (up to 78.57s) without improving measured answer correctness.

Answer Correctness vs. Citation Grounding
Answer Correctness
Citation Grounding
Granite 3BTop 3 Chunks
68%
4%
Granite 3BTop 5 Chunks
64%
6%
Granite 8BTop 3 Chunks
62%
64%
Granite 8BTop 5 Chunks
60%
60%
ModelContext ChunksAnswer Correctness*Citation GroundingMean Response Time
Granite 3BTop 368%4%19.87 s
Granite 3BTop 564%6%28.40 s
Granite 8BBest GroundingTop 362%64%50.06 s
Granite 8BTop 560%60%78.57 s
Methodological Caveat on Grounding: The low grounding score (4%) for Granite 3B does not prove that 96% of its answers were factually unsupported. Inspection of the outputs revealed that some source references failed to follow the rigid citation syntax expected by the automated evaluator. This illustrates the critical gap between semantic correctness and automated verification rigor.
06 / FAILURE ANALYSIS

Query-Level Failure Inspection

Why aggregate metrics are insufficient: a real case study comparing BM25 vs. Dense retrieval on the same question.

Benchmark Query

“What specific risk management measures are prescribed for autonomous decision-making systems under high-impact conditions?”

BM25 RetrievalMissed Evidence
“...decision-making protocols in administrative frameworks should assess risk management objectives broadly across departmental organizational tiers...”

Lexical Mismatch & Distractor: Matches the isolated terms “decision-making” and “risk management”, but fails to capture high-impact regulatory prescriptions.

Dense Retrieval (BGE-small)Evidence Found
“...autonomous systems categorized under high-impact tiers require continuous monitoring, fail-safe override mechanisms, and multi-party sign-off...”

Semantic Understanding: Captures the conceptual relationship between “autonomous”, “high-impact”, and prescribed oversight controls despite varied vocabulary.

Failure Diagnosis: In this instance, the failure occurred at the retrieval passage ranking stage rather than prompt assembly or LLM inference. Lexical BM25 lacked the semantic depth to associate governance tiers with specific impact definitions, highlighting the necessity of query-level inspections over aggregate scores.
07 / LIMITATIONS & CHALLENGES

Technical Challenges & Experimental Limitations

Documenting the engineering hurdles and clear boundaries of the benchmark.

Limitation 01

Evaluation Scope

Tested on 100 synthetic queries over two NIST AI governance documents. While controlled and reproducible, it does not claim universal generalization across all document formats, languages, or enterprise workloads.

Limitation 02

Grounding Measurement

Grounding checks citation presence and labeled passage mapping. It does not establish exhaustive per-sentence human fact-checking of every individual claim in the generated text.

Limitation 03

Document Processing

The pipeline ingests text-based PDFs. Optical Character Recognition (OCR) and multimodal inputs (tables, figures) are not included in the v1.0.0 benchmark scope.

CHALLENGE 01

Failures Beyond Aggregate Scores

High aggregate MRR and Recall can hide severe query-level hallucinations or missed evidence. Per-query failure diagnosis is mandatory to discover distractor chunks and lexical gaps.

CHALLENGE 02

Measuring Grounding Rigorously

Separating answer similarity from actual source grounding. Smaller models frequently hallucinate facts that match expected answers without relying on the provided context passages.

CHALLENGE 03

CPU Inference Latency Trade-Offs

Running local inference under CPU constraints revealed acute response-time penalties: 8B models took ~50–78s per query, defining real-world viability boundaries for local deployments.

08 / KEY LEARNINGS

Takeaways for Production RAG Engineering

Four core insights gained from running decoupled RAG evaluations.

Evaluate every stage independently: Retrieval quality does not automatically translate into trustworthy generated answers. Decoupling search testing from generation is the only way to diagnose errors accurately.

More context is not always better: Expanding context from 3 to 5 chunks lengthened latency by 43%–57% without yielding any measurable increase in answer correctness.

Attribution demands model scale: Granite 8B achieved 16× higher citation-based grounding compliance than Granite 3B, proving that smaller models struggle with strict source attribution formatting.

Inspect failures, don't just average metrics: Aggregate Precision and Recall averages routinely mask semantic drift and distractor passages that cause downstream answer hallucinations.

09 / REPOSITORY & TECHNICAL ARTICLE

Source Code & Technical Write-up

Reproduce the benchmark experiments or read the comprehensive technical article.

RAG Benchmark v1.0.0

The public repository includes document preprocessing, sparse and dense retrieval scripts, per-query benchmark results, failure analysis logs, and local answer generation configs.

Technologies & Frameworks
PythonQdrantBM25Sentence TransformersBGE-smallOllamaGranite 3B/8BDockerScikit-learn