use case · multi-model · nomic-embed-text-v1.5 (137.30 MB) → ms-marco-MiniLM-L-6-v2 (23.9 MB) · ~161 MB total · WASM q8

2-stage Matryoshka funnel retrieval

Production search engines don't score every document with their best model. Here Stage 1 (nomic-ai/nomic-embed-text-v1.5) scans the whole corpus with cheap 64-d vectors, re-scores a shortlist at full 768-d, and Stage 2 (Xenova/ms-marco-MiniLM-L-6-v2) reads each finalist together with the query as a cross-encoder.

1 · Two independent local models

Stage 1 · Nomic Embed Text v1.5 (137.30 MB q8)

Bi-encoder: 64-d Matryoshka filter + 768-d re-score (./worker.js).

Stage 2 · ms-marco-MiniLM-L-6-v2 (23.9 MB q8)

Cross-encoder: raw relevance logit per (query, passage) (./reranker-worker.js).

2 · Query, corpus & funnel shape

8
5

Prepare the models above.

3 · The funnel & rank shifts

Stage 1 latency–
Stage 2 latency–
Multiply-adds vs brute 768-d–
Filter recall vs 768-d–
Final #1–
NaN (S1 / S2)–
Per-passage ranks and scores at every funnel tier
Passage Filter rank (cos) 768-d rank (cos) Cross-encoder rank (logit) Shift 768→CE
Run the funnel to fill this table.

How the funnel works

Matryoshka training means the first 64 coordinates already rank well, so the filter costs N×64 multiply-adds instead of N×768. Only the shortlist is re-scored at 768-d, and only the finalists pay for a cross-encoder forward pass that attends across query and passage tokens jointly.

Show the code — nomic-core.mjs funnelRetrieve(): 64-d filter → 768-d re-score
Show the code — reranker-worker.js rerank(): raw cross-encoder logits