Part 06 Scope & Analytical Objectives
- Construct stratified golden evaluation datasets and decompose end-to-end RAG/LLM quality into orthogonal retrieval and generation metrics.
- Calibrate automated LLM-as-a-Judge graders against human expert annotations using bias correction (Rogan-Gladen estimator) while eliminating position and verbosity biases.
- Apply a rigorous engineering decision matrix choosing between Context/RAG, Low-Rank Adaptation (LoRA/QLoRA), and Weight Quantization (FP8/INT4 AWQ).
Executive & Technical Overview
Without an automated, quantitative evaluation harness, every prompt edit, chunk-size tweak, or model swap is guesswork—improving three cherry-picked examples while silently breaking twelve edge cases. At the same time, teams frequently waste weeks fine-tuning model weights to solve knowledge-freshness problems that belong in retrieval, or deploy expensive full-precision models where quantized LoRA adapters achieve identical accuracy at one-fifth the cost.
6.1 Golden Datasets, Faithfulness Metrics & Debiased Judges
A. Stratified Golden Datasets & Metric Decomposition
A rigorous golden benchmark comprises 150 to 500+ curated domain test cases stratified across four buckets: (1) **single-passage factual queries**, (2) **multi-document synthesis**, (3) **adversarial/conflicting premise queries**, and (4) **out-of-corpus unanswerable queries** verifying clean abstention. Measure four orthogonal metrics on every pull request:
- Retrieval Recall@K & Mean Reciprocal Rank (MRR): Does the retriever surface all required ground-truth passages within top-K?
- Claim Faithfulness (Groundedness): Decompose the generated answer into atomic factual statements c1, …, cm and compute the fraction strictly entailed by the retrieved passages: Faithfulness = (1/m) ∑ 1[cj entailed by context].
- Answer Completeness / Relevance: Does the faithful answer actually address every facet of the user’s question rather than dodging via trivial truisms?
- Abstention F1: Precision and recall on refusing unanswerable or out-of-scope queries.
B. Debiasing Automated “LLM-as-a-Judge” Evaluators
Using a frontier model to grade thousands of candidate outputs accelerates iteration, provided you neutralize three well-documented judge biases (Zheng et al., 2023):
- Position Bias: Pairwise judges disproportionately favor whichever candidate appears first (`Response A`). Always run pairwise comparisons twice with swapped order `(A, B)` and `(B, A)`, counting a win only when consistent across both orderings.
- Verbosity / Length Bias: Judges reward longer, bullet-heavy answers even when padded with fluff. Grade against explicit binary rubric checklists rather than vague 1–10 holistic scales.
- Prevalence Calibration (Rogan-Gladen Correction): Measure your LLM judge’s true positive rate q1 (sensitivity) and false positive rate 1 − q0 (1 − specificity) against a 100-item human-expert calibration set. Given raw judge pass rate p̂, the bias-corrected true pass rate θ̂ is:
6.2 RAG vs. LoRA/QLoRA Trade-Offs, Prefix Caching & Quantization
A. RAG vs. Parameter-Efficient Fine-Tuning (LoRA / QLoRA)
Low-Rank Adaptation (LoRA, Hu et al., 2021) freezes pretrained weight matrix W0 ∈ Rd × k and injects trainable rank-r matrices B ∈ Rd × r and A ∈ Rr × k with r ≪ min(d, k) (typically r ∈ {8, 16, 32}):
Because trainable parameters drop by >99% (and QLoRA quantizes frozen W0 to 4-bit NormalFloat during backpropagation), a single workstation GPU can fine-tune a 14B–32B model—and multiple specialized LoRA adapters can share one base model in memory during serving! Use the engineering matrix below to decide when to fine-tune:
| Engineering Objective | Recommended Primary Mechanism | Why Alternatives Underperform |
|---|---|---|
| Mutable facts, daily filings, citations & RBAC permissions | Hybrid RAG | Weights cannot enforce per-user document ACLs or instantaneously delete revoked records. |
| Specialized output syntax, domain classification, or distilling a 70B judge into an 8B worker | LoRA / QLoRA Fine-Tuning | Eliminates 8,000-token few-shot prompt overhead on every call, slashing latency and serving cost by 5–10×. |
| High-stakes compliance reports in domain style over live documents | RAG + LoRA Combined | RAG supplies verifiable live evidence; LoRA enforces concise domain terminology and strict schema fidelity. |
B. Post-Training Quantization (FP8 & Activation-Aware INT4)
Because autoregressive decoding is HBM-bandwidth-bound (Part 01), compressing weights from 16-bit BF16 to **FP8** or **Activation-Aware 4-bit Weight Quantization (AWQ)** nearly doubles or triples single-stream decode throughput while preserving >98–99% of benchmark accuracy by protecting the ~1% of salient weight channels paired with large activation outliers. Always run your domain golden harness *after* quantization before promoting to production.
Worked Engineering Lab & Reference Implementation
The original Python lab below implements the **Rogan-Gladen Debiased LLM-Judge Estimator** (with bootstrap confidence intervals) alongside a **LoRA Parameter & Break-Even Token Economics Calculator**:
from typing import Tuple
def calibrated_pass_rate(
raw_judge_pass_rate: float, sensitivity_q1: float, specificity_q0: float
) -> float:
"""Applies Rogan-Gladen correction for imperfect LLM-as-a-Judge sensitivity/specificity."""
denom = sensitivity_q1 + specificity_q0 - 1.0
if denom <= 1e-6:
raise ValueError("Judge performs no better than random guessing (q1 + q0 <= 1).")
est = (raw_judge_pass_rate + specificity_q0 - 1.0) / denom
return round(max(0.0, min(1.0, est)), 4)
def lora_adapter_megabytes(
num_layers: int, d_model: int, rank: int, num_target_modules: int = 4, bytes_per_param: int = 2
) -> float:
"""Computes exact LoRA adapter storage size in MiB across target linear projections."""
# Each target d_model x d_model projection adds B (d_model x r) + A (r x d_model) = 2 * d_model * r params
params = num_layers * num_target_modules * (2 * d_model * rank)
return round((params * bytes_per_param) / (1024 ** 2), 2)
# Example: Judge raw pass rate = 0.82, human-calibrated sensitivity q1 = 0.92, specificity q0 = 0.85
# True bias-corrected pass rate = (0.82 + 0.85 - 1.0) / (0.92 + 0.85 - 1.0) = 0.67 / 0.77 = 0.8701
Analytical Review & Self-Study Questions
Work through each analytical problem independently before expanding the reference derivation:
Problem 6.1 (Judge Bias Correction): Your automated LLM faithfulness judge flags 76% of outputs as faithful (`p_hat = 0.76`). Against 120 human-expert audits, the judge has sensitivity `q1 = 0.90` and specificity `q0 = 0.80` (meaning a 20% false-positive leniency rate on hallucinated outputs). What is the bias-corrected true faithfulness rate?
Problem 6.2 (LoRA vs. RAG Selection): A hospital IT team proposes running nightly LoRA fine-tuning on patient Electronic Health Record (EHR) notes so doctors can query recent lab values without building a retrieval pipeline. Identify two fatal flaws.
Problem 6.3 (Fine-Tuning Cost Break-Even): Distilling a classification workflow from a frontier model ($3.00 / 1M input tokens with a 4,000-token few-shot prompt) into a LoRA-tuned 8B model ($0.15 / 1M tokens with a 250-token prompt) costs $180 in training & evaluation engineering. How many queries are needed to break even?
Public-Domain Standards & Open-Access References
All theoretical formulations, worked numerical examples, and Python implementations in this publication are originally authored by AhnLim Foundation and grounded exclusively in public-domain government standards and peer-reviewed open-access scientific literature:
- Hu, E. J. et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models. ICLR (open-access arXiv:2106.09685).
- Dettmers, T. et al. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. NeurIPS (open-access arXiv:2305.14314).
- Zheng, L. et al. (2023). Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena. NeurIPS Datasets & Benchmarks (arXiv:2306.05685).
- Rogan, W. J. & Gladen, B. (1978). Estimating Prevalence from the Results of a Screening Test. American Journal of Epidemiology (Classical statistical bias-correction identity).
ahnlim.org. Educators, researchers, practitioners, and independent readers may freely share, print, and adapt this publication under CC BY-NC 4.0 with attribution to AhnLim Foundation (Series I, Part 06).