Skip to main content

Pipeline Latency

This page documents the end-to-end latency characteristics of the ZOL RAG pipeline (@lewis2020rag), the optimizations applied (ADR-0034), and the configuration choices that affect latency. Latency targets are framed against Nielsen's response-time thresholds (0.1 s, 1 s, 10 s) and reported at the tail per @beyer2016sre SRE practice.

Measured baseline (self-reported, run of 2026-03-21)

Method: the project's own evaluation run of 302 golden questions (version 3.6 of the question set) against the pilot system, timing each end-to-end response. Result: median 7,829 ms, P90 12,182 ms, P99 20,925 ms (distribution in thesis Chapter 4). This is a single run on the project's own question set, not an independent benchmark, and the pipeline has changed since. The stage descriptions below are qualitative; they were not re-measured after later changes (see "Re-measurement open items").

Pipeline Stage Breakdown​

Sequential vs Parallel Stages​

StageBlocking?Notes
Intent classificationYesMust complete before retrieval
User preference lookupNoRuns in parallel with intent classification
Vector + keyword searchYesSearches run in parallel internally
Taxonomy searchNoParallel with vector search
Cross-encoder rerankingYesAfter retrieval
Context assemblyYesAfter reranking; negligible cost
LLM responseYesThe dominant cost; the answer is streamed so the user sees text early
Safety validationYesRule-based, very fast
Follow-up suggestionsNoAfter the final chunk (asynchronous)
Background evaluationNoFire-and-forget task

The ADR-0034 optimisation sprint (February 2026) shortened the sequential path substantially by slimming the intent prompt, parallelising searches and streaming the answer. The per-stage timings recorded then were approximations and are not reproduced here.

LLM Call Chain​

The pipeline makes up to 4 LLM calls per query:

#CallProviderModel
1Intent classificationOpenAIgpt-4.1-mini
2Main responseOpenAIgpt-4.1
3Follow-up suggestionsOpenAIgpt-4.1-nano
4Background evaluationOpenAIgpt-4.1-mini

Only calls #1 and #2 are on the critical path. Call #3 runs after the user already sees the response. Call #4 is fire-and-forget.

All LLM calls use the OpenAI API directly (no intermediary). An intermediary gateway was removed on 2026-03-20 after DNS reliability problems caused 28 evaluation failures in a single run.

Configuration choices​

  • Provider routing. All LLM calls go to a single provider directly; model choice per call is configurable.
  • Streaming. Tokens stream to the client as they arrive (the default since ADR-0034). Post-generation safety validation runs after streaming completes; if a violation is detected, a retraction message replaces the streamed content.
  • Fallback chain. An ordered list of providers/models is tried in sequence, with a circuit breaker that skips a repeatedly failing provider for a short recovery period.
  • Rate-limit protection. Rate-limit errors are retried with exponential backoff; after three retries the fallback chain takes over.

Monitoring​

Per-stage timings are written to the query audit log (for example main LLM time and intent-classification time). Fallback events and rate-limit retries are logged as warnings.

Re-measurement open items​

The stage descriptions above date from the ADR-0034 optimisation sprint (February 2026). Two pipeline changes have landed since which a future re-measurement should reflect:

  1. Structured-output helper. Several call sites, including intent classification and query decomposition, use a shared helper for schema-validated output with retries. A different structured-output approach was trialled in May 2026 and removed within days after telemetry showed it added noticeable latency per call; the helper restored first-attempt latency to baseline. Rare retries on malformed output add some delay that has not been measured at population scale.
  2. Value Framework rerank and synthetic doctor-list injection. Both are small in-memory or single-query steps and only the latter is conditional (it fires only for doctor-list questions).

Neither item is expected to move the headline median materially, but a clean re-measurement at P95/P99 would close the loop.