Repository navigation
Commit 71df02e
feat(p12.2-4): BM25 + IntentRanker (Legacy / Bm25Hybrid / LlmRerank)
Per audit semantic-rank-layer 2026-05-05 :
L4 verdict WRONG : "no-bm25-only-baseline-measured (impact 5)" — the
audit blocked the original dense-first plan and demanded BM25 as the
measurable baseline first. This commit ships that baseline + the
layered IntentRanker abstraction the audit recommended.
L4 finding "llm-rerank-top-k-not-considered (impact 4)" — for SatRank's
current 192-row catalogue and <10 qps regime, BM25 narrow → Claude
Haiku rerank top-K is the audit-validated default. This commit ships
the LlmRerankRanker as one of the IntentRanker variants, gated by
RANKER_MODE env var (next commit).
L2 architecture : "EmbeddingProvider/VectorIndex/IntentRanker is
correctly placed seam" — IntentRanker interface is the seam; future
rankers (DenseHybridRanker, CrossEncoderRanker, GbdtLtrRanker) plug
in without rewriting intentService.
What ships :
src/services/bm25Service.ts
Standard Okapi BM25 (k1=1.5, b=0.75). In-memory inverted index +
English stopwords + lowercase non-alphanumeric tokenizer. Exposes :
buildIndex(docs) — rebuild from catalogue
score(docId, query) — single-doc score
topK(query, k) — top-K matching docs
explain(docId, query) — per-term contribution (audit L5 + L6)
stats() — diagnostics
Sub-ms p_avg at 192 docs ; ~30MB RAM at 100k docs.
src/services/intentRanker.ts
IntentRanker interface :
rank(intentText, candidates) → RankedCandidate[]
Three implementations :
LegacyRanker — pre-P12 ordering (p_e2e DESC)
Bm25HybridRanker — 0.5 × BM25 + 0.5 × p_e2e
LlmRerankRanker — BM25 narrow top-20 → LLM rerank top-K
+ buildAnthropicRerankAdapter — wires LlmRerankRanker.llmCall to
@anthropic-ai/sdk Messages.create with claude-haiku-4-5 default.
Anthropic SDK 0.93+ added as a runtime dep (was already in scripts/sim
but not in main package.json). Dependency is OPTIONAL at runtime — the
IntentRanker stack defaults to LegacyRanker when RANKER_MODE is unset.
Tests :
- 23 BM25 tests covering tokenize / buildIndex / topK / score /
explain / stats / 192-doc perf smoke (<50ms build, <10ms p_avg topK)
- 18 IntentRanker tests covering LegacyRanker tiebreaks / Bm25Hybrid
fallback + Sim-13-hyperdope-equivalent regression / LlmRerank LLM-
error fallback / buildAnthropicRerankAdapter JSON parsing
1876 server tests total ; tsc strict + tsc-tests strict clean.
Wiring into intentService + RANKER_MODE flag come in the next commit.
Production behaviour is UNCHANGED until that commit lands.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2b2dc1c commit 71df02e
6 files changed
Lines changed: 1070 additions & 0 deletions
File tree
- src
- services
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
0 commit comments