---
title: Search ranking for financial news and documents (with typeahead)
url: https://gurkanozkan.ai/learn/design/mle-search-ranking-for-financial-news-and-documents-with-typeahead-07/
markdown: https://gurkanozkan.ai/learn/design/mle-search-ranking-for-financial-news-and-documents-with-typeahead-07.md
kind: design
role: ML engineering
json: https://gurkanozkan.ai/api/learn/design/mle-search-ranking-for-financial-news-and-documents-with-typeahead-07.json
---

# Search ranking for financial news and documents (with typeahead)

Build search over news stories and company filings for professional users, including autocomplete; freshness matters within seconds of a story breaking.

## Constraints

- 1B documents, 1M new per day
- 2k QPS
- p99 300 ms
- queries mix tickers, entities and natural language

## What to cover

- **Requirements**: Build search over news stories and company filings for professional users, including autocomplete; freshness matters within seconds of a story breaking.
- **Estimates**: 1B documents, 1M new per day; 2k QPS; p99 300 ms; queries mix tickers, entities and natural language.
- **API**
- **Data model**
- **Architecture**: Query understanding (entity and ticker recognition, spelling).; Hybrid retrieval (BM25 inverted index + dense embeddings with ANN).; Learning-to-rank (LambdaMART or a cross-encoder for the top 100) with recency and authority features.; Real-time indexing pipeline; typeahead with a trie or prefix index ranked by popularity and personalisation.; Click logging with position-bias handling; relevance judgements by experts.
- **Deep dives**
- **Trade-offs**: freshness vs relevance; dense vs sparse retrieval cost; cross-encoder latency; personalisation vs auditability for professional users.
- **Evaluation**: Offline: NDCG@10 on expert-judged sets, recall@100 of retrieval, freshness lag.; Online: interleaving, time to first useful click, query reformulation rate, zero-result rate.

## Reference design

### Requirements

**Functional**: search across news stories and company filings with filters (date, source, document type, ticker, region) and sort by relevance or time; typeahead that suggests tickers, companies, people, topics and past queries; new stories searchable within seconds of publication; highlighted snippets.

**Users**: professionals (traders, analysts, journalists) who know what they want, value precision and recency, and need predictable, auditable results.

**Non-functional**: search p99 ≤ 300 ms at ~2k QPS; typeahead p99 ≤ 50 ms per keystroke; indexing lag p99 of a few seconds for breaking news; entitlements per source (licensed newswires).

**Query mix**: tickers and symbols ("VOD LN", "$AAPL"), entities ("Bank of England"), and natural language ("why did gilt yields jump today").

**Assumptions to confirm**: ~1B documents with ~1M new per day; English first; filings up to hundreds of pages; a small team of expert judges is available for relevance labels.


### Estimates

- **Corpus**: 1B documents; news averages ~600 words, filings are split into passages. Raw text ≈ 1B × ~5 KB ≈ 5 TB; inverted index ≈ 2 TB, sharded (~100 shards × 3 replicas).
- **Dense vectors**: 1B vectors (one per story or filing passage) × 768 dims × 1 byte (int8) ≈ 770 GB, or ~64 GB with product quantisation to 64 bytes — PQ plus re-scoring of the shortlist keeps ANN in memory.
- **Ingest**: 1M docs/day ≈ 12/s average, bursts of hundreds per second at market open and earnings; embedding a story takes ~10–20 ms on a GPU, so a few GPUs keep up with seconds of lag.
- **Query load**: 2k QPS search; typeahead ≈ 5 keystrokes per query → **~10k QPS** suggestions.
- **Reranking**: assuming ~2k–5k query–document pairs/s per GPU, a cross-encoder on the top 100 at 2k QPS = 200k pairs/s ≈ 40–100 GPUs; on the top 20 after LambdaMART = 40k pairs/s ≈ 8–20 GPUs. That cost difference shapes the cascade.
- **Latency budget (p99 300 ms)**: query understanding 20 ms, sparse and dense retrieval in parallel 60 ms, merge and feature extraction 30 ms, LambdaMART on ~200 20 ms, cross-encoder on top 20 60 ms, snippets and entitlement checks 30 ms, overhead and tail headroom ~80 ms.


### API

```
GET /v1/search?q=…&filters=type:news,source:…,from:…&tickers=…&sort=relevance|time&page=1
  → {request_id, query_interpretation: {entities: [{text, entity_id, ticker}], intent},
     results: [{doc_id, title, snippet_html, source, doc_type, published_at, tickers[],
                entitled: true}], total_estimate}

GET /v1/suggest?prefix=vodaf&session_id=…      (p99 ≤ 50 ms)
  → [{text: "Vodafone Group PLC", type: "company", entity_id, ticker: "VOD LN"},
     {text: "vodafone three merger", type: "query"}]

POST /v1/search/events  {request_id, events: [{type: "impression"|"click"|"dwell"|"reformulate",
                         doc_id, position, ts}]}
```
Entitlement filtering happens in the index query, so unlicensed sources never appear even as counts. `sort=time` is deterministic, which professional users rely on. Both endpoints return a `request_id` so clicks join to the exact ranking for training and interleaving analysis.


### Data model

- **Document**: doc_id, type (news | filing | transcript), source, published_at, updated_at, version chain (wire stories are updated repeatedly), language, title, body, passages, entities and tickers (linked to the entity master), authority score, entitlement tags.
- **EntityMaster**: entity_id, names and aliases, tickers per exchange, ISIN, sector, relationships (subsidiaries); drives query understanding and typeahead.
- **Indices**: hot tier (last ~7 days, near-real-time refresh) and cold tier (history, rebuilt in batches); BM25 fields with boosts; ANN index on passage embeddings.
- **QueryLog / ClickLog**: request_id, user, query, interpretation, results with positions, clicks, dwell, reformulations.
- **Judgements**: (query, doc, grade 0–4, judge, guideline version) from expert assessors.
- **SuggestionStore**: prefix → ranked suggestions from entities, popular queries (recency-weighted) and the user's history; trending boosts.


### Architecture

```
Wires / filings feeds ─► Kafka ─► Enrichment: dedup and version chains, entity
   linking (tickers, companies), language, embeddings ─► Hot index (NRT, ~1 s
   refresh) ─► nightly merge ─► Cold index
Query ─► Query understanding: ticker/entity recognition against EntityMaster,
   spelling correction, intent (navigational vs news vs research), filters
   ─► Retrieval in parallel: BM25 (hot + cold) and dense ANN ─► merge (~200)
   ─► LambdaMART with text, entity-match, recency, authority, source and
      click features ─► top 20 ─► cross-encoder rerank ─► snippets ─► results
Typeahead: in-memory prefix index (FST/trie) per region, entries from
   EntityMaster + popular queries + user history, ranked by popularity,
   recency and personalisation; trending terms injected within minutes
Logs ─► click models (position-bias correction) ─► training data
Expert judging tool ─► judged sets ─► offline evaluation and training
```


### Deep dives

**Freshness within seconds.** Two-tier index: new documents go to a small hot index with a one-second refresh; embeddings are computed in the streaming pipeline before indexing; a story is searchable within a few seconds of arriving. Ranking learns query-dependent recency: for "VOD" or "gilt yields" the newest relevant story usually wins; for "IFRS 17 transition" relevance dominates. A freshness-intent feature (share of recent clicks for this query in the last hour) lets the ranker switch.

**Position bias in clicks.** Users click what is on top, so raw clicks reward the incumbent ranker. Estimate propensities with small randomised swaps of adjacent results, train with inverse-propensity weighting, and use interleaving for online comparisons. Expert judgements remain the ground truth for offline gates.

**Typeahead.** Within 50 ms there is no time for heavy models: precompute candidates per prefix, rank with a light model on popularity, recency and the user's watchlist, and prefer entities (jumping straight to a company page) for short prefixes.


### Trade-offs

- **Freshness vs relevance**: always boosting recency buries the authoritative analysis; ignoring it shows stale news on a breaking story. Learn the trade-off per query and offer an explicit time sort.
- **Dense vs sparse retrieval cost**: BM25 is cheap, exact on tickers and names, and easy to explain; dense retrieval helps natural-language questions but costs memory and GPU time. Hybrid retrieval with dense only on passages and the hot tier, or only when query understanding detects natural language, controls cost.
- **Cross-encoder latency**: best precision, but 200k pairs/s is expensive; restrict it to the top 20 after LambdaMART, and skip it for navigational ticker queries.
- **Personalisation vs auditability for professional users**: people want to reproduce a search and trust that colleagues see the same results; keep core ranking non-personalised, personalise typeahead and soft boosts (watchlist tickers) visibly, and log everything for audit.


### Evaluation

- **Offline**: NDCG@10 on expert-judged query sets stratified by query type (ticker, entity, natural language) and recency need; recall@100 of the retrieval stage (judged or pooled); freshness lag (publish time to searchable) p50/p99; typeahead mean reciprocal rank and keystrokes saved.
- **Online**: team-draft interleaving for ranking changes (sensitive with less traffic than A/B); time to first useful click (click followed by long dwell); query reformulation rate; zero-result rate; abandonment.
- **Monitoring**: indexing lag per source, query latency p99 per stage, entitlement-filter errors (must be zero), click-through by position, spikes in zero-result queries (often a new entity missing from EntityMaster).


## What a strong design shows

- Has query understanding that recognises tickers and entities, not just text matching.
- Uses hybrid retrieval and a cost-aware ranking cascade (LambdaMART, then a cross-encoder on a short list).
- Achieves seconds-level freshness with a hot/cold index and learns query-dependent recency.
- Corrects click logs for position bias and relies on expert judgements and interleaving for evaluation.
- Treats typeahead as its own low-latency system and respects professional users' need for predictable, auditable results.

---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
