@graphorin/embedder-ollama 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # @graphorin/embedder-ollama
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release. First-class opt-in alternative to
8
+ `@graphorin/embedder-transformersjs`. Wraps the local Ollama HTTP
9
+ API for in-process-friendly embedding via `nomic-embed-text` (default),
10
+ `mxbai-embed-large`, `snowflake-arctic-embed`, and `bge-m3`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oleksiy Stepurenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @graphorin/embedder-ollama
2
+
3
+ > First-class opt-in alternative embedder for the Graphorin framework.
4
+
5
+ `@graphorin/embedder-ollama` wraps the local Ollama HTTP API to produce
6
+ dense embeddings without the bundled-model overhead of
7
+ `@graphorin/embedder-transformersjs`. The package targets four models
8
+ out of the box:
9
+
10
+ | Model | Dim | Notes |
11
+ |---|---:|---|
12
+ | `nomic-embed-text` (default) | 768 | Multilingual; the de-facto Ollama default. |
13
+ | `mxbai-embed-large` | 1024 | Strong English; competitive with cloud peers. |
14
+ | `snowflake-arctic-embed` | 1024 | Strong English. |
15
+ | `bge-m3` | 1024 | Multilingual; same family also ships via the transformers.js adapter. |
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pnpm add @graphorin/embedder-ollama
21
+ ```
22
+
23
+ The package has **no native peers**. It uses the standard `fetch`
24
+ API to talk to a running Ollama instance (default
25
+ `http://127.0.0.1:11434`).
26
+
27
+ ## Quick start
28
+
29
+ ```ts
30
+ import { createOllamaEmbedder } from '@graphorin/embedder-ollama';
31
+
32
+ const embedder = createOllamaEmbedder({
33
+ model: 'nomic-embed-text',
34
+ baseUrl: 'http://127.0.0.1:11434',
35
+ });
36
+
37
+ const [vec] = await embedder.embed(['Loves espresso.']);
38
+ console.log(embedder.id(), embedder.dim(), vec.length);
39
+ ```
40
+
41
+ ## Trust + privacy
42
+
43
+ The embedder operates against the same `LocalProviderTrust`
44
+ classifier as the Ollama LLM provider adapter (Phase 06). When
45
+ `baseUrl` resolves to a loopback host (`localhost`, `127.0.0.1`,
46
+ `::1`), the trust class is permanent `loopback` and accepts every
47
+ sensitivity tier (`'public'`, `'internal'`, `'secret'`). Remote /
48
+ private-network hosts trigger a one-time WARN per process and the
49
+ runtime caller may pass an explicit `acceptsSensitivity` override.
50
+
51
+ ## Versioning of `embedder_id`
52
+
53
+ The canonical id includes the Ollama model digest discovered via
54
+ `POST /api/show` at construction time. A model upgrade in the same
55
+ Ollama instance produces a different digest — and therefore a
56
+ different `embedder_id`. The default `lock-on-first` policy in
57
+ `@graphorin/store-sqlite` then fires the same migration path the
58
+ existing `transformersjs` swap takes.
59
+
60
+ ## License
61
+
62
+ MIT © 2026 Oleksiy Stepurenko.
63
+
64
+ ---
65
+
66
+ **Project Graphorin** · v0.5.0 · MIT License · © 2026 Oleksiy Stepurenko · <https://github.com/o-stepper/graphorin>
@@ -0,0 +1,137 @@
1
+ import { EmbedOptions, EmbedderProvider } from "@graphorin/core/contracts";
2
+
3
+ //#region src/index.d.ts
4
+
5
+ /** Canonical version constant. Mirrors the `package.json` version. */
6
+ declare const VERSION = "0.5.0";
7
+ /**
8
+ * Default Ollama base URL. Operators that run Ollama on a non-default
9
+ * port pass an explicit `baseUrl`.
10
+ *
11
+ * @stable
12
+ */
13
+ declare const DEFAULT_OLLAMA_BASE_URL = "http://127.0.0.1:11434";
14
+ /**
15
+ * Default Ollama model. Matches the de-facto choice in the Ollama
16
+ * community for general-purpose multilingual embeddings.
17
+ *
18
+ * @stable
19
+ */
20
+ declare const DEFAULT_OLLAMA_MODEL = "nomic-embed-text";
21
+ /**
22
+ * Options accepted by {@link createOllamaEmbedder}.
23
+ *
24
+ * @stable
25
+ */
26
+ interface OllamaEmbedderOptions {
27
+ /** Default `'nomic-embed-text'`. */
28
+ readonly model?: string;
29
+ /** Default `'http://127.0.0.1:11434'`. */
30
+ readonly baseUrl?: string;
31
+ /**
32
+ * Optional dimensionality hint. When known up-front, the canonical
33
+ * id is stable from the first `embed()` call instead of being
34
+ * resolved from the response.
35
+ */
36
+ readonly dim?: number;
37
+ /**
38
+ * Override `fetch`. Used by the test suite to inject a mock HTTP
39
+ * fixture. Production callers should leave this unset so the
40
+ * embedder uses the platform's `globalThis.fetch`.
41
+ */
42
+ readonly fetchImpl?: typeof fetch;
43
+ /**
44
+ * If `true`, skip the `POST /api/show` model-digest probe at
45
+ * construction. Used in test fixtures where the digest is
46
+ * pre-populated.
47
+ */
48
+ readonly skipDigestProbe?: boolean;
49
+ /**
50
+ * Optional pre-resolved digest (e.g. from a probe done elsewhere).
51
+ * When set, the embedder uses this value instead of issuing a
52
+ * `POST /api/show` request.
53
+ */
54
+ readonly digest?: string;
55
+ /** Optional API path override (default `'/api/embed'`). */
56
+ readonly embedPath?: string;
57
+ /** Optional API path override (default `'/api/embeddings'`). */
58
+ readonly legacyEmbedPath?: string;
59
+ /** Optional API path override (default `'/api/show'`). */
60
+ readonly showPath?: string;
61
+ /**
62
+ * Per-request hard timeout in milliseconds. Default `30000`. Each
63
+ * HTTP call (`/api/show`, `/api/embed`, legacy `/api/embeddings`) is
64
+ * aborted if the Ollama daemon does not respond in time, so a hung
65
+ * daemon never stalls the caller. A per-call {@link EmbedOptions.signal}
66
+ * is combined with this timeout. Set to `0` to disable.
67
+ */
68
+ readonly timeoutMs?: number;
69
+ }
70
+ /**
71
+ * Raised when the Ollama HTTP API returns a non-2xx response.
72
+ *
73
+ * @stable
74
+ */
75
+ declare class OllamaEmbedderError extends Error {
76
+ readonly statusCode?: number | undefined;
77
+ readonly name = "OllamaEmbedderError";
78
+ constructor(message: string, statusCode?: number | undefined, options?: {
79
+ cause?: unknown;
80
+ });
81
+ }
82
+ /**
83
+ * Model -> output-dimension hints used to seed the canonical id before the
84
+ * first `embed()` resolves the real width from a response. Only single-width
85
+ * families are listed; size-variant families (e.g. `qwen3-embedding`, whose
86
+ * dim depends on the `:0.6b` / `:4b` / `:8b` tag) are deliberately omitted so
87
+ * an ambiguous bind fails loudly rather than baking a wrong width (PS-11).
88
+ */
89
+ declare const KNOWN_OLLAMA_MODEL_DIMS: ReadonlyMap<string, number>;
90
+ /**
91
+ * Build an Ollama-backed embedder. The first `embed()` call issues a
92
+ * `POST /api/show` to capture the model digest; subsequent calls hit
93
+ * the embedding endpoint directly.
94
+ *
95
+ * @stable
96
+ */
97
+ declare function createOllamaEmbedder(options?: OllamaEmbedderOptions): OllamaEmbedder;
98
+ /**
99
+ * `EmbedderProvider` implementation that talks to the Ollama HTTP API.
100
+ *
101
+ * @stable
102
+ */
103
+ declare class OllamaEmbedder implements EmbedderProvider {
104
+ #private;
105
+ constructor(options: OllamaEmbedderOptions);
106
+ /** The canonical embedder id — `'ollama:<model>@<dim-or-digest>'`. */
107
+ id(): string;
108
+ /**
109
+ * Output dimension — the explicit `dim` option, the resolved width from the
110
+ * first `embed()`, or a known-family default. PS-11: throws for an unknown
111
+ * model with no `dim` hint instead of returning `0` (which the store would
112
+ * persist and use to create a `float[0]` vec0 table, silently breaking
113
+ * vector search). Pass `dim` for any model not in {@link
114
+ * KNOWN_OLLAMA_MODEL_DIMS}, or call `embed()` once first to resolve it.
115
+ */
116
+ dim(): number;
117
+ /**
118
+ * Deterministic hash over the embedder's full configuration —
119
+ * including the discovered digest. A model upgrade in the same
120
+ * Ollama instance changes the digest (and therefore the hash), so
121
+ * `lock-on-first` correctly fires a migration path instead of
122
+ * silently reusing the same `embedder_id`.
123
+ */
124
+ configHash(): string;
125
+ embed(texts: ReadonlyArray<string>, opts?: EmbedOptions): Promise<ReadonlyArray<Float32Array>>;
126
+ }
127
+ /**
128
+ * Canonical-JSON deterministic hash over an embedder configuration.
129
+ * Object keys are sorted lexicographically so the resulting hash is
130
+ * stable across `JSON.stringify` reorderings.
131
+ *
132
+ * @stable
133
+ */
134
+ declare function canonicalConfigHash(config: unknown): string;
135
+ //#endregion
136
+ export { DEFAULT_OLLAMA_BASE_URL, DEFAULT_OLLAMA_MODEL, KNOWN_OLLAMA_MODEL_DIMS, OllamaEmbedder, OllamaEmbedderError, OllamaEmbedderOptions, VERSION, canonicalConfigHash, createOllamaEmbedder };
137
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;AAoFA;AAkBa,cA3FA,OAAA,GAsGX,OAAA;AASF;AASA;;;;;AAwFa,cAxMA,uBAAA,GAwMA,wBAAA;;;;AAyJb;;;cAzVa,oBAAA;;;;;;UAOI,qBAAA;;;;;;;;;;;;;;;;8BAgBa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkCjB,mBAAA,SAA4B,KAAA;;;;;;;;;;;;;;cAkB5B,yBAAyB;;;;;;;;iBAoBtB,oBAAA,WAA8B,wBAA6B;;;;;;cAS9D,cAAA,YAA0B;;uBAchB;;;;;;;;;;;;;;;;;;;;eAwEZ,8BACD,eACL,QAAQ,cAAc;;;;;;;;;iBAyJX,mBAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,270 @@
1
+ import { createHash } from "node:crypto";
2
+
3
+ //#region src/index.ts
4
+ /**
5
+ * @graphorin/embedder-ollama — first-class opt-in alternative embedder
6
+ * for the Graphorin framework. Wraps the local Ollama HTTP API.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ /** Canonical version constant. Mirrors the `package.json` version. */
11
+ const VERSION = "0.5.0";
12
+ /**
13
+ * Default Ollama base URL. Operators that run Ollama on a non-default
14
+ * port pass an explicit `baseUrl`.
15
+ *
16
+ * @stable
17
+ */
18
+ const DEFAULT_OLLAMA_BASE_URL = "http://127.0.0.1:11434";
19
+ /**
20
+ * Default Ollama model. Matches the de-facto choice in the Ollama
21
+ * community for general-purpose multilingual embeddings.
22
+ *
23
+ * @stable
24
+ */
25
+ const DEFAULT_OLLAMA_MODEL = "nomic-embed-text";
26
+ /**
27
+ * Raised when the Ollama HTTP API returns a non-2xx response.
28
+ *
29
+ * @stable
30
+ */
31
+ var OllamaEmbedderError = class extends Error {
32
+ name = "OllamaEmbedderError";
33
+ constructor(message, statusCode, options) {
34
+ super(message, options);
35
+ this.statusCode = statusCode;
36
+ }
37
+ };
38
+ /**
39
+ * Model -> output-dimension hints used to seed the canonical id before the
40
+ * first `embed()` resolves the real width from a response. Only single-width
41
+ * families are listed; size-variant families (e.g. `qwen3-embedding`, whose
42
+ * dim depends on the `:0.6b` / `:4b` / `:8b` tag) are deliberately omitted so
43
+ * an ambiguous bind fails loudly rather than baking a wrong width (PS-11).
44
+ */
45
+ const KNOWN_OLLAMA_MODEL_DIMS = new Map([
46
+ ["nomic-embed-text", 768],
47
+ ["mxbai-embed-large", 1024],
48
+ ["snowflake-arctic-embed", 1024],
49
+ ["snowflake-arctic-embed2", 1024],
50
+ ["bge-m3", 1024],
51
+ ["bge-large", 1024],
52
+ ["embeddinggemma", 768],
53
+ ["all-minilm", 384],
54
+ ["granite-embedding", 384],
55
+ ["paraphrase-multilingual", 768]
56
+ ]);
57
+ /**
58
+ * Build an Ollama-backed embedder. The first `embed()` call issues a
59
+ * `POST /api/show` to capture the model digest; subsequent calls hit
60
+ * the embedding endpoint directly.
61
+ *
62
+ * @stable
63
+ */
64
+ function createOllamaEmbedder(options = {}) {
65
+ return new OllamaEmbedder(options);
66
+ }
67
+ /**
68
+ * `EmbedderProvider` implementation that talks to the Ollama HTTP API.
69
+ *
70
+ * @stable
71
+ */
72
+ var OllamaEmbedder = class {
73
+ #model;
74
+ #baseUrl;
75
+ #fetchImpl;
76
+ #skipDigestProbe;
77
+ #embedPath;
78
+ #legacyEmbedPath;
79
+ #showPath;
80
+ #timeoutMs;
81
+ #digest;
82
+ #resolvedDim;
83
+ #initialized = false;
84
+ #initializing = null;
85
+ constructor(options) {
86
+ this.#model = options.model ?? DEFAULT_OLLAMA_MODEL;
87
+ this.#baseUrl = stripTrailingSlashesLocal(options.baseUrl ?? DEFAULT_OLLAMA_BASE_URL);
88
+ this.#fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
89
+ this.#skipDigestProbe = options.skipDigestProbe ?? false;
90
+ this.#embedPath = options.embedPath ?? "/api/embed";
91
+ this.#legacyEmbedPath = options.legacyEmbedPath ?? "/api/embeddings";
92
+ this.#showPath = options.showPath ?? "/api/show";
93
+ this.#timeoutMs = options.timeoutMs ?? 3e4;
94
+ this.#digest = options.digest ?? null;
95
+ this.#resolvedDim = options.dim ?? KNOWN_OLLAMA_MODEL_DIMS.get(this.#model) ?? null;
96
+ }
97
+ /**
98
+ * Build the `{ signal }` fetch-init fragment, combining the caller's
99
+ * abort signal (if any) with the per-request timeout so a hung Ollama
100
+ * daemon cannot stall the embed call. Returns `{}` when neither
101
+ * applies. Call once per fetch — each call mints a fresh timeout.
102
+ */
103
+ #signalInit(opts) {
104
+ const timeoutSignal = this.#timeoutMs > 0 ? AbortSignal.timeout(this.#timeoutMs) : void 0;
105
+ const signal = opts.signal !== void 0 && timeoutSignal !== void 0 ? AbortSignal.any([opts.signal, timeoutSignal]) : opts.signal ?? timeoutSignal;
106
+ return signal === void 0 ? {} : { signal };
107
+ }
108
+ /** The canonical embedder id — `'ollama:<model>@<dim-or-digest>'`. */
109
+ id() {
110
+ const dim = this.dim();
111
+ const digest = this.#digest !== null ? `:${this.#digest.slice(0, 12)}` : "";
112
+ return `ollama:${this.#model}@${dim}${digest}`;
113
+ }
114
+ /**
115
+ * Output dimension — the explicit `dim` option, the resolved width from the
116
+ * first `embed()`, or a known-family default. PS-11: throws for an unknown
117
+ * model with no `dim` hint instead of returning `0` (which the store would
118
+ * persist and use to create a `float[0]` vec0 table, silently breaking
119
+ * vector search). Pass `dim` for any model not in {@link
120
+ * KNOWN_OLLAMA_MODEL_DIMS}, or call `embed()` once first to resolve it.
121
+ */
122
+ dim() {
123
+ if (this.#resolvedDim !== null) return this.#resolvedDim;
124
+ const known = KNOWN_OLLAMA_MODEL_DIMS.get(this.#model);
125
+ if (known !== void 0) return known;
126
+ throw new OllamaEmbedderError(`[graphorin/embedder-ollama] unknown output dimension for model '${this.#model}'. Pass \`dim\` to ollamaEmbedder({ model, dim }), or call embed() once to resolve it from a response, before registering the embedder.`);
127
+ }
128
+ /**
129
+ * Deterministic hash over the embedder's full configuration —
130
+ * including the discovered digest. A model upgrade in the same
131
+ * Ollama instance changes the digest (and therefore the hash), so
132
+ * `lock-on-first` correctly fires a migration path instead of
133
+ * silently reusing the same `embedder_id`.
134
+ */
135
+ configHash() {
136
+ return canonicalConfigHash({
137
+ adapter: "ollama",
138
+ model: this.#model,
139
+ baseUrl: this.#baseUrl,
140
+ digest: this.#digest ?? null,
141
+ dim: this.#resolvedDim ?? null
142
+ });
143
+ }
144
+ async embed(texts, opts = {}) {
145
+ if (texts.length === 0) return [];
146
+ await this.#ensureInitialized(opts);
147
+ return this.#callEmbed(texts, opts);
148
+ }
149
+ async #ensureInitialized(opts) {
150
+ if (this.#initialized) return;
151
+ if (this.#initializing !== null) return this.#initializing;
152
+ const inflight = (async () => {
153
+ try {
154
+ if (!this.#skipDigestProbe && this.#digest === null) await this.#probeDigest(opts);
155
+ this.#initialized = true;
156
+ } finally {
157
+ this.#initializing = null;
158
+ }
159
+ })();
160
+ this.#initializing = inflight;
161
+ return inflight;
162
+ }
163
+ async #probeDigest(opts) {
164
+ const url = `${this.#baseUrl}${this.#showPath}`;
165
+ let resp;
166
+ try {
167
+ resp = await this.#fetchImpl(url, {
168
+ method: "POST",
169
+ headers: { "content-type": "application/json" },
170
+ body: JSON.stringify({ name: this.#model }),
171
+ ...this.#signalInit(opts)
172
+ });
173
+ } catch (err) {
174
+ throw new OllamaEmbedderError(`[graphorin/embedder-ollama] failed to reach Ollama at ${url}`, void 0, { cause: err });
175
+ }
176
+ if (!resp.ok) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] /api/show returned ${resp.status} for model '${this.#model}'`, resp.status);
177
+ const json = await resp.json();
178
+ if (typeof json.digest === "string" && json.digest.length > 0) this.#digest = json.digest;
179
+ }
180
+ async #callEmbed(texts, opts) {
181
+ const batchUrl = `${this.#baseUrl}${this.#embedPath}`;
182
+ const batchBody = JSON.stringify({
183
+ model: this.#model,
184
+ input: [...texts]
185
+ });
186
+ let resp;
187
+ try {
188
+ resp = await this.#fetchImpl(batchUrl, {
189
+ method: "POST",
190
+ headers: { "content-type": "application/json" },
191
+ body: batchBody,
192
+ ...this.#signalInit(opts)
193
+ });
194
+ } catch (err) {
195
+ throw new OllamaEmbedderError(`[graphorin/embedder-ollama] failed to reach Ollama at ${batchUrl}`, void 0, { cause: err });
196
+ }
197
+ if (resp.status === 404) return this.#legacyEmbedPerText(texts, opts);
198
+ if (!resp.ok) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] /api/embed returned ${resp.status}`, resp.status);
199
+ const list = (await resp.json()).embeddings;
200
+ if (!Array.isArray(list) || list.length !== texts.length) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] /api/embed response had unexpected shape`);
201
+ const out = [];
202
+ for (let i = 0; i < list.length; i++) {
203
+ const row = list[i];
204
+ if (!Array.isArray(row)) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] embedding row ${i} is not an array`);
205
+ const f32 = Float32Array.from(row);
206
+ if (this.#resolvedDim === null) this.#resolvedDim = f32.length;
207
+ else if (this.#resolvedDim !== f32.length) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] embedding dim drifted: expected ${this.#resolvedDim}, got ${f32.length}`);
208
+ out.push(f32);
209
+ }
210
+ return out;
211
+ }
212
+ async #legacyEmbedPerText(texts, opts) {
213
+ const url = `${this.#baseUrl}${this.#legacyEmbedPath}`;
214
+ const out = [];
215
+ for (const text of texts) {
216
+ const resp = await this.#fetchImpl(url, {
217
+ method: "POST",
218
+ headers: { "content-type": "application/json" },
219
+ body: JSON.stringify({
220
+ model: this.#model,
221
+ prompt: text
222
+ }),
223
+ ...this.#signalInit(opts)
224
+ });
225
+ if (!resp.ok) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] /api/embeddings returned ${resp.status}`, resp.status);
226
+ const json = await resp.json();
227
+ if (!Array.isArray(json.embedding)) throw new OllamaEmbedderError(`[graphorin/embedder-ollama] /api/embeddings response has no 'embedding' array`);
228
+ const f32 = Float32Array.from(json.embedding);
229
+ if (this.#resolvedDim === null) this.#resolvedDim = f32.length;
230
+ out.push(f32);
231
+ }
232
+ return out;
233
+ }
234
+ };
235
+ /**
236
+ * Canonical-JSON deterministic hash over an embedder configuration.
237
+ * Object keys are sorted lexicographically so the resulting hash is
238
+ * stable across `JSON.stringify` reorderings.
239
+ *
240
+ * @stable
241
+ */
242
+ function canonicalConfigHash(config) {
243
+ return createHash("sha256").update(canonicalize(config), "utf8").digest("hex");
244
+ }
245
+ function canonicalize(value) {
246
+ if (value === null) return "null";
247
+ if (typeof value === "boolean") return value ? "true" : "false";
248
+ if (typeof value === "number") return Number.isFinite(value) ? value.toString() : "null";
249
+ if (typeof value === "string") return JSON.stringify(value);
250
+ if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
251
+ if (typeof value === "object") {
252
+ const obj = value;
253
+ return `{${Object.keys(obj).sort().map((k) => `${JSON.stringify(k)}:${canonicalize(obj[k])}`).join(",")}}`;
254
+ }
255
+ return "null";
256
+ }
257
+ /**
258
+ * Strip every trailing `/` from a URL string in `O(n)`. Kept regex-free
259
+ * so CodeQL does not flag the (otherwise harmless) `/+` anchored
260
+ * quantifier as a polynomial-redos vector.
261
+ */
262
+ function stripTrailingSlashesLocal(url) {
263
+ let end = url.length;
264
+ while (end > 0 && url.charCodeAt(end - 1) === 47) end -= 1;
265
+ return end === url.length ? url : url.slice(0, end);
266
+ }
267
+
268
+ //#endregion
269
+ export { DEFAULT_OLLAMA_BASE_URL, DEFAULT_OLLAMA_MODEL, KNOWN_OLLAMA_MODEL_DIMS, OllamaEmbedder, OllamaEmbedderError, VERSION, canonicalConfigHash, createOllamaEmbedder };
270
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["statusCode?: number","KNOWN_OLLAMA_MODEL_DIMS: ReadonlyMap<string, number>","#model","#baseUrl","#fetchImpl","#skipDigestProbe","#embedPath","#legacyEmbedPath","#showPath","#timeoutMs","#digest","#resolvedDim","#ensureInitialized","#callEmbed","#initialized","#initializing","#probeDigest","resp: Response","#signalInit","#legacyEmbedPerText","out: Float32Array[]"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @graphorin/embedder-ollama — first-class opt-in alternative embedder\n * for the Graphorin framework. Wraps the local Ollama HTTP API.\n *\n * @packageDocumentation\n */\n\nimport { createHash } from 'node:crypto';\nimport type { EmbedderProvider, EmbedOptions } from '@graphorin/core/contracts';\n\n/** Canonical version constant. Mirrors the `package.json` version. */\nexport const VERSION = '0.5.0';\n\n/**\n * Default Ollama base URL. Operators that run Ollama on a non-default\n * port pass an explicit `baseUrl`.\n *\n * @stable\n */\nexport const DEFAULT_OLLAMA_BASE_URL = 'http://127.0.0.1:11434';\n\n/**\n * Default Ollama model. Matches the de-facto choice in the Ollama\n * community for general-purpose multilingual embeddings.\n *\n * @stable\n */\nexport const DEFAULT_OLLAMA_MODEL = 'nomic-embed-text';\n\n/**\n * Options accepted by {@link createOllamaEmbedder}.\n *\n * @stable\n */\nexport interface OllamaEmbedderOptions {\n /** Default `'nomic-embed-text'`. */\n readonly model?: string;\n /** Default `'http://127.0.0.1:11434'`. */\n readonly baseUrl?: string;\n /**\n * Optional dimensionality hint. When known up-front, the canonical\n * id is stable from the first `embed()` call instead of being\n * resolved from the response.\n */\n readonly dim?: number;\n /**\n * Override `fetch`. Used by the test suite to inject a mock HTTP\n * fixture. Production callers should leave this unset so the\n * embedder uses the platform's `globalThis.fetch`.\n */\n readonly fetchImpl?: typeof fetch;\n /**\n * If `true`, skip the `POST /api/show` model-digest probe at\n * construction. Used in test fixtures where the digest is\n * pre-populated.\n */\n readonly skipDigestProbe?: boolean;\n /**\n * Optional pre-resolved digest (e.g. from a probe done elsewhere).\n * When set, the embedder uses this value instead of issuing a\n * `POST /api/show` request.\n */\n readonly digest?: string;\n /** Optional API path override (default `'/api/embed'`). */\n readonly embedPath?: string;\n /** Optional API path override (default `'/api/embeddings'`). */\n readonly legacyEmbedPath?: string;\n /** Optional API path override (default `'/api/show'`). */\n readonly showPath?: string;\n /**\n * Per-request hard timeout in milliseconds. Default `30000`. Each\n * HTTP call (`/api/show`, `/api/embed`, legacy `/api/embeddings`) is\n * aborted if the Ollama daemon does not respond in time, so a hung\n * daemon never stalls the caller. A per-call {@link EmbedOptions.signal}\n * is combined with this timeout. Set to `0` to disable.\n */\n readonly timeoutMs?: number;\n}\n\n/**\n * Raised when the Ollama HTTP API returns a non-2xx response.\n *\n * @stable\n */\nexport class OllamaEmbedderError extends Error {\n override readonly name = 'OllamaEmbedderError';\n constructor(\n message: string,\n public readonly statusCode?: number,\n options?: { cause?: unknown },\n ) {\n super(message, options);\n }\n}\n\n/**\n * Model -> output-dimension hints used to seed the canonical id before the\n * first `embed()` resolves the real width from a response. Only single-width\n * families are listed; size-variant families (e.g. `qwen3-embedding`, whose\n * dim depends on the `:0.6b` / `:4b` / `:8b` tag) are deliberately omitted so\n * an ambiguous bind fails loudly rather than baking a wrong width (PS-11).\n */\nexport const KNOWN_OLLAMA_MODEL_DIMS: ReadonlyMap<string, number> = new Map([\n ['nomic-embed-text', 768],\n ['mxbai-embed-large', 1024],\n ['snowflake-arctic-embed', 1024],\n ['snowflake-arctic-embed2', 1024],\n ['bge-m3', 1024],\n ['bge-large', 1024],\n ['embeddinggemma', 768],\n ['all-minilm', 384],\n ['granite-embedding', 384],\n ['paraphrase-multilingual', 768],\n]);\n\n/**\n * Build an Ollama-backed embedder. The first `embed()` call issues a\n * `POST /api/show` to capture the model digest; subsequent calls hit\n * the embedding endpoint directly.\n *\n * @stable\n */\nexport function createOllamaEmbedder(options: OllamaEmbedderOptions = {}): OllamaEmbedder {\n return new OllamaEmbedder(options);\n}\n\n/**\n * `EmbedderProvider` implementation that talks to the Ollama HTTP API.\n *\n * @stable\n */\nexport class OllamaEmbedder implements EmbedderProvider {\n readonly #model: string;\n readonly #baseUrl: string;\n readonly #fetchImpl: typeof fetch;\n readonly #skipDigestProbe: boolean;\n readonly #embedPath: string;\n readonly #legacyEmbedPath: string;\n readonly #showPath: string;\n readonly #timeoutMs: number;\n #digest: string | null;\n #resolvedDim: number | null;\n #initialized = false;\n #initializing: Promise<void> | null = null;\n\n constructor(options: OllamaEmbedderOptions) {\n this.#model = options.model ?? DEFAULT_OLLAMA_MODEL;\n this.#baseUrl = stripTrailingSlashesLocal(options.baseUrl ?? DEFAULT_OLLAMA_BASE_URL);\n this.#fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);\n this.#skipDigestProbe = options.skipDigestProbe ?? false;\n this.#embedPath = options.embedPath ?? '/api/embed';\n this.#legacyEmbedPath = options.legacyEmbedPath ?? '/api/embeddings';\n this.#showPath = options.showPath ?? '/api/show';\n this.#timeoutMs = options.timeoutMs ?? 30_000;\n this.#digest = options.digest ?? null;\n this.#resolvedDim = options.dim ?? KNOWN_OLLAMA_MODEL_DIMS.get(this.#model) ?? null;\n }\n\n /**\n * Build the `{ signal }` fetch-init fragment, combining the caller's\n * abort signal (if any) with the per-request timeout so a hung Ollama\n * daemon cannot stall the embed call. Returns `{}` when neither\n * applies. Call once per fetch — each call mints a fresh timeout.\n */\n #signalInit(opts: EmbedOptions): { signal?: AbortSignal } {\n const timeoutSignal = this.#timeoutMs > 0 ? AbortSignal.timeout(this.#timeoutMs) : undefined;\n const signal =\n opts.signal !== undefined && timeoutSignal !== undefined\n ? AbortSignal.any([opts.signal, timeoutSignal])\n : (opts.signal ?? timeoutSignal);\n return signal === undefined ? {} : { signal };\n }\n\n /** The canonical embedder id — `'ollama:<model>@<dim-or-digest>'`. */\n id(): string {\n const dim = this.dim();\n const digest = this.#digest !== null ? `:${this.#digest.slice(0, 12)}` : '';\n return `ollama:${this.#model}@${dim}${digest}`;\n }\n\n /**\n * Output dimension — the explicit `dim` option, the resolved width from the\n * first `embed()`, or a known-family default. PS-11: throws for an unknown\n * model with no `dim` hint instead of returning `0` (which the store would\n * persist and use to create a `float[0]` vec0 table, silently breaking\n * vector search). Pass `dim` for any model not in {@link\n * KNOWN_OLLAMA_MODEL_DIMS}, or call `embed()` once first to resolve it.\n */\n dim(): number {\n if (this.#resolvedDim !== null) return this.#resolvedDim;\n const known = KNOWN_OLLAMA_MODEL_DIMS.get(this.#model);\n if (known !== undefined) return known;\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] unknown output dimension for model '${this.#model}'. ` +\n 'Pass `dim` to ollamaEmbedder({ model, dim }), or call embed() once to resolve it ' +\n 'from a response, before registering the embedder.',\n );\n }\n\n /**\n * Deterministic hash over the embedder's full configuration —\n * including the discovered digest. A model upgrade in the same\n * Ollama instance changes the digest (and therefore the hash), so\n * `lock-on-first` correctly fires a migration path instead of\n * silently reusing the same `embedder_id`.\n */\n configHash(): string {\n return canonicalConfigHash({\n adapter: 'ollama',\n model: this.#model,\n baseUrl: this.#baseUrl,\n digest: this.#digest ?? null,\n dim: this.#resolvedDim ?? null,\n });\n }\n\n async embed(\n texts: ReadonlyArray<string>,\n opts: EmbedOptions = {},\n ): Promise<ReadonlyArray<Float32Array>> {\n if (texts.length === 0) return [];\n await this.#ensureInitialized(opts);\n return this.#callEmbed(texts, opts);\n }\n\n async #ensureInitialized(opts: EmbedOptions): Promise<void> {\n if (this.#initialized) return;\n if (this.#initializing !== null) return this.#initializing;\n const inflight = (async () => {\n try {\n if (!this.#skipDigestProbe && this.#digest === null) {\n await this.#probeDigest(opts);\n }\n this.#initialized = true;\n } finally {\n // Always clear the in-flight slot so a transient failure does\n // not poison every subsequent call with the same rejection.\n this.#initializing = null;\n }\n })();\n this.#initializing = inflight;\n return inflight;\n }\n\n async #probeDigest(opts: EmbedOptions): Promise<void> {\n const url = `${this.#baseUrl}${this.#showPath}`;\n let resp: Response;\n try {\n resp = await this.#fetchImpl(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ name: this.#model }),\n ...this.#signalInit(opts),\n });\n } catch (err) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] failed to reach Ollama at ${url}`,\n undefined,\n { cause: err },\n );\n }\n if (!resp.ok) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] /api/show returned ${resp.status} for model '${this.#model}'`,\n resp.status,\n );\n }\n const json = (await resp.json()) as { digest?: string };\n if (typeof json.digest === 'string' && json.digest.length > 0) {\n this.#digest = json.digest;\n }\n }\n\n async #callEmbed(\n texts: ReadonlyArray<string>,\n opts: EmbedOptions,\n ): Promise<ReadonlyArray<Float32Array>> {\n const batchUrl = `${this.#baseUrl}${this.#embedPath}`;\n const batchBody = JSON.stringify({ model: this.#model, input: [...texts] });\n let resp: Response;\n try {\n resp = await this.#fetchImpl(batchUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: batchBody,\n ...this.#signalInit(opts),\n });\n } catch (err) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] failed to reach Ollama at ${batchUrl}`,\n undefined,\n { cause: err },\n );\n }\n if (resp.status === 404) {\n // Older Ollama versions only expose the legacy single-input path.\n return this.#legacyEmbedPerText(texts, opts);\n }\n if (!resp.ok) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] /api/embed returned ${resp.status}`,\n resp.status,\n );\n }\n const json = (await resp.json()) as { embeddings?: number[][] };\n const list = json.embeddings;\n if (!Array.isArray(list) || list.length !== texts.length) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] /api/embed response had unexpected shape`,\n );\n }\n const out: Float32Array[] = [];\n for (let i = 0; i < list.length; i++) {\n const row = list[i];\n if (!Array.isArray(row)) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] embedding row ${i} is not an array`,\n );\n }\n const f32 = Float32Array.from(row);\n if (this.#resolvedDim === null) {\n this.#resolvedDim = f32.length;\n } else if (this.#resolvedDim !== f32.length) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] embedding dim drifted: expected ${this.#resolvedDim}, got ${f32.length}`,\n );\n }\n out.push(f32);\n }\n return out;\n }\n\n async #legacyEmbedPerText(\n texts: ReadonlyArray<string>,\n opts: EmbedOptions,\n ): Promise<ReadonlyArray<Float32Array>> {\n const url = `${this.#baseUrl}${this.#legacyEmbedPath}`;\n const out: Float32Array[] = [];\n for (const text of texts) {\n const resp = await this.#fetchImpl(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ model: this.#model, prompt: text }),\n ...this.#signalInit(opts),\n });\n if (!resp.ok) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] /api/embeddings returned ${resp.status}`,\n resp.status,\n );\n }\n const json = (await resp.json()) as { embedding?: number[] };\n if (!Array.isArray(json.embedding)) {\n throw new OllamaEmbedderError(\n `[graphorin/embedder-ollama] /api/embeddings response has no 'embedding' array`,\n );\n }\n const f32 = Float32Array.from(json.embedding);\n if (this.#resolvedDim === null) this.#resolvedDim = f32.length;\n out.push(f32);\n }\n return out;\n }\n}\n\n/**\n * Canonical-JSON deterministic hash over an embedder configuration.\n * Object keys are sorted lexicographically so the resulting hash is\n * stable across `JSON.stringify` reorderings.\n *\n * @stable\n */\nexport function canonicalConfigHash(config: unknown): string {\n return createHash('sha256').update(canonicalize(config), 'utf8').digest('hex');\n}\n\nfunction canonicalize(value: unknown): string {\n if (value === null) return 'null';\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n if (typeof value === 'number') return Number.isFinite(value) ? value.toString() : 'null';\n if (typeof value === 'string') return JSON.stringify(value);\n if (Array.isArray(value)) {\n return `[${value.map(canonicalize).join(',')}]`;\n }\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalize(obj[k])}`).join(',')}}`;\n }\n return 'null';\n}\n\n/**\n * Strip every trailing `/` from a URL string in `O(n)`. Kept regex-free\n * so CodeQL does not flag the (otherwise harmless) `/+` anchored\n * quantifier as a polynomial-redos vector.\n */\nfunction stripTrailingSlashesLocal(url: string): string {\n let end = url.length;\n while (end > 0 && url.charCodeAt(end - 1) === 0x2f) end -= 1;\n return end === url.length ? url : url.slice(0, end);\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAa,UAAU;;;;;;;AAQvB,MAAa,0BAA0B;;;;;;;AAQvC,MAAa,uBAAuB;;;;;;AAyDpC,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAkB,OAAO;CACzB,YACE,SACA,AAAgBA,YAChB,SACA;AACA,QAAM,SAAS,QAAQ;EAHP;;;;;;;;;;AAcpB,MAAaC,0BAAuD,IAAI,IAAI;CAC1E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MAAM,QAAQ,MAAM,CACtB,QAAO,IAAI,MAAM,IAAI,aAAa,CAAC,KAAK,IAAI,CAAC;AAE/C,KAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,MAAM;AAEZ,SAAO,IADM,OAAO,KAAK,IAAI,CAAC,MAAM,CACpB,KAAK,MAAM,GAAG,KAAK,UAAU,EAAE,CAAC,GAAG,aAAa,IAAI,GAAG,GAAG,CAAC,KAAK,IAAI,CAAC;;AAEvF,QAAO;;;;;;;AAQT,SAAS,0BAA0B,KAAqB;CACtD,IAAI,MAAM,IAAI;AACd,QAAO,MAAM,KAAK,IAAI,WAAW,MAAM,EAAE,KAAK,GAAM,QAAO;AAC3D,QAAO,QAAQ,IAAI,SAAS,MAAM,IAAI,MAAM,GAAG,IAAI"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@graphorin/embedder-ollama",
3
+ "version": "0.5.0",
4
+ "description": "First-class opt-in alternative to @graphorin/embedder-transformersjs for the Graphorin framework. Wraps the local Ollama HTTP API to produce dense embeddings via models such as `nomic-embed-text` (768-dim, multilingual default), `mxbai-embed-large` (1024-dim), `snowflake-arctic-embed` (1024-dim), and `bge-m3` (1024-dim). Implements the `EmbedderProvider` contract with a deterministic configHash that includes the model digest reported by `POST /api/show`, so a model upgrade in the same Ollama instance produces a different embedder_id and the multi-table per-embedder vec0 layout in `@graphorin/store-sqlite` triggers a clean migration path.",
5
+ "license": "MIT",
6
+ "author": "Oleksiy Stepurenko",
7
+ "homepage": "https://github.com/o-stepper/graphorin/tree/main/packages/embedder-ollama",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/o-stepper/graphorin.git",
11
+ "directory": "packages/embedder-ollama"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/o-stepper/graphorin/issues"
15
+ },
16
+ "keywords": [
17
+ "graphorin",
18
+ "ai",
19
+ "agents",
20
+ "framework",
21
+ "embeddings",
22
+ "ollama",
23
+ "nomic-embed-text",
24
+ "bge-m3",
25
+ "local-first"
26
+ ],
27
+ "type": "module",
28
+ "engines": {
29
+ "node": ">=22.0.0"
30
+ },
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "CHANGELOG.md",
45
+ "LICENSE"
46
+ ],
47
+ "dependencies": {
48
+ "@graphorin/core": "0.5.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "provenance": true
53
+ },
54
+ "devDependencies": {
55
+ "@graphorin/store-sqlite": "0.5.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsdown",
59
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",
60
+ "test": "vitest run",
61
+ "lint": "biome check .",
62
+ "clean": "rimraf dist .turbo *.tsbuildinfo"
63
+ }
64
+ }