Repository navigation
Commit 2a00fe0
committed
Initial commit: rerank client on the Interchange inference primitives
`rerankDocuments` posts a query and candidate set to a reranker, maps the reply
back to caller-supplied document ids, and returns {id, score} sorted descending.
Three wire formats, because reranking has no OpenAI-compatible standard and is
not converging on one — TEI does not serve an OpenAI-shaped rerank route at all
(huggingface/text-embeddings-inference#683):
tei /rerank {query, texts} -> [{index, score}]
cohere /v2/rerank {query, documents} -> {results: [{index, relevance_score}]}
voyage /v1/rerank {query, documents} -> {data: [{index, relevance_score}]}
Jina's /rerank uses Cohere's shape and is served by that adapter. This is a real
adapter boundary rather than a knob, which is the opposite conclusion from
@corbits/embedding — there, every provider serves one /v1/embeddings shape and
only the parameters differ. Cohere and Voyage require a model and fail by name
at request-build time rather than as a 400 in production; TEI serves whatever
model it was started with.
Scores are mapped through docs[index], never by reply position. Every protocol
addresses documents by their offset in the request array and TEI's reply is
explicitly unordered, so trusting position would attach the top score to the
wrong document. An out-of-range index raises. RerankDoc.id exists for this
reason: the wire formats only speak in offsets, so translating back to a stable
identifier belongs here rather than in every caller.
Built on @intx/inference rather than reimplementing it. Requests are
BuiltRequests sent through the single deps.fetch path; deps.scheduler drives
elapsed time and backoff so virtual-clock tests run the retry loop with no wall
time; failures classify through the shared taxonomy, including a 200 whose body
is not JSON (classifyProtocolMismatch), which a local model server behind a
proxy will produce; createDefaultRetryPolicy decides back-off vs abort, and an
abort mid-delay wakes immediately as the harness documents. The client this
replaces had no retry at all.
RerankAdapter mirrors ProviderAdapter — same buildRequest/parseResponse members,
same optional extractRetryAfterMs. Styles resolve through a Map-backed registry
mirroring createAdapterRegistry, so an apiStyle from config cannot reach an
inherited Object.prototype member and fail later as an opaque TypeError. deps is
Pick<Dependencies, "fetch" | "scheduler">: callers should not have to assemble a
registry of inference providers in order to rerank a list.
Failures raise rather than degrading soft. A reranker outage should be a policy
decision at the call site — a retrieval pipeline usually wants to fall back to
fused ordering — and it cannot make that choice if the failure is hidden here.
Naming follows the published @intX surface rather than assumption: baseURL (used
18 times upstream, baseUrl zero), uppercase acronyms in type names, lowercase
leading acronym in apiKey/apiStyle to match upstream's own apiKey.
Tests: 21 pass. Typecheck, prettier and build clean, all four gated in CI. The
index-mapping and retry paths were regression-verified by reintroducing each bug
and confirming the tests fail.
Refs CL-4539, CL-4549, CL-4550
Claude-Session: https://claude.ai/code/session_017GTgGzn5xAwvkU2GAPAHpF0 parents commit 2a00fe0
14 files changed
Lines changed: 1609 additions & 0 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Large diffs are not rendered by default.
| 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 | + | |
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 | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments