Skip to main content

Performance and Metrics

Performance in a RAG system is multi-dimensional (@lewis2020rag, @gao2024ragsurvey). Latency, cost, and quality form a three-way trade-off where optimizing one often degrades another. The ZOL Intelligent Search navigates this trade-off through careful model selection, caching, and the hybrid evaluation strategy. Tail-latency measurement and SLO framing follow @beyer2016sre; the underlying response-time UX targets follow @nielsen1993responsetimes (0.1 s for instantaneous feedback, 1 s for seamless flow, 10 s as the upper attention bound).

Source-of-truth for measured numbers

The waterfall below describes the design-time stage budget from the ADR-0034 optimization sprint (February 2026). The end-to-end distribution measured across the 302-question golden set v3.6 in the 2026-03-21 run is median 7,829 ms, P90 12,182 ms, P99 20,925 ms (self-reported; thesis Chapter 4, Table 4.3). It has not been re-measured since, and no pilot-traffic latency distribution is claimed here. The ~5,500 ms total in the waterfall is consistent with the lower part of the measured distribution; the upper tail reflects long-form generation and follow-up-chain queries.

Response Time Breakdown​

The end-to-end query pipeline completes in approximately 5.5 seconds (P50). The following waterfall shows where time is spent:

Time Budget Allocation​

StageTime% of TotalOptimization
Cache check5ms< 0.1%PostgreSQL semantic cache (SHA-256 hash, Tier 1)
Intent classification + query rewriting400ms7%Tier 2 (combined in one LLM call)
Metadata filtering5ms< 0.1%In-memory lookup
Vector search600ms11%HNSW index
BM25 search600ms(parallel)PostgreSQL tsvector
Taxonomy search600ms(parallel)SQL query optimization
Metadata boosting5ms< 0.1%In-memory computation
Context assembly50ms1%Expand ±1, dedup, budget
Response generation3,500ms64%Tier 2 / Tier 3 full mode
Fast quality gate600ms11%Embedding similarity
Streaming overhead85ms1%WebSocket
Total~5,500ms100%
Key Insight

Response generation dominates the pipeline at 64% of total time. This is by design -- the generation model (Tier 2 / Tier 3 in full mode) is the highest-quality model in the stack, and the streaming interface masks perceived latency. Users see the response appearing word-by-word after ~4.5 seconds, rather than waiting the full 5.5 seconds for a complete response. Intent classification and query rewriting are combined into a single LLM call (~400ms), saving ~300ms compared to separate calls.

LLM Cost Optimization​

The multi-model strategy minimizes cost by using the right model for each task:

TaskModelCost per 1M tokensMonthly VolumeMonthly Cost
Intent classification + query rewritingTier 2~$0.40/1M in~25K queries~$0.50
Response generation (standard)Tier 2~$0.40/1M in~15K queries~$3.00
Response generation (full mode)Tier 3~$2.00/1M in~15K queries~$7.50
Background evaluationTier 2~$0.40/1M in~15K queries~$0.30
EmbeddingsOpenAI text-embedding-3-large (1536d, hosted, ADR-0048)$0.13 / 1M tokensAll queries (~50 tokens/query × 25 K/mo ≈ 1.25 M tokens/yr)≈$0.16/year
Entity extractionRegex$0 (local)All documents$0
Graph entity validation + page summariesTier 2~$0.40/1M in~2,000 pages/run~$1-2/run*
Total~$8.70/month (projection)

*Graph validation is an ingestion-time cost, not per-query. It runs once per full corpus extraction (~2,000 pages), producing validated entities for the taxonomy and page summaries for contextual retrieval. A cross-page entity cache reduces LLM calls by 10-25%. See ADR-0014.

Caching Impact

The ~$8.70 figure is a projection, not a measured bill. It assumes the ~25,000 queries per month stated in the January 2026 project brief and a 40% cache hit rate (an assumption), which avoids all LLM calls for repeated queries. Without caching, costs would be approximately $14/month. The PostgreSQL-based semantic query cache (ADR-0031, 1-hour TTL) provides a significant return on its minimal infrastructure cost through two-tier lookup (SHA-256 hash + embedding similarity).

The Hybrid Evaluation Breakthrough​

The most significant performance decision was the shift from full inline evaluation to hybrid evaluation (fast gate + background analytics):

On the design-time figures above, this architectural change reduced perceived latency by roughly 88-91% while maintaining quality assurance through the fast embedding-similarity gate and providing comprehensive analytics via the asynchronous background evaluation.

Monitoring Metrics​

The system exports operational metrics to a Prometheus-based monitoring stack. They fall into three groups:

  • Request metrics: query counts by intent type, end-to-end latency histograms (P50, P95, P99), cache hit ratio, and the number of retrieval results per query.
  • Quality metrics: fast quality-gate scores and pass ratio, user thumbs-up ratio, and background judge scores for faithfulness and relevancy. The background judge scores are not valid after mid-May 2026, when the judge silently stopped running, and should not be read as current evidence.
  • Safety metrics: counts of intent-based safety blocks and post-generation safety blocks, and a counter of medical-advice incidents. The target for that counter is zero; it is a monitoring target, not a statement that none has occurred. The counter can only record what the system itself detects, and the June 2026 dose incident was discovered by a person, not by this counter (see the Safety overview).

Caching Strategy​

The semantic query cache operates in PostgreSQL via pgvector (ADR-0031), providing a two-tier lookup system that operates on LLM-reformulated queries for maximum hit rates across languages:

Cache LevelMechanismLatencyHit rate (planning assumption, not measured)
Tier 1: Exact hashSHA-256 of reformulated query~1ms~30%
Tier 2: Semantic similaritypgvector HNSW cosine similarity >= 0.97~30ms~10-15% additional
Session context (Redis)In-memory conversation history< 1msPer-user

The semantic cache was migrated from Redis to PostgreSQL (ADR-0031) because Tier 2 approximate nearest neighbor search requires pgvector's HNSW index. Redis continues to serve ephemeral state (sessions, rate limits, token blacklist). See Storage Architecture for schema details.

Performance Targets​

MetricTargetCurrent figureSource and status
P50 latencyunder 10 s (@nielsen1993responsetimes)7.8 sGolden-set run of 2026-03-21, self-reported (thesis Chapter 4, Table 4.3)
P90 latencyunder 15 s12.2 sSame run, self-reported
P99 latencynot yet targeted20.9 sSame run; no service-level objective yet
Cache hit rateover 30%~40% assumedPlanning assumption; not a measured pilot figure
Golden-set pass rate (302 questions, v3.6)95% or above99.0% (296/299)Run of 2026-03-21, self-reported; measures entity recall and must-refuse behaviour only
Monthly LLM costunder $20~$8.70Projection from the January 2026 brief's query volume, not a measured bill

Benchmarking Methodology​

Performance measurements follow standard practices for latency benchmarking:

  • Measurement point: End-to-end from WebSocket message receipt to final streaming chunk delivery
  • Statistical reporting: P50 (median), P95, and P99 latencies to capture tail behavior
  • Warm cache exclusion: Cache hit responses are excluded from latency measurements to reflect true pipeline performance
  • Repeat measurements: Each benchmark reports the mean of 10 consecutive queries with the same input to account for LLM response variability
  • Environment: Measurements were taken on a development environment, not on pilot traffic