You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ee7b566
Browse filesBrowse the repository at this point in the historyBrowse files
One API for every embedding provider. Point at any OpenAI-compatible `/v1/embeddings` endpoint, swap models with a config change, and get ordered vectors back.
3
+
Batched text embeddings over any OpenAI-compatible `/v1/embeddings` endpoint, built on `@intx/inference` retries and error classification. A retrieval building block for Corbits and Interchange agents that also works standalone.
4
4
5
-
OpenAI, Ollama, TEI, vLLM, and Jina all serve the same wire shape. This package is one code path over that shape, with parameters for what varies between providers:
5
+
## Why @corbits/embedding?
6
6
7
-
-`dimensions` — Matryoshka truncation for models that support it, including OpenAI `text-embedding-3` (down to 256), Jina v3 (32), and Jina v4 (128). Sent only when set, so models without MRL stay happy.
8
-
-`encodingFormat` — `float` (default) or compact `base64`.
9
-
-`batchSize` — inputs per request (default 32). Tune it to provider caps and per-request token ceilings.
7
+
1.**One client for every provider.** OpenAI, Ollama, TEI, vLLM and Jina all speak the same wire format. Switching models is a config change.
8
+
2.**Order-safe batching.** Inputs are split into batches, and vectors come back in input order, placed by the index each response echoes. Short or duplicate replies throw instead of misaligning results.
9
+
3.**Interchange retry semantics.** Requests run through `@intx/inference`, so a 429 backs off and a 401 fails the same way it does for inference calls. Failures throw a typed `EmbeddingRequestError`.
10
+
11
+
It does not store or search vectors. For that, pair it with [`@corbits/memory`](https://github.com/corbitsdev/corbits-memory).
10
12
11
13
## Install
12
14
@@ -18,6 +20,8 @@ Runs on Bun >= 1.2 or Node >= 24.
18
20
19
21
## Quickstart
20
22
23
+
Needs a local Ollama with `nomic-embed-text` pulled.
`embedTexts(texts, config, options?)` batches sequentially, posts each batch to
34
-
`{baseURL}/embeddings`, and returns vectors in input order. `options` is
35
-
optional: `deps` (defaults to global `fetch` and `@intx/inference`'s
36
-
`createDefaultScheduler()`),
37
-
`retryPolicy`, `extractRetryAfterMs`, and `signal`.
37
+
## Where it fits
38
+
39
+
[Interchange](https://github.com/faremeter/interchange) runs AI agents as principals (accounts that hold their own identity, permissions and credentials). Corbits packages add what an agent product needs around it.
40
+
41
+
-**Runs in:** any process: the Interchange hub (the multi-tenant control plane), an agent sidecar (the runtime next to each agent), or a plain script. No hub is required.
42
+
-**Plugs into:**[`@intx/inference`](https://github.com/faremeter/interchange) for transport, retries and error classification, and [`@intx/types`](https://github.com/faremeter/interchange).
43
+
-**Pairs with:**[`@corbits/reranking`](https://github.com/corbitsdev/corbits-reranking) to reorder results and [`@corbits/memory`](https://github.com/corbitsdev/corbits-memory) to store and search vectors.
|`embedTexts(texts, config, options?)`| Embeds the texts and returns one vector per text, in order. |
50
+
|`probeEmbedDims(config, options?)`| Embeds one probe string and returns the vector dimension. |
51
+
|`EmbedConfigSchema`, `EmbedConfig`| Schema and type for `config`. |
52
+
|`EmbedOptions`| Type for `options`. |
53
+
|`EmbeddingRequestError`| Thrown when a request fails. |
54
+
|`RequestDependencies`, `RetryAfterExtractor`| Types for `options.deps` and `options.extractRetryAfterMs`. |
38
55
39
-
##Dimensionality
56
+
### Config
40
57
41
-
`probeEmbedDims(config)` embeds one probe string and reports the length received. Dimensionality follows the provider and the `dimensions` setting, so callers that persist vectors discover it at startup and treat a model swap as a migration. Representative widths: 1536 for OpenAI `text-embedding-3-small`, 768 for `nomic-embed-text`, 384 for `bge-small-en-v1.5`.
|`baseURL`|`string`| Server root with its version path, such as `http://host:11434/v1`. |
61
+
|`model`|`string`| Model name. |
62
+
|`apiKey`|`string?`| Sent as a bearer token. |
63
+
|`dimensions`|`number?`| Requested output dimension. Sent only when set; not all models honor it. |
64
+
|`encodingFormat`|`"float" \| "base64"?`| Wire format. Defaults to `float`. Results are always `number[]`. |
65
+
|`batchSize`|`number?`| Texts per request. Defaults to 32. |
66
+
|`timeoutMs`|`number?`| Per-request timeout. Defaults to 30000. |
42
67
43
-
##Errors
68
+
### Options
44
69
45
-
Every request failure — transport, HTTP status, or a 200 with an unexpected body — throws `EmbeddingRequestError` (`extends Error`), carrying the classified `InferenceError` as `reason` and the request `url`. A config that fails `EmbedConfigSchema` throws arktype's `TraversalError` before any request.
|`deps`|`{ fetch, scheduler }`. Defaults to global `fetch` and Interchange's scheduler. |
73
+
|`retryPolicy`| Retry policy. Defaults to Interchange's policy. |
74
+
|`extractRetryAfterMs`| Reads the server's retry delay. Defaults to parsing `Retry-After`. |
75
+
|`signal`| Aborts all pending requests. |
76
+
77
+
### Errors
78
+
79
+
A failed request throws `EmbeddingRequestError` with a classified `reason` and the request `url`. An invalid config throws before any request is sent.
80
+
81
+
### Dimensions
82
+
83
+
Each model has a fixed output dimension: 768 for `nomic-embed-text`, 1536 for OpenAI `text-embedding-3-small`. If you store vectors, call `probeEmbedDims` at startup. Changing models changes the dimension, so treat it as a schema migration.
46
84
47
85
## Using with Interchange
48
86
49
-
Requests go through `deps.fetch`, failures are classified into `@intx/inference`'s `InferenceError`, and `createDefaultRetryPolicy` decides retries: a 429 backs off and retries, a credential failure does not. `@intx/inference` and `@intx/types` are peer dependencies, so the host's Interchange version is the one used.
87
+
`@intx/inference` and `@intx/types` are peer dependencies, so your host's Interchange version supplies them.
88
+
89
+
To share the retry scheduler with the rest of your host, pass it in:
- Install `@intx/inference` and `@intx/types` (^0.4.0) yourself. They are now peer dependencies.
108
+
-`ModelRequestError` is renamed to `EmbeddingRequestError`.
109
+
-`runJSONRequest`, `extractRetryAfterMs` and `RunRequestOptions` are no longer exported. To change how retry waits are read, pass `options.extractRetryAfterMs`.
0 commit comments