@h-ai/vecdb 1.0.0-beta.21 → 1.0.0-beta.23
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/README.en.md +4 -2
- package/README.ja.md +4 -2
- package/README.md +3 -1
- package/dist/index.js +33 -56
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -164,10 +164,12 @@ path: ./data/vecdb
|
|
|
164
164
|
operationLog:
|
|
165
165
|
read: false # collection.exists/info/list, vector.search/count
|
|
166
166
|
write: false # collection.create/drop, vector.insert/upsert/delete
|
|
167
|
-
maxLength: 1000 #
|
|
168
|
-
level: debug # info | debug | trace
|
|
167
|
+
maxLength: 1000 # Maximum summary length in characters. Use 0 to omit the summary.
|
|
168
|
+
level: debug # info | debug | trace, defaults to debug
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
Logs include the operation and a summary such as document counts, dimensions, topK, and whether a filter was supplied.
|
|
172
|
+
|
|
171
173
|
```ts
|
|
172
174
|
await vecdb.init({
|
|
173
175
|
type: 'lancedb',
|
package/README.ja.md
CHANGED
|
@@ -164,10 +164,12 @@ path: ./data/vecdb
|
|
|
164
164
|
operationLog:
|
|
165
165
|
read: false # collection.exists/info/list, vector.search/count
|
|
166
166
|
write: false # collection.create/drop, vector.insert/upsert/delete
|
|
167
|
-
maxLength: 1000 #
|
|
168
|
-
level: debug # info | debug | trace
|
|
167
|
+
maxLength: 1000 # 概要の最大文字数。0 で概要を省略します。
|
|
168
|
+
level: debug # info | debug | trace、既定値は debug
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
ログには操作名と件数、次元数、topK、フィルターの有無などの概要だけを記録します。
|
|
172
|
+
|
|
171
173
|
```ts
|
|
172
174
|
await vecdb.init({
|
|
173
175
|
type: 'lancedb',
|
package/README.md
CHANGED
|
@@ -164,10 +164,12 @@ path: ./data/vecdb
|
|
|
164
164
|
operationLog:
|
|
165
165
|
read: false # collection.exists/info/list, vector.search/count
|
|
166
166
|
write: false # collection.create/drop, vector.insert/upsert/delete
|
|
167
|
-
maxLength: 1000 #
|
|
167
|
+
maxLength: 1000 # 安全摘要的最大字符数,0 省略摘要
|
|
168
168
|
level: debug # info | debug | trace,默认 debug
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
日志只记录操作类型和条数、维度、topK、是否有过滤条件等摘要。
|
|
172
|
+
|
|
171
173
|
```ts
|
|
172
174
|
await vecdb.init({
|
|
173
175
|
type: 'lancedb',
|
package/dist/index.js
CHANGED
|
@@ -122,6 +122,7 @@ var DistanceMetricSchema = z.enum(["cosine", "euclidean", "dot"]).default("cosin
|
|
|
122
122
|
var VecdbOperationLogConfigSchema = z.object({
|
|
123
123
|
read: z.boolean().default(false),
|
|
124
124
|
write: z.boolean().default(false),
|
|
125
|
+
/** 安全摘要的最大字符数,0 省略摘要。 */
|
|
125
126
|
maxLength: z.number().int().min(0).default(1e3),
|
|
126
127
|
level: z.enum(["info", "debug", "trace"]).default("debug")
|
|
127
128
|
});
|
|
@@ -230,36 +231,14 @@ function vectorScoreFromDistance(distance, metric) {
|
|
|
230
231
|
return 1 / (1 + Math.exp(distance));
|
|
231
232
|
return 1 / (1 + Math.max(0, distance));
|
|
232
233
|
}
|
|
233
|
-
function
|
|
234
|
-
if (maxLength <= 0) {
|
|
235
|
-
return "";
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
const text = JSON.stringify(payload, (_key, value) => {
|
|
239
|
-
if (typeof value === "bigint") {
|
|
240
|
-
return value.toString();
|
|
241
|
-
}
|
|
242
|
-
if (typeof value === "function") {
|
|
243
|
-
return "[Function]";
|
|
244
|
-
}
|
|
245
|
-
return value;
|
|
246
|
-
});
|
|
247
|
-
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
|
|
248
|
-
} catch {
|
|
249
|
-
const text = String(payload);
|
|
250
|
-
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function logVecdbOperation(ctx, category, operation, payload) {
|
|
234
|
+
function logVecdbOperation(ctx, category, operation, summary = {}) {
|
|
254
235
|
const config = ctx.operationLog?.();
|
|
255
236
|
if (!config?.[category]) {
|
|
256
237
|
return;
|
|
257
238
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
payload: stringifyOperationPayload(payload, config.maxLength)
|
|
262
|
-
});
|
|
239
|
+
const fields = Object.entries(summary).filter(([, value]) => typeof value === "number" || typeof value === "boolean");
|
|
240
|
+
const payload = config.maxLength > 0 ? JSON.stringify(Object.fromEntries(fields)).slice(0, config.maxLength) : "";
|
|
241
|
+
ctx.logger[config.level]("VecDB operation started", { category, operation, payload });
|
|
263
242
|
}
|
|
264
243
|
function errorMsgFromCode(def, errorStr) {
|
|
265
244
|
switch (def) {
|
|
@@ -281,14 +260,17 @@ function errorMsgFromCode(def, errorStr) {
|
|
|
281
260
|
});
|
|
282
261
|
}
|
|
283
262
|
}
|
|
284
|
-
async function wrapOp(ctx, fn, errorDef, errorLabel
|
|
263
|
+
async function wrapOp(ctx, fn, errorDef, errorLabel) {
|
|
285
264
|
if (!ctx.isConnected()) {
|
|
286
265
|
return err(HaiVecdbError.NOT_INITIALIZED, vecdbM("vecdb_notInitialized"));
|
|
287
266
|
}
|
|
288
267
|
try {
|
|
289
268
|
return await fn();
|
|
290
269
|
} catch (error) {
|
|
291
|
-
ctx.logger.error(errorLabel, {
|
|
270
|
+
ctx.logger.error(errorLabel, {
|
|
271
|
+
errorCode: errorDef.code,
|
|
272
|
+
causeName: error instanceof Error ? error.name : void 0
|
|
273
|
+
});
|
|
292
274
|
return err(errorDef, errorMsgFromCode(errorDef, String(error)), error);
|
|
293
275
|
}
|
|
294
276
|
}
|
|
@@ -305,47 +287,43 @@ function createBaseCollectionOps(ctx, driver) {
|
|
|
305
287
|
})
|
|
306
288
|
);
|
|
307
289
|
}
|
|
308
|
-
logVecdbOperation(ctx, "write", "collection.create", {
|
|
290
|
+
logVecdbOperation(ctx, "write", "collection.create", { dimension: options.dimension });
|
|
309
291
|
return wrapOp(
|
|
310
292
|
ctx,
|
|
311
293
|
() => driver.create(name, options),
|
|
312
294
|
HaiVecdbError.QUERY_FAILED,
|
|
313
|
-
"Failed to create collection"
|
|
314
|
-
{ name }
|
|
295
|
+
"Failed to create collection"
|
|
315
296
|
);
|
|
316
297
|
},
|
|
317
298
|
drop: (name) => {
|
|
318
|
-
logVecdbOperation(ctx, "write", "collection.drop"
|
|
299
|
+
logVecdbOperation(ctx, "write", "collection.drop");
|
|
319
300
|
return wrapOp(
|
|
320
301
|
ctx,
|
|
321
302
|
() => driver.drop(name),
|
|
322
303
|
HaiVecdbError.DELETE_FAILED,
|
|
323
|
-
"Failed to drop collection"
|
|
324
|
-
{ name }
|
|
304
|
+
"Failed to drop collection"
|
|
325
305
|
);
|
|
326
306
|
},
|
|
327
307
|
exists: (name) => {
|
|
328
|
-
logVecdbOperation(ctx, "read", "collection.exists"
|
|
308
|
+
logVecdbOperation(ctx, "read", "collection.exists");
|
|
329
309
|
return wrapOp(
|
|
330
310
|
ctx,
|
|
331
311
|
() => driver.exists(name),
|
|
332
312
|
HaiVecdbError.QUERY_FAILED,
|
|
333
|
-
"Failed to check collection"
|
|
334
|
-
{ name }
|
|
313
|
+
"Failed to check collection"
|
|
335
314
|
);
|
|
336
315
|
},
|
|
337
316
|
info: (name) => {
|
|
338
|
-
logVecdbOperation(ctx, "read", "collection.info"
|
|
317
|
+
logVecdbOperation(ctx, "read", "collection.info");
|
|
339
318
|
return wrapOp(
|
|
340
319
|
ctx,
|
|
341
320
|
() => driver.info(name),
|
|
342
321
|
HaiVecdbError.QUERY_FAILED,
|
|
343
|
-
"Failed to get collection info"
|
|
344
|
-
{ name }
|
|
322
|
+
"Failed to get collection info"
|
|
345
323
|
);
|
|
346
324
|
},
|
|
347
325
|
list: () => {
|
|
348
|
-
logVecdbOperation(ctx, "read", "collection.list"
|
|
326
|
+
logVecdbOperation(ctx, "read", "collection.list");
|
|
349
327
|
return wrapOp(
|
|
350
328
|
ctx,
|
|
351
329
|
() => driver.list(),
|
|
@@ -358,53 +336,52 @@ function createBaseCollectionOps(ctx, driver) {
|
|
|
358
336
|
function createBaseVectorOps(ctx, driver) {
|
|
359
337
|
return {
|
|
360
338
|
insert: (collection, documents) => {
|
|
361
|
-
logVecdbOperation(ctx, "write", "vector.insert", {
|
|
339
|
+
logVecdbOperation(ctx, "write", "vector.insert", { count: documents?.length, dimension: documents?.[0]?.vector?.length });
|
|
362
340
|
return wrapOp(
|
|
363
341
|
ctx,
|
|
364
342
|
() => documents.length === 0 ? Promise.resolve(ok(void 0)) : driver.insert(collection, documents),
|
|
365
343
|
HaiVecdbError.INSERT_FAILED,
|
|
366
|
-
"Failed to insert vectors"
|
|
367
|
-
{ collection }
|
|
344
|
+
"Failed to insert vectors"
|
|
368
345
|
);
|
|
369
346
|
},
|
|
370
347
|
upsert: (collection, documents) => {
|
|
371
|
-
logVecdbOperation(ctx, "write", "vector.upsert", {
|
|
348
|
+
logVecdbOperation(ctx, "write", "vector.upsert", { count: documents?.length, dimension: documents?.[0]?.vector?.length });
|
|
372
349
|
return wrapOp(
|
|
373
350
|
ctx,
|
|
374
351
|
() => documents.length === 0 ? Promise.resolve(ok(void 0)) : driver.upsert(collection, documents),
|
|
375
352
|
HaiVecdbError.UPDATE_FAILED,
|
|
376
|
-
"Failed to upsert vectors"
|
|
377
|
-
{ collection }
|
|
353
|
+
"Failed to upsert vectors"
|
|
378
354
|
);
|
|
379
355
|
},
|
|
380
356
|
delete: (collection, ids) => {
|
|
381
|
-
logVecdbOperation(ctx, "write", "vector.delete", {
|
|
357
|
+
logVecdbOperation(ctx, "write", "vector.delete", { count: ids?.length });
|
|
382
358
|
return wrapOp(
|
|
383
359
|
ctx,
|
|
384
360
|
() => ids.length === 0 ? Promise.resolve(ok(void 0)) : driver.delete(collection, ids),
|
|
385
361
|
HaiVecdbError.DELETE_FAILED,
|
|
386
|
-
"Failed to delete vectors"
|
|
387
|
-
{ collection }
|
|
362
|
+
"Failed to delete vectors"
|
|
388
363
|
);
|
|
389
364
|
},
|
|
390
365
|
search: (collection, vector, options) => {
|
|
391
|
-
logVecdbOperation(ctx, "read", "vector.search", {
|
|
366
|
+
logVecdbOperation(ctx, "read", "vector.search", {
|
|
367
|
+
dimension: vector?.length,
|
|
368
|
+
topK: options?.topK,
|
|
369
|
+
hasFilter: Boolean(options?.filter)
|
|
370
|
+
});
|
|
392
371
|
return wrapOp(
|
|
393
372
|
ctx,
|
|
394
373
|
() => driver.search(collection, vector, options),
|
|
395
374
|
HaiVecdbError.QUERY_FAILED,
|
|
396
|
-
"Failed to search vectors"
|
|
397
|
-
{ collection }
|
|
375
|
+
"Failed to search vectors"
|
|
398
376
|
);
|
|
399
377
|
},
|
|
400
378
|
count: (collection) => {
|
|
401
|
-
logVecdbOperation(ctx, "read", "vector.count"
|
|
379
|
+
logVecdbOperation(ctx, "read", "vector.count");
|
|
402
380
|
return wrapOp(
|
|
403
381
|
ctx,
|
|
404
382
|
() => driver.count(collection),
|
|
405
383
|
HaiVecdbError.QUERY_FAILED,
|
|
406
|
-
"Failed to count vectors"
|
|
407
|
-
{ collection }
|
|
384
|
+
"Failed to count vectors"
|
|
408
385
|
);
|
|
409
386
|
}
|
|
410
387
|
};
|