RobinSinghAI Engineer · Interface
Case study CS-002 · Omni Docs

Cutting doc-search latency by with a two-stage retriever.

Latency reduction
61%
Cache hit rate
340ms
p50 response
−38%
Inference cost
01

Problem

Developers searching API documentation were getting semantically plausible but factually wrong answers, and waiting two seconds for them. Pure vector retrieval missed exact identifiers — endpoint names, error codes, parameter keys — which is precisely what developers search for.

02

Constraints

One engineer, a fixed monthly inference budget, and a corpus that changes on every upstream release. Any solution had to reindex incrementally and degrade to something useful rather than failing closed.

03

Architecture

A two-stage retriever: lexical BM25 and dense KNN run in parallel, fuse with reciprocal rank fusion, then a cross-encoder reranks the top 24 down to 6. The generation step only ever sees six passages, which caps token cost independent of corpus size.

04

Decisions

Reranking was the expensive call, so it sits behind a semantic cache keyed on normalized query embeddings. The cache absorbs 61% of traffic. Reindexing is diff-based against upstream release tags rather than a nightly full rebuild.

05

Results

p50 dropped from 1.4s to 340ms and inference cost fell 38% despite the extra reranking stage. Exact-identifier recall went from 0.52 to 0.91 on a hand-labelled evaluation set of 400 developer queries.

# two-stage retrieve
cands = bm25.search(q, k=120)
vecs = index.knn(embed(q), k=120)
merged = rrf(cands, vecs)[:24]
final = cross_encoder.rank(q, merged)[:6]