Repository navigation
Commit f3d9557
committed
Initial commit: embedding client on the Interchange inference primitives
`embedTexts` embeds a corpus in batches against any /v1/embeddings endpoint;
`probeEmbedDims` discovers a model's output dimensionality by embedding one
probe string.
One wire format, no adapter layer. OpenAI, Ollama, TEI, vLLM and Jina all serve
/v1/embeddings and differ only in parameters, so a provider switch would be
three copies of the same function. Verified live rather than assumed: Ollama
returns 768 dims there, matching its native /api/embed, and a TEI container
running bge-small-en-v1.5 returns 384, matching its native /embed. This is the
opposite conclusion from @corbits/reranking, and deliberately so — that protocol
has no standard, this one does.
Dimensionality is discovered, never assumed. It varies by provider and is
changed by `dimensions` (Matryoshka truncation: OpenAI text-embedding-3 to 256,
Jina v3 to 32, v4 to 128), so anything persisting vectors must probe for it.
Vectors are placed by the `index` each entry echoes, never by reply position,
and a reply that is not exactly one entry per input is rejected. OpenAI does not
promise reply order, and callers pair vectors with their own texts positionally
— so a reordered or short reply would not fail loudly, it would silently persist
text/vector pairs that are wrong. The base64 encoding is decoded as a
little-endian float32 buffer, so the option the config advertises actually
round-trips.
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. A caller signal and
timeoutMs compose via AbortSignal.any rather than the signal silently winning.
The client this replaces had no retry at all.
deps is Pick<Dependencies, "fetch" | "scheduler">: callers should not have to
assemble a registry of inference providers in order to embed a string. A real
Dependencies still satisfies it structurally.
Batches are sequential rather than concurrent. A provider that rate-limits would
otherwise see the whole corpus at once, and the retry policy is per request, not
per burst.
Naming follows the published @intX surface rather than assumption: baseURL (used
18 times upstream, baseUrl zero) and uppercase acronyms in identifiers.
Tests: 19 pass. Typecheck, prettier and build clean, all four gated in CI. The
retry, index-mapping and timeout 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 f3d9557
13 files changed
Lines changed: 1522 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 | + | |
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