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 42314c6
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
+
Embedding vectors for Interchange agents: a retrieval primitive (a small search building block) that plugs into `@intx/inference`.
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
+
An embedding is a list of numbers that captures what a piece of text means. Similar texts get similar numbers, so you can search by meaning. This package sends your text to an embedding model and gives you the vectors back in order. It works with any server that speaks the OpenAI embeddings format, including OpenAI, Ollama, TEI, vLLM and Jina. To switch models, change the config. It does not store or search vectors. For that, pair it with [`@corbits/memory`](https://github.com/corbitsdev/corbits-memory).
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
+
## Where it fits
8
+
9
+
[Interchange](https://github.com/faremeter/interchange) runs AI agents with their own identity and permissions. Corbits packages add the parts an agent product needs around it.
10
+
11
+
-**Runs in:** any process. That can be the Interchange hub (the server that manages tenants and agents), an agent sidecar (the runtime next to each agent), or a plain script. No hub is needed.
12
+
-**Plugs into:**[`@intx/inference`](https://github.com/faremeter/interchange) for retries and error types, and [`@intx/types`](https://github.com/faremeter/interchange).
13
+
-**Pairs with:**[`@corbits/reranking`](https://github.com/corbitsdev/corbits-reranking) to sort search results, and [`@corbits/memory`](https://github.com/corbitsdev/corbits-memory) to store and search vectors.
10
14
11
15
## Install
12
16
@@ -18,6 +22,8 @@ Runs on Bun >= 1.2 or Node >= 24.
18
22
19
23
## Quickstart
20
24
25
+
This example needs a local Ollama with the model pulled: `ollama pull nomic-embed-text`.
|`baseURL`|`string`| Server root with its version path, such as `http://host:11434/v1`. |
55
+
|`model`|`string`| Model name. |
56
+
|`apiKey`|`string?`| Sent as a bearer token. |
57
+
|`dimensions`|`number?`| Asks for shorter vectors. Only some models support it. Sent only when set. |
58
+
|`encodingFormat`|`"float" \| "base64"?`| Wire format. Defaults to `float`. You always get numbers back. |
59
+
|`batchSize`|`number?`| Texts per request. Defaults to 32. |
60
+
|`timeoutMs`|`number?`| Time limit per request. Defaults to 30000. |
40
61
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`.
|`deps`|`{ fetch, scheduler }`. Defaults to global `fetch` and Interchange's scheduler. |
67
+
|`retryPolicy`| Decides when to retry. Defaults to Interchange's policy. |
68
+
|`extractRetryAfterMs`| Reads how long the server asks you to wait. Defaults to `Retry-After`. |
69
+
|`signal`| Cancels the requests. |
44
70
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.
71
+
### Errors
72
+
73
+
A failed request throws `EmbeddingRequestError`. Its `reason` says what went wrong, and `url` says where. A bad config throws before any request is sent.
74
+
75
+
### Vector length
76
+
77
+
Each model returns vectors of a fixed length. `nomic-embed-text` returns 768 numbers, and OpenAI `text-embedding-3-small` returns 1536. If you store vectors, call `probeEmbedDims` at startup to learn the length. Changing models changes the length, so treat it like a database migration.
46
78
47
79
## Using with Interchange
48
80
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.
81
+
`@intx/inference` and `@intx/types` are peer dependencies. Your host's Interchange version supplies them. Rate limits (HTTP 429) are retried after a pause. Bad credentials are not retried.
82
+
83
+
The scheduler is the Interchange object that times retries. To share one with the rest of your host, pass it in:
- Install `@intx/inference` and `@intx/types` (^0.4.0) yourself. They are now peer dependencies.
102
+
-`ModelRequestError` is renamed to `EmbeddingRequestError`.
103
+
-`runJSONRequest`, `extractRetryAfterMs` and `RunRequestOptions` are no longer exported. To change how retry waits are read, pass `options.extractRetryAfterMs`.
0 commit comments