@utaba/deep-memory-embeddings-openai 0.16.0 → 0.18.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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +136 -0
  3. package/package.json +4 -5
package/LICENSE CHANGED
@@ -175,7 +175,7 @@
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
177
 
178
- Copyright 2024 Utaba AI Ltd
178
+ Copyright 2024 Tim Wheeler
179
179
 
180
180
  Licensed under the Apache License, Version 2.0 (the "License");
181
181
  you may not use this file except in compliance with the License.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @utaba/deep-memory-embeddings-openai
2
+
3
+ OpenAI-compatible embeddings provider for [@utaba/deep-memory](https://www.npmjs.com/package/@utaba/deep-memory). Works with any server that implements the [OpenAI Embeddings API](https://platform.openai.com/docs/api-reference/embeddings) — including vLLM, OpenAI, Azure OpenAI, Ollama, HuggingFace TEI, and LiteLLM.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @utaba/deep-memory @utaba/deep-memory-embeddings-openai
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { DeepMemory } from '@utaba/deep-memory';
15
+ import { OpenAIEmbeddingProvider } from '@utaba/deep-memory-embeddings-openai';
16
+
17
+ const embeddings = new OpenAIEmbeddingProvider({
18
+ baseUrl: 'http://localhost:8010',
19
+ model: 'Qwen/Qwen3-Embedding-8B',
20
+ });
21
+
22
+ const dm = new DeepMemory({
23
+ embeddingProvider: embeddings,
24
+ });
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ | Option | Type | Default | Description |
30
+ |--------|------|---------|-------------|
31
+ | `baseUrl` | `string` | *required* | Base URL of the embeddings API (e.g. `http://localhost:8010`) |
32
+ | `model` | `string` | *required* | Model identifier sent in API requests |
33
+ | `apiKey` | `string` | `undefined` | Bearer token for authenticated endpoints. Not needed for local servers. |
34
+ | `dimensions` | `number` | auto-detected | Embedding vector dimensionality. Auto-detected on the first `embed()` call if omitted. |
35
+ | `timeoutMs` | `number` | `30000` | Request timeout in milliseconds |
36
+ | `maxBatchSize` | `number` | `64` | Maximum number of texts per batch request. Larger batches are automatically chunked. |
37
+
38
+ ## What It Enables
39
+
40
+ Without an `EmbeddingProvider`, deep-memory falls back to string similarity (Jaro-Winkler) for vocabulary deduplication and does not support semantic search. With this provider configured:
41
+
42
+ - **`searchByConcept()`** — semantic search across entities using vector similarity
43
+ - **Vocabulary deduplication** — detect near-duplicate entity types and labels using embeddings instead of string matching
44
+ - **Embedding storage** — vectors are stored alongside entities for fast retrieval
45
+
46
+ ## API
47
+
48
+ ### `embed(text: string): Promise<number[]>`
49
+
50
+ Generate a single embedding vector.
51
+
52
+ ### `embedBatch(texts: string[]): Promise<number[][]>`
53
+
54
+ Generate embeddings for multiple texts. Automatically chunks requests that exceed `maxBatchSize`. Results are returned in the same order as the input.
55
+
56
+ ### `dimensions(): number`
57
+
58
+ Returns the dimensionality of the embedding vectors. Throws if called before the first `embed()` call and `dimensions` was not set in config.
59
+
60
+ ### `modelId(): string`
61
+
62
+ Returns the model identifier from config. Stored alongside embeddings for compatibility tracking.
63
+
64
+ ### `similarity(a: number[], b: number[]): number`
65
+
66
+ Computes cosine similarity between two vectors. Returns a value between -1 and 1.
67
+
68
+ ## Backend Examples
69
+
70
+ ### vLLM (local GPU)
71
+
72
+ ```typescript
73
+ const embeddings = new OpenAIEmbeddingProvider({
74
+ baseUrl: 'http://localhost:8010',
75
+ model: 'Qwen/Qwen3-Embedding-8B',
76
+ });
77
+ ```
78
+
79
+ See the repo's `docker-compose.yml` for a ready-to-use vLLM container serving Qwen3-Embedding-8B on port 8010.
80
+
81
+ ### OpenAI
82
+
83
+ ```typescript
84
+ const embeddings = new OpenAIEmbeddingProvider({
85
+ baseUrl: 'https://api.openai.com',
86
+ model: 'text-embedding-3-small',
87
+ apiKey: process.env.OPENAI_API_KEY,
88
+ dimensions: 1536,
89
+ });
90
+ ```
91
+
92
+ ### Ollama
93
+
94
+ ```typescript
95
+ const embeddings = new OpenAIEmbeddingProvider({
96
+ baseUrl: 'http://localhost:11434',
97
+ model: 'nomic-embed-text',
98
+ });
99
+ ```
100
+
101
+ ### Azure OpenAI
102
+
103
+ ```typescript
104
+ const embeddings = new OpenAIEmbeddingProvider({
105
+ baseUrl: 'https://<resource>.openai.azure.com/openai/deployments/<deployment>',
106
+ model: 'text-embedding-3-small',
107
+ apiKey: process.env.AZURE_OPENAI_KEY,
108
+ });
109
+ ```
110
+
111
+ ## Error Handling
112
+
113
+ All errors thrown are `ProviderError` instances from `@utaba/deep-memory`, with a `suggestion` property containing actionable guidance:
114
+
115
+ ```typescript
116
+ try {
117
+ await embeddings.embed('test');
118
+ } catch (error) {
119
+ if (error instanceof ProviderError) {
120
+ console.error(error.message); // what went wrong
121
+ console.error(error.suggestion); // how to fix it
122
+ }
123
+ }
124
+ ```
125
+
126
+ Common error scenarios:
127
+ - **Connection refused** — server not running at `baseUrl`
128
+ - **Timeout** — request exceeded `timeoutMs`; increase timeout or reduce batch size
129
+ - **401 Unauthorized** — missing or invalid `apiKey`
130
+ - **Empty response** — model loaded but returned no embeddings
131
+
132
+ ## Zero Runtime Dependencies
133
+
134
+ This package uses the built-in `fetch` API and has no runtime dependencies beyond the peer dependency on `@utaba/deep-memory`. Supported on Node.js 22 and 24.
135
+ </content>
136
+ </invoke>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utaba/deep-memory-embeddings-openai",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "OpenAI-compatible embeddings provider for @utaba/deep-memory",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -24,10 +24,9 @@
24
24
  "README.md"
25
25
  ],
26
26
  "engines": {
27
- "node": ">=18"
27
+ "node": ">=22"
28
28
  },
29
29
  "license": "Apache-2.0",
30
- "homepage": "https://utaba.ai",
31
30
  "repository": {
32
31
  "type": "git",
33
32
  "url": "https://github.com/TjWheeler/deep-memory.git",
@@ -52,7 +51,7 @@
52
51
  "agents"
53
52
  ],
54
53
  "dependencies": {
55
- "@utaba/deep-memory": "0.16.0"
54
+ "@utaba/deep-memory": "0.18.0"
56
55
  },
57
56
  "devDependencies": {
58
57
  "@types/node": "^22.0.0",
@@ -61,7 +60,7 @@
61
60
  "vitest": "^4.1.2"
62
61
  },
63
62
  "peerDependencies": {
64
- "@utaba/deep-memory": "^0.16.0"
63
+ "@utaba/deep-memory": "^0.18.0"
65
64
  },
66
65
  "scripts": {
67
66
  "build": "tsup",