@openclaw/memory-lancedb 2026.7.2-beta.2 → 2026.7.2-beta.3
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/dist/index.js +63 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -137,21 +137,73 @@ var OpenAiCompatibleEmbeddings = class {
|
|
|
137
137
|
}));
|
|
138
138
|
}
|
|
139
139
|
async embed(text, options) {
|
|
140
|
+
const dimensions = this.dimensions;
|
|
141
|
+
const startedAtMs = options?.timeoutMs && Number.isFinite(options.timeoutMs) ? Date.now() : null;
|
|
142
|
+
try {
|
|
143
|
+
return normalizeEmbeddingVector((await this.postEmbedding(text, {
|
|
144
|
+
includeDimensions: true,
|
|
145
|
+
options
|
|
146
|
+
})).data?.[0]?.embedding);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (typeof dimensions !== "number" || !isEmbeddingDimensionsRejectedError(error)) throw error;
|
|
149
|
+
}
|
|
150
|
+
const fallbackOptions = startedAtMs === null || options?.timeoutMs === void 0 ? options : { timeoutMs: Math.max(1, options.timeoutMs - (Date.now() - startedAtMs)) };
|
|
151
|
+
return truncateEmbeddingVector(normalizeEmbeddingVector((await this.postEmbedding(text, {
|
|
152
|
+
includeDimensions: false,
|
|
153
|
+
options: fallbackOptions
|
|
154
|
+
})).data?.[0]?.embedding), dimensions, this.model);
|
|
155
|
+
}
|
|
156
|
+
async postEmbedding(text, request) {
|
|
140
157
|
const params = {
|
|
141
158
|
model: this.model,
|
|
142
|
-
input: text
|
|
159
|
+
input: text,
|
|
160
|
+
...request.includeDimensions && typeof this.dimensions === "number" ? { dimensions: this.dimensions } : {}
|
|
143
161
|
};
|
|
144
|
-
if (this.dimensions) params.dimensions = this.dimensions;
|
|
145
162
|
ensureGlobalUndiciEnvProxyDispatcher();
|
|
146
|
-
return
|
|
163
|
+
return await (await this.clientPromise).post("/embeddings", {
|
|
147
164
|
body: params,
|
|
148
|
-
...options?.timeoutMs ? {
|
|
149
|
-
timeout: options.timeoutMs,
|
|
165
|
+
...request.options?.timeoutMs ? {
|
|
166
|
+
timeout: request.options.timeoutMs,
|
|
150
167
|
maxRetries: 0
|
|
151
168
|
} : {}
|
|
152
|
-
})
|
|
169
|
+
});
|
|
153
170
|
}
|
|
154
171
|
};
|
|
172
|
+
function isEmbeddingDimensionsRejectedError(error) {
|
|
173
|
+
const record = asOptionalRecord(error);
|
|
174
|
+
if (record?.status !== 400 && record?.status !== 422) return false;
|
|
175
|
+
const details = stringifyEmbeddingApiError(error).toLowerCase();
|
|
176
|
+
return /\bdimensions\b/.test(details) && isUnsupportedEmbeddingFieldError(details);
|
|
177
|
+
}
|
|
178
|
+
function isUnsupportedEmbeddingFieldError(details) {
|
|
179
|
+
if (/\b(?:parameter|field|argument)[_ -]value\b/.test(details)) return false;
|
|
180
|
+
return /\bextra[_ -]forbidden\b/.test(details) || /\bextra inputs? (?:are )?not permitted\b/.test(details) || /\bextra fields? (?:are )?not permitted\b/.test(details) || /\b(?:unknown|unrecognized|unexpected|unsupported)[_ -](?:request[_ -])?(?:parameter|field|argument)\b/.test(details);
|
|
181
|
+
}
|
|
182
|
+
function stringifyEmbeddingApiError(error) {
|
|
183
|
+
const record = asOptionalRecord(error);
|
|
184
|
+
const parts = error instanceof Error ? [error.message] : [];
|
|
185
|
+
for (const value of [
|
|
186
|
+
record?.code,
|
|
187
|
+
record?.type,
|
|
188
|
+
record?.param,
|
|
189
|
+
record?.error
|
|
190
|
+
]) {
|
|
191
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
192
|
+
parts.push(String(value));
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (value && typeof value === "object") try {
|
|
196
|
+
parts.push(JSON.stringify(value));
|
|
197
|
+
} catch {}
|
|
198
|
+
}
|
|
199
|
+
return parts.join("\n");
|
|
200
|
+
}
|
|
201
|
+
function truncateEmbeddingVector(embedding, dimensions, model) {
|
|
202
|
+
if (embedding.length < dimensions) throw new Error(`Embedding model ${model} returned ${embedding.length} dimensions, need at least ${dimensions} for local truncation`);
|
|
203
|
+
const truncated = embedding.slice(0, dimensions);
|
|
204
|
+
const magnitude = Math.sqrt(truncated.reduce((sum, value) => sum + value * value, 0));
|
|
205
|
+
return magnitude > 0 ? truncated.map((value) => value / magnitude) : truncated;
|
|
206
|
+
}
|
|
155
207
|
var ProviderAdapterEmbeddings = class {
|
|
156
208
|
constructor(api, embedding) {
|
|
157
209
|
this.api = api;
|
|
@@ -247,7 +299,11 @@ var MemoryRecallEmbeddingError = class extends Error {
|
|
|
247
299
|
this.name = "MemoryRecallEmbeddingError";
|
|
248
300
|
}
|
|
249
301
|
};
|
|
250
|
-
const testing = {
|
|
302
|
+
const testing = {
|
|
303
|
+
isEmbeddingDimensionsRejectedError,
|
|
304
|
+
runWithTimeout,
|
|
305
|
+
truncateEmbeddingVector
|
|
306
|
+
};
|
|
251
307
|
function createEmbeddings(api, cfg) {
|
|
252
308
|
const { provider, model, dimensions, apiKey, baseUrl } = cfg.embedding;
|
|
253
309
|
if (provider === "openai" && apiKey) return new OpenAiCompatibleEmbeddings(apiKey, model, baseUrl, dimensions);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/memory-lancedb",
|
|
3
|
-
"version": "2026.7.2-beta.
|
|
3
|
+
"version": "2026.7.2-beta.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@openclaw/memory-lancedb",
|
|
9
|
-
"version": "2026.7.2-beta.
|
|
9
|
+
"version": "2026.7.2-beta.3",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@lancedb/lancedb": "0.30.0",
|
|
12
12
|
"apache-arrow": "18.1.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/memory-lancedb",
|
|
3
|
-
"version": "2026.7.2-beta.
|
|
3
|
+
"version": "2026.7.2-beta.3",
|
|
4
4
|
"description": "OpenClaw LanceDB-backed long-term memory plugin with auto-recall, auto-capture, and vector search.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"minHostVersion": ">=2026.5.31"
|
|
27
27
|
},
|
|
28
28
|
"compat": {
|
|
29
|
-
"pluginApi": ">=2026.7.2-beta.
|
|
29
|
+
"pluginApi": ">=2026.7.2-beta.3"
|
|
30
30
|
},
|
|
31
31
|
"build": {
|
|
32
|
-
"openclawVersion": "2026.7.2-beta.
|
|
32
|
+
"openclawVersion": "2026.7.2-beta.3"
|
|
33
33
|
},
|
|
34
34
|
"release": {
|
|
35
35
|
"bundleRuntimeDependencies": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"README.md"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"openclaw": ">=2026.7.2-beta.
|
|
50
|
+
"openclaw": ">=2026.7.2-beta.3"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"openclaw": {
|