|
| 1 | +# Retrieval Roadmap |
| 2 | + |
| 3 | +Ideas for improving retrieval quality, ranked by expected gain per effort, and |
| 4 | +the baseline they are measured against. Measure every change with |
| 5 | +`doc2vec eval` (see README, "Evaluating retrieval quality") before adopting it. |
| 6 | + |
| 7 | +## Baseline (2026-10-21) |
| 8 | + |
| 9 | +Eval set built from real support-assistant conversations: each case is either |
| 10 | +the user's first question or one of the assistant's own search queries, |
| 11 | +labelled with the docs pages the assistant cited in its answer (silver labels: |
| 12 | +a cited page is relevant, an uncited one is not necessarily irrelevant). The |
| 13 | +eval cases themselves are private and not part of the repository; only |
| 14 | +aggregate scores are reported here. |
| 15 | + |
| 16 | +Databases: `solo-enterprise-for-kgateway` 2.3.x docs (339 pages, 2,649 chunks) |
| 17 | +and `solo-enterprise-for-agentgateway` kubernetes/latest docs (391 pages, 3,113 |
| 18 | +chunks); `text-embedding-3-large`, 3072 dims, sqlite-vec, same query as the MCP |
| 19 | +server. Agentgateway labels cited under the old `/latest/` paths were mapped |
| 20 | +through their 301 redirects. |
| 21 | + |
| 22 | +| Docs | Case set | Cases | recall@1 | recall@4 | recall@10 | MRR | |
| 23 | +|---|---|---|---|---|---|---| |
| 24 | +| kgateway | User questions | 84 | 41.7% | 59.5% | 72.6% | 0.506 | |
| 25 | +| kgateway | Agent search queries | 443 | 45.8% | 69.3% | 79.9% | 0.567 | |
| 26 | +| agentgateway | User questions | 116 | 42.2% | 62.9% | 74.1% | 0.526 | |
| 27 | +| agentgateway | Agent search queries | 563 | 42.3% | 63.6% | 74.8% | 0.526 | |
| 28 | + |
| 29 | +Where the first relevant chunk lands (top-50 retrieval): |
| 30 | + |
| 31 | +| Docs | Case set | rank 1 | 2–4 | 5–10 | 11–50 | >50 | |
| 32 | +|---|---|---|---|---|---|---| |
| 33 | +| kgateway | User questions | 42% | 18% | 13% | 17% | 11% | |
| 34 | +| kgateway | Agent search queries | 46% | 23% | 11% | 13% | 7% | |
| 35 | +| agentgateway | User questions | 42% | 21% | 11% | 14% | 12% | |
| 36 | +| agentgateway | Agent search queries | 42% | 21% | 11% | 16% | 9% | |
| 37 | + |
| 38 | +About a quarter of cases have the right page in the top 50 but not the top 4, |
| 39 | +which is what a reranker recovers. The top 4 chunks also hold on average 1.2 |
| 40 | +chunks from a page already shown. |
| 41 | + |
| 42 | +## Comparison matrix (2026-10-21) |
| 43 | + |
| 44 | +Same 1,206 cases, scores averaged over the four case sets. Each embedding model |
| 45 | +re-embedded the same stored chunks (queries and documents marked as such where |
| 46 | +the model supports it). Hybrid = dense + SQLite FTS5 BM25 fused with RRF (k=60). |
| 47 | + |
| 48 | +Recall@4 by embedding model and search method: |
| 49 | + |
| 50 | +| Embedding | Vector | Vector, 1 chunk/page | Hybrid | Hybrid, 1 chunk/page | |
| 51 | +|---|---|---|---|---| |
| 52 | +| Nemotron-3.5-Embed-8B (DeepInfra) | 70.4 | **77.3** | 68.0 | 75.2 | |
| 53 | +| Gemini embedding-2 | 67.0 | 74.0 | 68.8 | 75.8 | |
| 54 | +| Qwen3-Embedding-8B (DeepInfra) | 66.5 | 70.2 | 66.9 | 74.3 | |
| 55 | +| Gemini embedding-001 | 68.2 | 74.1 | 67.3 | 73.8 | |
| 56 | +| Cohere embed-v4 (Bedrock) | 64.3 | 71.9 | 65.6 | 72.0 | |
| 57 | +| OpenAI text-embedding-3-large (today) | 63.8 | 68.2 | 64.8 | 70.8 | |
| 58 | +| OpenAI text-embedding-3-large @1024 | 64.0 | 69.5 | 64.2 | 70.4 | |
| 59 | +| Mistral embed | 60.8 | 65.3 | 64.2 | 69.8 | |
| 60 | +| OpenAI text-embedding-3-small | 55.8 | 63.8 | 61.9 | 67.9 | |
| 61 | + |
| 62 | +Keyword search alone (BM25): 53.0, or 57.6 with one chunk per page. |
| 63 | + |
| 64 | +Rerankers on the top 40 hybrid chunks, then one chunk per page: |
| 65 | + |
| 66 | +| Reranker | On text-embedding-3-large: @1 / @4 / MRR@10 | On Nemotron-3.5-Embed-8B: @1 / @4 / MRR@10 | Latency p50 / p95 (one at a time) | |
| 67 | +|---|---|---|---| |
| 68 | +| No reranker (hybrid, 1 chunk/page) | 42.5 / 70.8 / 0.560 | 42.5 / 75.2 / 0.575 | — | |
| 69 | +| **Nemotron-3.5-Rerank-8B** | **52.7 / 79.5 / 0.655** | **52.1 / 82.8 / 0.662** | 1.5 s / 2.8 s | |
| 70 | +| Nemotron rerank VL 1B (current chatbot) | 44.5 / 74.6 / 0.588 | 43.5 / 76.6 / 0.589 | 0.86 s / 2.1 s | |
| 71 | +| Qwen3-Reranker-4B | 44.5 / 76.0 / 0.588 | 44.0 / 76.4 / 0.593 | 2.3 s / 12.9 s | |
| 72 | +| Qwen3-Reranker-8B | 40.1 / 72.7 / 0.557 | 38.7 / 74.2 / 0.553 | 2.1 s / 4.9 s | |
| 73 | +| Cohere Rerank 3.5 (Bedrock) | 40.9 / 72.4 / 0.560 | 40.4 / 74.7 / 0.564 | 1.6 s / 2.2 s | |
| 74 | +| Claude Haiku, listwise (user questions only) | — | 41.6 / 75.7 / 0.570 | 2.0 s / 2.6 s | |
| 75 | + |
| 76 | +Today (text-embedding-3-large, vector search, no reranker): 43.0 / 63.8 / 0.532. |
| 77 | + |
| 78 | +On today's vector-only candidates (top 40 of text-embedding-3-large vector search), recall@1 / @4 / MRR@10: |
| 79 | + |
| 80 | +| Reranker | Chunks as reranked | Then 1 chunk/page | |
| 81 | +|---|---|---| |
| 82 | +| No reranker | 43.0 / 63.8 / 0.532 | 43.0 / 68.2 / 0.556 | |
| 83 | +| Nemotron rerank VL 1B (current chatbot) | 43.4 / 65.9 / 0.551 | 43.4 / 73.5 / 0.578 | |
| 84 | +| Nemotron-3.5-Rerank-8B | 52.5 / 73.8 / 0.624 | 52.5 / 78.5 / 0.647 | |
| 85 | + |
| 86 | +The VL 1B reranker on its own adds about +0.4 recall@1 and +2 recall@4; most of |
| 87 | +its apparent gain comes from one chunk per page. |
| 88 | + |
| 89 | +### MCP server implementation (measured) |
| 90 | + |
| 91 | +`mcp/src/server.ts` now runs vector search → keyword search fused by RRF |
| 92 | +(SQLite, `HYBRID_SEARCH`) → URL filters → reranking (`RERANKER=deepinfra`) → |
| 93 | +one chunk per page (`ONE_CHUNK_PER_PAGE`). Its built code, called through |
| 94 | +`queryDocumentation` with `limit: 4` on the same cases, scored: |
| 95 | + |
| 96 | +| Configuration | recall@1 | recall@4 | |
| 97 | +|---|---|---| |
| 98 | +| Vector only (previous behaviour) | 43.0 | 63.8 | |
| 99 | +| One chunk per page | 43.0 | 68.2 | |
| 100 | +| Hybrid + one chunk per page | 42.5 | 70.8 | |
| 101 | +| Hybrid + Nemotron-3.5-Rerank-8B + one chunk per page | 52.7 | 79.5 | |
| 102 | + |
| 103 | +These match `doc2vec eval --mode hybrid --per-page --rerank deepinfra` |
| 104 | +(identical on three sets, one case apart on the fourth, within reranker |
| 105 | +run-to-run variation). |
| 106 | + |
| 107 | +### Cost: text-embedding-3-large vs Nemotron-3.5-Embed-8B |
| 108 | + |
| 109 | +| | text-embedding-3-large (OpenAI) | Nemotron-3.5-Embed-8B (DeepInfra) | |
| 110 | +|---|---|---| |
| 111 | +| Price per 1M tokens | $0.13 ($0.065 via Batch API) | $0.035 | |
| 112 | +| Re-embed the two eval sites (5,762 chunks, ~2.4M tokens) | ~$0.31 | ~$0.08 | |
| 113 | +| Per 1M chunks (~415 tokens each) | ~$54 | ~$15 | |
| 114 | +| Per 1M queries (~20 tokens each) | ~$2.60 | ~$0.70 | |
| 115 | +| Vector size (float32) | 3072 dims, 12 KB per chunk | 4096 dims, 16 KB per chunk (+33%) | |
| 116 | +| SQLite file, kgateway / agentgateway | 46 MB / 60 MB | 58 MB / 76 MB | |
| 117 | + |
| 118 | +Nemotron supports Matryoshka truncation (1024, 768, 512 dims, re-normalized), |
| 119 | +which would make vectors smaller than today's; quality at lower dims is not |
| 120 | +yet measured. Token counts are estimated at 4 characters per token. Reranking |
| 121 | +40 chunks is about 17k tokens per query: ~$0.85 per 1,000 queries with |
| 122 | +Nemotron-3.5-Rerank-8B ($0.05/M), ~$0.17 with VL 1B ($0.01/M). Using Nemotron |
| 123 | +embeddings in production also needs `input_type` (`query` / `passage`) sent by |
| 124 | +ingestion and by the MCP server; the measured scores used it, and doc2vec does |
| 125 | +not send it today. |
| 126 | + |
| 127 | +Findings: |
| 128 | +- One chunk per page is the largest free gain: +4 to +8 points of recall@4 for every model. |
| 129 | +- Nemotron-3.5-Embed-8B and Gemini embedding-2 beat text-embedding-3-large by 5–9 points with the same search method; text-embedding-3-small and Mistral embed are the weakest. |
| 130 | +- Cutting text-embedding-3-large to 1024 dims costs nothing measurable (3x smaller vectors). |
| 131 | +- Hybrid helps weaker embeddings most; with the strongest one, vector + one chunk per page is as good or better. |
| 132 | +- Only Nemotron-3.5-Rerank-8B clearly beats the best first stage without a reranker. Most rerankers lower recall@1 below today's. |
| 133 | +- Swapping the chatbot's reranker for Nemotron-3.5-Rerank-8B gains about +5 points of recall@4 and +8 of recall@1 on today's embeddings, for about 0.6 s more median latency. |
| 134 | +- The Qwen3 retrieval instruction changes nothing on DeepInfra (it likely applies a default). |
| 135 | +- Latency under 6 parallel requests reached 5–7 s median for the 8B models on DeepInfra: plan capacity or a dedicated deployment. |
| 136 | + |
| 137 | +## Ideas |
| 138 | + |
| 139 | +1. ~~One chunk per page in the MCP query tools.~~ Done (`ONE_CHUNK_PER_PAGE=true`, opt-in). |
| 140 | +2. ~~Nemotron-3.5-Rerank-8B in the MCP server.~~ Done (`RERANKER=deepinfra`, opt-in). |
| 141 | + Still to do: the same reranker in the support chatbot. |
| 142 | +3. ~~Hybrid search for Qdrant.~~ Done: sources with `keyword_index: true` |
| 143 | + store a `bm25` sparse vector computed by Qdrant (`qdrant/bm25`), existing |
| 144 | + collections are extended and backfilled on the next sync (Qdrant 1.18+), |
| 145 | + and the MCP server queries it with `HYBRID_SEARCH=true`. SQLite builds its |
| 146 | + keyword index in memory at query time. Qdrant's BM25 stems English and drops |
| 147 | + stopwords where SQLite FTS5 does neither, so their scores can differ. |
| 148 | +4. **Record the embedding model and dimension in each database** and check it |
| 149 | + at query time; prerequisite for switching models safely. |
| 150 | +5. **Switch embeddings to Nemotron-3.5-Embed-8B or Gemini embedding-2**, |
| 151 | + with query/document input types. Needs (4), provider support in ingestion |
| 152 | + and the MCP server, and a full re-embed. |
| 153 | +6. **Lower dimensions** if staying on text-embedding-3-large: 1024 dims |
| 154 | + scored the same as 3072. |
| 155 | +7. **Contextual chunk enrichment** (LLM-written context per chunk, or a |
| 156 | + context-aware embedding model such as voyage-context-3). |
| 157 | +8. **Batch embedding requests** during ingestion (currently one chunk per |
| 158 | + call) — speed, not quality, but it makes a re-embed for (5) cheaper. |
| 159 | +9. **Multi-vector / late interaction (ColBERT, ColPali)** — last; storage cost |
| 160 | + is high and sqlite-vec has no MaxSim. ColPali only if PDFs with diagrams |
| 161 | + matter. |
| 162 | +10. **Not tested (no keys):** Voyage embeddings and rerankers, Zerank-2, Cohere |
| 163 | + Rerank 4 Pro, Jina. |
| 164 | + |
| 165 | +## Found while building the eval |
| 166 | + |
| 167 | +- **Fixed.** Chunks with identical text on different pages collapsed into one Qdrant |
| 168 | + point: the point id was derived from `chunk_id`, a hash of the chunk text |
| 169 | + (breadcrumb included), so the last page written won. Loading the eval sites |
| 170 | + into Qdrant kept 2,303 of 2,649 kgateway chunks and 2,949 of 3,113 |
| 171 | + agentgateway chunks; SQLite keeps them all. Both pages then looked changed |
| 172 | + on every sync: with the old ids, 108 of 339 kgateway pages were re-embedded |
| 173 | + on every pass. Point ids now come from the page URL and chunk position; a |
| 174 | + one-time pass on website and S3 sources restores the lost chunks (measured |
| 175 | + on a local Qdrant: the first sync rewrote 55 pages and restored all 2,649 |
| 176 | + chunks, later syncs rewrote nothing). |
| 177 | +- **Fixed.** `@qdrant/js-client-rest` 1.19 removed `search`, and the MCP |
| 178 | + server's `^1.16.2` range allowed 1.19 on a fresh install. Its vector search |
| 179 | + now uses the Query API and the client is on 1.19 (1.16 also fails on |
| 180 | + Node 26). |
0 commit comments