@graphorin/embedder-ollama 0.6.0 → 0.6.1
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 +9 -0
- package/README.md +22 -10
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @graphorin/embedder-ollama
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#142](https://github.com/o-stepper/graphorin/pull/142) [`436d6ca`](https://github.com/o-stepper/graphorin/commit/436d6ca5ebbd16df094e915682d3915c279a8430) Thanks [@o-stepper](https://github.com/o-stepper)! - Version constants and version-bearing strings now derive from each package's manifest at build time (`VERSION = pkg.version`; writer ids, client/server info, OTLP framework attributes, build-info metrics interpolate it). No behavioral change at the current version: the rendered strings are byte-identical. A release bump no longer edits source; the new `check-version-consistency` gate fails any reintroduced hardcoded framework version.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`436d6ca`](https://github.com/o-stepper/graphorin/commit/436d6ca5ebbd16df094e915682d3915c279a8430)]:
|
|
10
|
+
- @graphorin/core@0.6.1
|
|
11
|
+
|
|
3
12
|
## 0.6.0
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -4,15 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
`@graphorin/embedder-ollama` wraps the local Ollama HTTP API to produce
|
|
6
6
|
dense embeddings without the bundled-model overhead of
|
|
7
|
-
`@graphorin/embedder-transformersjs`. The package
|
|
8
|
-
out of the box
|
|
7
|
+
`@graphorin/embedder-transformersjs`. The package ships known output
|
|
8
|
+
dimensions for ten common Ollama embedding models out of the box
|
|
9
|
+
(`KNOWN_OLLAMA_MODEL_DIMS`); any other model works too by passing an
|
|
10
|
+
explicit `dim`:
|
|
9
11
|
|
|
10
12
|
| Model | Dim | Notes |
|
|
11
13
|
|---|---:|---|
|
|
12
14
|
| `nomic-embed-text` (default) | 768 | Multilingual; the de-facto Ollama default. |
|
|
13
15
|
| `mxbai-embed-large` | 1024 | Strong English; competitive with cloud peers. |
|
|
14
16
|
| `snowflake-arctic-embed` | 1024 | Strong English. |
|
|
17
|
+
| `snowflake-arctic-embed2` | 1024 | Multilingual successor to arctic-embed. |
|
|
15
18
|
| `bge-m3` | 1024 | Multilingual; same family also ships via the transformers.js adapter. |
|
|
19
|
+
| `bge-large` | 1024 | Strong English. |
|
|
20
|
+
| `embeddinggemma` | 768 | Multilingual (Google). |
|
|
21
|
+
| `paraphrase-multilingual` | 768 | Multilingual paraphrase family. |
|
|
22
|
+
| `all-minilm` | 384 | Compact English. |
|
|
23
|
+
| `granite-embedding` | 384 | Compact (IBM). |
|
|
24
|
+
|
|
25
|
+
Multi-size models (e.g. tags whose dimension depends on the `:0.6b` /
|
|
26
|
+
`:4b` / `:8b` variant) are deliberately omitted from the known-dims
|
|
27
|
+
map so an ambiguous bind fails loudly instead of baking a wrong width.
|
|
16
28
|
|
|
17
29
|
## Install
|
|
18
30
|
|
|
@@ -40,13 +52,13 @@ console.log(embedder.id(), embedder.dim(), vec.length);
|
|
|
40
52
|
|
|
41
53
|
## Trust + privacy
|
|
42
54
|
|
|
43
|
-
The embedder
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
sensitivity
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
The embedder itself performs no trust classification - it is a thin
|
|
56
|
+
client for whatever `baseUrl` you give it, and it never talks to
|
|
57
|
+
anything else. Point it at a loopback Ollama (`http://127.0.0.1:11434`,
|
|
58
|
+
the default) and embeddings never leave the machine. Trust
|
|
59
|
+
classification and sensitivity gating for LLM traffic live one layer
|
|
60
|
+
up, in `@graphorin/provider`'s `LocalProviderTrust` classifier; apply
|
|
61
|
+
the same judgement before pointing this embedder at a remote host.
|
|
50
62
|
|
|
51
63
|
## Versioning of `embedder_id`
|
|
52
64
|
|
|
@@ -63,4 +75,4 @@ MIT © 2026 Oleksiy Stepurenko.
|
|
|
63
75
|
|
|
64
76
|
---
|
|
65
77
|
|
|
66
|
-
**Project Graphorin** · v0.6.
|
|
78
|
+
**Project Graphorin** · v0.6.1 · MIT License · © 2026 Oleksiy Stepurenko · <https://github.com/o-stepper/graphorin>
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { EmbedOptions, EmbedderProvider } from "@graphorin/core/contracts";
|
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
declare const VERSION = "0.6.0";
|
|
5
|
+
declare const VERSION: string;
|
|
7
6
|
/**
|
|
8
7
|
* Default Ollama base URL. Operators that run Ollama on a non-default
|
|
9
8
|
* port pass an explicit `baseUrl`.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;AAsFa,cAzEA,OAyEoB,EAAA,MAAA;AAkBjC;AAoBA;AASA;;;;AAwF2B,cAxMd,uBAAA,GAwMc,wBAAA;;;;;AAyJ3B;;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
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { version } from "./package.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
|
|
3
4
|
//#region src/index.ts
|
|
@@ -7,8 +8,8 @@ import { createHash } from "node:crypto";
|
|
|
7
8
|
*
|
|
8
9
|
* @packageDocumentation
|
|
9
10
|
*/
|
|
10
|
-
/** Canonical version constant
|
|
11
|
-
const VERSION =
|
|
11
|
+
/** Canonical version constant, derived from `package.json` at build time. */
|
|
12
|
+
const VERSION = version;
|
|
12
13
|
/**
|
|
13
14
|
* Default Ollama base URL. Operators that run Ollama on a non-default
|
|
14
15
|
* port pass an explicit `baseUrl`.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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.6.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,CAAC,oBAAoB,IAAI;CACzB,CAAC,qBAAqB,KAAK;CAC3B,CAAC,0BAA0B,KAAK;CAChC,CAAC,2BAA2B,KAAK;CACjC,CAAC,UAAU,KAAK;CAChB,CAAC,aAAa,KAAK;CACnB,CAAC,kBAAkB,IAAI;CACvB,CAAC,cAAc,IAAI;CACnB,CAAC,qBAAqB,IAAI;CAC1B,CAAC,2BAA2B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G,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["VERSION: string","pkg.version","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, derived from `package.json` at build time. */\nimport pkg from '../package.json' with { type: 'json' };\n\nexport const VERSION: string = pkg.version;\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":";;;;;;;;;;;AAaA,MAAaA,UAAkBC;;;;;;;AAQ/B,MAAa,0BAA0B;;;;;;;AAQvC,MAAa,uBAAuB;;;;;;AAyDpC,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAkB,OAAO;CACzB,YACE,SACA,AAAgBC,YAChB,SACA;AACA,QAAM,SAAS,QAAQ;EAHP;;;;;;;;;;AAcpB,MAAaC,0BAAuD,IAAI,IAAI;CAC1E,CAAC,oBAAoB,IAAI;CACzB,CAAC,qBAAqB,KAAK;CAC3B,CAAC,0BAA0B,KAAK;CAChC,CAAC,2BAA2B,KAAK;CACjC,CAAC,UAAU,KAAK;CAChB,CAAC,aAAa,KAAK;CACnB,CAAC,kBAAkB,IAAI;CACvB,CAAC,cAAc,IAAI;CACnB,CAAC,qBAAqB,IAAI;CAC1B,CAAC,2BAA2B,IAAI;CACjC,CAAC;;;;;;;;AASF,SAAgB,qBAAqB,UAAiC,EAAE,EAAkB;AACxF,QAAO,IAAI,eAAe,QAAQ;;;;;;;AAQpC,IAAa,iBAAb,MAAwD;CACtD,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;C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I,MAAM,GAAG,IAAI"}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@graphorin/embedder-ollama\",\n \"version\": \"0.6.1\",\n \"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.\",\n \"license\": \"MIT\",\n \"author\": \"Oleksiy Stepurenko\",\n \"homepage\": \"https://github.com/o-stepper/graphorin/tree/main/packages/embedder-ollama\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/o-stepper/graphorin.git\",\n \"directory\": \"packages/embedder-ollama\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/o-stepper/graphorin/issues\"\n },\n \"keywords\": [\n \"graphorin\",\n \"ai\",\n \"agents\",\n \"framework\",\n \"embeddings\",\n \"ollama\",\n \"nomic-embed-text\",\n \"bge-m3\",\n \"local-first\"\n ],\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"CHANGELOG.md\",\n \"LICENSE\"\n ],\n \"scripts\": {\n \"build\": \"tsdown\",\n \"typecheck\": \"tsc --noEmit && tsc -p tsconfig.tests.json\",\n \"test\": \"vitest run\",\n \"lint\": \"biome check .\",\n \"clean\": \"rimraf dist .turbo *.tsbuildinfo\"\n },\n \"dependencies\": {\n \"@graphorin/core\": \"workspace:*\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"devDependencies\": {\n \"@graphorin/store-sqlite\": \"workspace:*\"\n }\n}\n"],"mappings":";cAEa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphorin/embedder-ollama",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oleksiy Stepurenko",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@graphorin/core": "0.6.
|
|
48
|
+
"@graphorin/core": "0.6.1"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public",
|
|
52
52
|
"provenance": true
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@graphorin/store-sqlite": "0.6.
|
|
55
|
+
"@graphorin/store-sqlite": "0.6.1"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|