@upstash/vector 1.2.0 → 1.2.2
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.md +16 -0
- package/dist/{chunk-4AKSNQD7.mjs → chunk-MQ3XJEJ2.mjs} +212 -126
- package/dist/cloudflare.d.mts +10 -3
- package/dist/cloudflare.d.ts +10 -3
- package/dist/cloudflare.js +223 -127
- package/dist/cloudflare.mjs +15 -3
- package/dist/nodejs.d.mts +10 -3
- package/dist/nodejs.d.ts +10 -3
- package/dist/nodejs.js +224 -126
- package/dist/nodejs.mjs +16 -2
- package/dist/{vector-FeePts30.d.mts → vector-7jBuY6ad.d.mts} +149 -52
- package/dist/{vector-FeePts30.d.ts → vector-7jBuY6ad.d.ts} +149 -52
- package/package.json +1 -1
package/dist/cloudflare.js
CHANGED
|
@@ -60,13 +60,15 @@ var HttpClient = class {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
async request(req) {
|
|
63
|
+
const signal = this.options.signal;
|
|
64
|
+
const isSignalFunction = typeof signal === "function";
|
|
63
65
|
const requestOptions = {
|
|
64
66
|
cache: this.options.cache,
|
|
65
67
|
method: "POST",
|
|
66
68
|
headers: this.headers,
|
|
67
69
|
body: JSON.stringify(req.body),
|
|
68
70
|
keepalive: true,
|
|
69
|
-
signal:
|
|
71
|
+
signal: isSignalFunction ? signal() : signal
|
|
70
72
|
};
|
|
71
73
|
let res = null;
|
|
72
74
|
let error = null;
|
|
@@ -75,13 +77,15 @@ var HttpClient = class {
|
|
|
75
77
|
res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
|
|
76
78
|
break;
|
|
77
79
|
} catch (error_) {
|
|
78
|
-
if (
|
|
80
|
+
if (requestOptions.signal?.aborted && isSignalFunction) {
|
|
81
|
+
throw error_;
|
|
82
|
+
} else if (requestOptions.signal?.aborted) {
|
|
79
83
|
const myBlob = new Blob([
|
|
80
|
-
JSON.stringify({ result:
|
|
84
|
+
JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
|
|
81
85
|
]);
|
|
82
86
|
const myOptions = {
|
|
83
87
|
status: 200,
|
|
84
|
-
statusText:
|
|
88
|
+
statusText: requestOptions.signal.reason ?? "Aborted"
|
|
85
89
|
};
|
|
86
90
|
res = new Response(myBlob, myOptions);
|
|
87
91
|
break;
|
|
@@ -131,18 +135,28 @@ var Command = class {
|
|
|
131
135
|
|
|
132
136
|
// src/commands/client/delete/index.ts
|
|
133
137
|
var DeleteCommand = class extends Command {
|
|
134
|
-
constructor(
|
|
138
|
+
constructor(payload, options) {
|
|
135
139
|
let endpoint = "delete";
|
|
136
140
|
if (options?.namespace) {
|
|
137
141
|
endpoint = `${endpoint}/${options.namespace}`;
|
|
138
142
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
if (typeof payload === "string" || typeof payload === "number") {
|
|
144
|
+
super(
|
|
145
|
+
{
|
|
146
|
+
ids: [payload]
|
|
147
|
+
},
|
|
148
|
+
endpoint
|
|
149
|
+
);
|
|
150
|
+
} else if (Array.isArray(payload)) {
|
|
151
|
+
super(
|
|
152
|
+
{
|
|
153
|
+
ids: payload
|
|
154
|
+
},
|
|
155
|
+
endpoint
|
|
156
|
+
);
|
|
157
|
+
} else if (typeof payload === "object") {
|
|
158
|
+
super(payload, endpoint);
|
|
144
159
|
}
|
|
145
|
-
super(finalArr, endpoint);
|
|
146
160
|
}
|
|
147
161
|
};
|
|
148
162
|
|
|
@@ -214,13 +228,19 @@ var isVectorPayload = (payload) => {
|
|
|
214
228
|
|
|
215
229
|
// src/commands/client/fetch/index.ts
|
|
216
230
|
var FetchCommand = class extends Command {
|
|
217
|
-
constructor([
|
|
231
|
+
constructor([payload, opts]) {
|
|
218
232
|
let endpoint = "fetch";
|
|
219
233
|
if (opts?.namespace) {
|
|
220
234
|
endpoint = `${endpoint}/${opts.namespace}`;
|
|
221
235
|
delete opts.namespace;
|
|
222
236
|
}
|
|
223
|
-
|
|
237
|
+
if (Array.isArray(payload)) {
|
|
238
|
+
super({ ids: payload, ...opts }, endpoint);
|
|
239
|
+
} else if (typeof payload === "object") {
|
|
240
|
+
super({ ...payload, ...opts }, endpoint);
|
|
241
|
+
} else {
|
|
242
|
+
throw new Error("Invalid payload");
|
|
243
|
+
}
|
|
224
244
|
}
|
|
225
245
|
};
|
|
226
246
|
|
|
@@ -256,6 +276,67 @@ var InfoCommand = class extends Command {
|
|
|
256
276
|
}
|
|
257
277
|
};
|
|
258
278
|
|
|
279
|
+
// src/commands/client/resumable-query/resume.ts
|
|
280
|
+
var ResumeQueryCommand = class extends Command {
|
|
281
|
+
constructor(payload) {
|
|
282
|
+
super(payload, "resumable-query-next");
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/commands/client/resumable-query/start.ts
|
|
287
|
+
var StartResumableQueryCommand = class extends Command {
|
|
288
|
+
constructor(payload, namespace) {
|
|
289
|
+
let endpoint = "resumable-query";
|
|
290
|
+
if ("data" in payload) {
|
|
291
|
+
endpoint = "resumable-query-data";
|
|
292
|
+
}
|
|
293
|
+
if (namespace) {
|
|
294
|
+
endpoint = `${endpoint}/${namespace}`;
|
|
295
|
+
}
|
|
296
|
+
super(payload, endpoint);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/commands/client/resumable-query/stop.ts
|
|
301
|
+
var StopResumableQueryCommand = class extends Command {
|
|
302
|
+
constructor(payload) {
|
|
303
|
+
super(payload, "resumable-query-end");
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// src/commands/client/resumable-query/index.ts
|
|
308
|
+
var ResumableQuery = class {
|
|
309
|
+
uuid;
|
|
310
|
+
start;
|
|
311
|
+
fetchNext;
|
|
312
|
+
stop;
|
|
313
|
+
constructor(payload, client, namespace) {
|
|
314
|
+
this.start = async () => {
|
|
315
|
+
const result = await new StartResumableQueryCommand(payload, namespace).exec(
|
|
316
|
+
client
|
|
317
|
+
);
|
|
318
|
+
this.uuid = result.uuid;
|
|
319
|
+
return result;
|
|
320
|
+
};
|
|
321
|
+
this.fetchNext = (additionalK) => {
|
|
322
|
+
if (!this.uuid) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
"The resumable query has already been stopped. Please start another resumable query."
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
return new ResumeQueryCommand({ uuid: this.uuid, additionalK }).exec(client);
|
|
328
|
+
};
|
|
329
|
+
this.stop = async () => {
|
|
330
|
+
if (!this.uuid) {
|
|
331
|
+
throw new Error("Resumable query has not been started. Call start() first.");
|
|
332
|
+
}
|
|
333
|
+
const result = await new StopResumableQueryCommand({ uuid: this.uuid }).exec(client);
|
|
334
|
+
this.uuid = "";
|
|
335
|
+
return result;
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
259
340
|
// src/commands/client/namespace/index.ts
|
|
260
341
|
var Namespace = class {
|
|
261
342
|
client;
|
|
@@ -323,19 +404,21 @@ var Namespace = class {
|
|
|
323
404
|
*/
|
|
324
405
|
update = (args) => new UpdateCommand(args, { namespace: this.namespace }).exec(this.client);
|
|
325
406
|
/**
|
|
326
|
-
*
|
|
327
|
-
*
|
|
407
|
+
* Fetches specific items from the index by their IDs or by an id prefix.
|
|
408
|
+
*
|
|
409
|
+
* Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
|
|
328
410
|
*
|
|
329
411
|
* @example
|
|
330
412
|
* ```js
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
413
|
+
* // Using ids
|
|
414
|
+
* await index.namespace("ns").fetch(["test-1", "test-2"], { includeMetadata: true });
|
|
415
|
+
*
|
|
416
|
+
* // Using id prefix
|
|
417
|
+
* await index.namespace("ns").fetch({ prefix: "test-" });
|
|
335
418
|
* ```
|
|
336
419
|
*
|
|
337
420
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
338
|
-
* @param {
|
|
421
|
+
* @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
|
|
339
422
|
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
340
423
|
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
341
424
|
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
@@ -376,34 +459,82 @@ var Namespace = class {
|
|
|
376
459
|
*/
|
|
377
460
|
query = (args) => new QueryCommand(args, { namespace: this.namespace }).exec(this.client);
|
|
378
461
|
/**
|
|
379
|
-
*
|
|
462
|
+
* Initializes a resumable query operation on the vector database.
|
|
463
|
+
* This method allows for querying large result sets in multiple chunks or implementing pagination.
|
|
380
464
|
*
|
|
465
|
+
* @template TMetadata
|
|
466
|
+
* @param {ResumableQueryPayload} args - The arguments for the resumable query.
|
|
467
|
+
* @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
|
|
468
|
+
* @param {number} args.topK - The number of top results to return in each fetch operation.
|
|
469
|
+
* @param {number[]} args.vector - The query vector used for similarity search.
|
|
470
|
+
* @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
|
|
471
|
+
* @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
|
|
472
|
+
* @param {Object} [options] - Additional options for the query.
|
|
473
|
+
* @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
|
|
381
474
|
* @example
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
475
|
+
* const { result, fetchNext, stop } = await index.namespace("ns").resumableQuery({
|
|
476
|
+
* maxIdle: 3600,
|
|
477
|
+
* topK: 50,
|
|
478
|
+
* vector: [0.1, 0.2, 0.3, ...],
|
|
479
|
+
* includeMetadata: true,
|
|
480
|
+
* includeVectors: true
|
|
481
|
+
* }, { namespace: 'my-namespace' });
|
|
386
482
|
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
483
|
+
* const firstBatch = await fetchNext(10);
|
|
484
|
+
* const secondBatch = await fetchNext(10);
|
|
485
|
+
* await stop(); // End the query session
|
|
389
486
|
*/
|
|
487
|
+
resumableQuery = async (args) => {
|
|
488
|
+
const resumableQuery = new ResumableQuery(args, this.client, this.namespace);
|
|
489
|
+
const initialQuery = await resumableQuery.start();
|
|
490
|
+
const { fetchNext, stop } = resumableQuery;
|
|
491
|
+
return { fetchNext, stop, result: initialQuery.scores };
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Deletes items from the index namespace by id, by id prefix, or by filter.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```js
|
|
498
|
+
* // Delete by id
|
|
499
|
+
* await index.namespace("ns").delete("test-id");
|
|
500
|
+
|
|
501
|
+
* // Delete by ids
|
|
502
|
+
* await index.namespace("ns").delete(["test-id1", "test-id2"]);
|
|
503
|
+
|
|
504
|
+
* // Delete by id prefix
|
|
505
|
+
* await index.namespace("ns").delete({ prefix: "test-" });
|
|
506
|
+
|
|
507
|
+
* // Delete by filter
|
|
508
|
+
* await index.namespace("ns").delete({ filter: "age >= 23" });
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
|
|
512
|
+
* @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
|
|
513
|
+
*/
|
|
390
514
|
delete = (args) => new DeleteCommand(args, { namespace: this.namespace }).exec(this.client);
|
|
391
515
|
/**
|
|
392
|
-
* Retrieves a range of items from the index.
|
|
516
|
+
* Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
|
|
517
|
+
* Returns items in batches with a cursor for pagination.
|
|
393
518
|
*
|
|
394
519
|
* @example
|
|
395
520
|
* ```js
|
|
396
|
-
* const
|
|
397
|
-
* cursor: 0,
|
|
521
|
+
* const args = {
|
|
398
522
|
* limit: 10,
|
|
399
523
|
* includeVectors: true,
|
|
400
524
|
* includeMetadata: false
|
|
401
525
|
* };
|
|
402
|
-
*
|
|
403
|
-
*
|
|
526
|
+
* await index.namespace("ns").range(args);
|
|
527
|
+
*
|
|
528
|
+
* // Use the cursor to get the next page of results
|
|
529
|
+
* const nextPage = await index.namespace("ns").range({
|
|
530
|
+
* // You have to pass the arguments from the first call
|
|
531
|
+
* ...args,
|
|
532
|
+
* cursor: rangeResult.nextCursor,
|
|
533
|
+
* });
|
|
404
534
|
* ```
|
|
405
535
|
*
|
|
406
536
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
537
|
+
* @param {string} [args.prefix] - The prefix of the items to be fetched.
|
|
407
538
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
408
539
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
409
540
|
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
@@ -437,67 +568,6 @@ var UpdateCommand = class extends Command {
|
|
|
437
568
|
}
|
|
438
569
|
};
|
|
439
570
|
|
|
440
|
-
// src/commands/client/resumable-query/resume.ts
|
|
441
|
-
var ResumeQueryCommand = class extends Command {
|
|
442
|
-
constructor(payload) {
|
|
443
|
-
super(payload, "resumable-query-next");
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
// src/commands/client/resumable-query/start.ts
|
|
448
|
-
var StartResumableQueryCommand = class extends Command {
|
|
449
|
-
constructor(payload, namespace) {
|
|
450
|
-
let endpoint = "resumable-query";
|
|
451
|
-
if ("data" in payload) {
|
|
452
|
-
endpoint = "resumable-query-data";
|
|
453
|
-
}
|
|
454
|
-
if (namespace) {
|
|
455
|
-
endpoint = `${endpoint}/${namespace}`;
|
|
456
|
-
}
|
|
457
|
-
super(payload, endpoint);
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// src/commands/client/resumable-query/stop.ts
|
|
462
|
-
var StopResumableQueryCommand = class extends Command {
|
|
463
|
-
constructor(payload) {
|
|
464
|
-
super(payload, "resumable-query-end");
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// src/commands/client/resumable-query/index.ts
|
|
469
|
-
var ResumableQuery = class {
|
|
470
|
-
uuid;
|
|
471
|
-
start;
|
|
472
|
-
fetchNext;
|
|
473
|
-
stop;
|
|
474
|
-
constructor(payload, client, namespace) {
|
|
475
|
-
this.start = async () => {
|
|
476
|
-
const result = await new StartResumableQueryCommand(payload, namespace).exec(
|
|
477
|
-
client
|
|
478
|
-
);
|
|
479
|
-
this.uuid = result.uuid;
|
|
480
|
-
return result;
|
|
481
|
-
};
|
|
482
|
-
this.fetchNext = (additionalK) => {
|
|
483
|
-
if (!this.uuid) {
|
|
484
|
-
throw new Error(
|
|
485
|
-
"The resumable query has already been stopped. Please start another resumable query."
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
return new ResumeQueryCommand({ uuid: this.uuid, additionalK }).exec(client);
|
|
489
|
-
};
|
|
490
|
-
this.stop = async () => {
|
|
491
|
-
if (!this.uuid) {
|
|
492
|
-
throw new Error("Resumable query has not been started. Call start() first.");
|
|
493
|
-
}
|
|
494
|
-
const result = await new StopResumableQueryCommand({ uuid: this.uuid }).exec(client);
|
|
495
|
-
this.uuid = "";
|
|
496
|
-
return result;
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
|
|
501
571
|
// src/commands/management/namespaces/list/index.ts
|
|
502
572
|
var ListNamespacesCommand = class extends Command {
|
|
503
573
|
constructor() {
|
|
@@ -533,17 +603,26 @@ var Index = class {
|
|
|
533
603
|
}
|
|
534
604
|
namespace = (namespace) => new Namespace(this.client, namespace);
|
|
535
605
|
/**
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
606
|
+
* Deletes items from the index by id, by id prefix, or by filter.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```js
|
|
610
|
+
* // Delete by id
|
|
611
|
+
* await index.delete("test-id");
|
|
612
|
+
|
|
613
|
+
* // Delete by ids
|
|
614
|
+
* await index.delete(["test-id1", "test-id2"]);
|
|
615
|
+
|
|
616
|
+
* // Delete by id prefix
|
|
617
|
+
* await index.delete({ prefix: "test-" });
|
|
618
|
+
|
|
619
|
+
* // Delete by filter
|
|
620
|
+
* await index.delete({ filter: "age >= 23" });
|
|
621
|
+
* ```
|
|
622
|
+
*
|
|
623
|
+
* @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
|
|
624
|
+
* @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
|
|
625
|
+
*/
|
|
547
626
|
delete = (args, options) => new DeleteCommand(args, options).exec(this.client);
|
|
548
627
|
/**
|
|
549
628
|
* Queries an index with specified parameters.
|
|
@@ -685,23 +764,25 @@ var Index = class {
|
|
|
685
764
|
*/
|
|
686
765
|
update = (args, options) => new UpdateCommand(args, options).exec(this.client);
|
|
687
766
|
/**
|
|
688
|
-
*
|
|
689
|
-
*
|
|
767
|
+
* Fetches specific items from the index by their IDs or by an id prefix.
|
|
768
|
+
*
|
|
769
|
+
* Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
|
|
690
770
|
*
|
|
691
771
|
* @example
|
|
692
772
|
* ```js
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
773
|
+
* // Using ids
|
|
774
|
+
* await index.fetch(["test-1", "test-2"], { includeMetadata: true });
|
|
775
|
+
*
|
|
776
|
+
* // Using id prefix
|
|
777
|
+
* await index.fetch({ prefix: "test-" });
|
|
697
778
|
* ```
|
|
698
779
|
*
|
|
699
780
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
700
|
-
* @param {
|
|
701
|
-
* @param {FetchCommandOptions} args - Options for the fetch operation.
|
|
702
|
-
* @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
703
|
-
* @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
704
|
-
* @param {
|
|
781
|
+
* @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
|
|
782
|
+
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
783
|
+
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
784
|
+
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
785
|
+
* @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
|
|
705
786
|
*
|
|
706
787
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
707
788
|
*/
|
|
@@ -737,27 +818,28 @@ var Index = class {
|
|
|
737
818
|
*/
|
|
738
819
|
reset = (options) => new ResetCommand(options).exec(this.client);
|
|
739
820
|
/**
|
|
740
|
-
* Retrieves a range of items from the index.
|
|
821
|
+
* Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
|
|
822
|
+
* Returns items in batches with a cursor for pagination.
|
|
741
823
|
*
|
|
742
824
|
* @example
|
|
743
825
|
* ```js
|
|
744
|
-
* const
|
|
745
|
-
* cursor: 0,
|
|
826
|
+
* const args = {
|
|
746
827
|
* limit: 10,
|
|
747
828
|
* includeVectors: true,
|
|
748
829
|
* includeMetadata: false
|
|
749
830
|
* };
|
|
750
|
-
*
|
|
751
|
-
* console.log(rangeResults); // Outputs the result of the range operation
|
|
752
|
-
* ```
|
|
831
|
+
* await index.range(args);
|
|
753
832
|
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
833
|
+
* // Use the cursor to get the next page of results
|
|
834
|
+
* const nextPage = await index.range({
|
|
835
|
+
* // You have to pass the arguments from the first call
|
|
836
|
+
* ...args,
|
|
837
|
+
* cursor: rangeResult.nextCursor,
|
|
838
|
+
* });
|
|
758
839
|
* ```
|
|
759
840
|
*
|
|
760
841
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
842
|
+
* @param {string} [args.prefix] - The prefix of the items to be fetched.
|
|
761
843
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
762
844
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
763
845
|
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
@@ -805,6 +887,9 @@ var Index = class {
|
|
|
805
887
|
deleteNamespace = (namespace) => new DeleteNamespaceCommand(namespace).exec(this.client);
|
|
806
888
|
};
|
|
807
889
|
|
|
890
|
+
// version.ts
|
|
891
|
+
var VERSION = "v1.2.2";
|
|
892
|
+
|
|
808
893
|
// src/platforms/cloudflare.ts
|
|
809
894
|
var Index2 = class _Index extends Index {
|
|
810
895
|
/**
|
|
@@ -839,10 +924,15 @@ var Index2 = class _Index extends Index {
|
|
|
839
924
|
if (token.startsWith(" ") || token.endsWith(" ") || /\r|\n/.test(token)) {
|
|
840
925
|
console.warn("The vector token contains whitespace or newline, which can cause errors!");
|
|
841
926
|
}
|
|
927
|
+
const enableTelemetry = safeProcess.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
|
|
928
|
+
const telemetryHeaders = enableTelemetry ? {
|
|
929
|
+
"Upstash-Telemetry-Sdk": `upstash-vector-js@${VERSION}`,
|
|
930
|
+
"Upstash-Telemetry-Platform": "cloudflare"
|
|
931
|
+
} : {};
|
|
842
932
|
const client = new HttpClient({
|
|
843
933
|
baseUrl: url,
|
|
844
934
|
retry: config?.retry,
|
|
845
|
-
headers: { authorization: `Bearer ${token}
|
|
935
|
+
headers: { authorization: `Bearer ${token}`, ...telemetryHeaders },
|
|
846
936
|
signal: config?.signal,
|
|
847
937
|
cache: config?.cache === false ? void 0 : config?.cache
|
|
848
938
|
});
|
|
@@ -875,7 +965,13 @@ var Index2 = class _Index extends Index {
|
|
|
875
965
|
);
|
|
876
966
|
}
|
|
877
967
|
}
|
|
878
|
-
return new _Index({
|
|
968
|
+
return new _Index({
|
|
969
|
+
// @ts-expect-error We don't need to type this in the cf env type
|
|
970
|
+
enableTelemetry: env?.UPSTASH_DISABLE_TELEMETRY ? false : void 0,
|
|
971
|
+
...config,
|
|
972
|
+
url,
|
|
973
|
+
token
|
|
974
|
+
});
|
|
879
975
|
}
|
|
880
976
|
};
|
|
881
977
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cloudflare.mjs
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
HttpClient,
|
|
4
4
|
Index,
|
|
5
5
|
QueryMode,
|
|
6
|
+
VERSION,
|
|
6
7
|
WeightingStrategy
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MQ3XJEJ2.mjs";
|
|
8
9
|
|
|
9
10
|
// src/platforms/cloudflare.ts
|
|
10
11
|
var Index2 = class _Index extends Index {
|
|
@@ -40,10 +41,15 @@ var Index2 = class _Index extends Index {
|
|
|
40
41
|
if (token.startsWith(" ") || token.endsWith(" ") || /\r|\n/.test(token)) {
|
|
41
42
|
console.warn("The vector token contains whitespace or newline, which can cause errors!");
|
|
42
43
|
}
|
|
44
|
+
const enableTelemetry = safeProcess.UPSTASH_DISABLE_TELEMETRY ? false : config?.enableTelemetry ?? true;
|
|
45
|
+
const telemetryHeaders = enableTelemetry ? {
|
|
46
|
+
"Upstash-Telemetry-Sdk": `upstash-vector-js@${VERSION}`,
|
|
47
|
+
"Upstash-Telemetry-Platform": "cloudflare"
|
|
48
|
+
} : {};
|
|
43
49
|
const client = new HttpClient({
|
|
44
50
|
baseUrl: url,
|
|
45
51
|
retry: config?.retry,
|
|
46
|
-
headers: { authorization: `Bearer ${token}
|
|
52
|
+
headers: { authorization: `Bearer ${token}`, ...telemetryHeaders },
|
|
47
53
|
signal: config?.signal,
|
|
48
54
|
cache: config?.cache === false ? void 0 : config?.cache
|
|
49
55
|
});
|
|
@@ -76,7 +82,13 @@ var Index2 = class _Index extends Index {
|
|
|
76
82
|
);
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
|
-
return new _Index({
|
|
85
|
+
return new _Index({
|
|
86
|
+
// @ts-expect-error We don't need to type this in the cf env type
|
|
87
|
+
enableTelemetry: env?.UPSTASH_DISABLE_TELEMETRY ? false : void 0,
|
|
88
|
+
...config,
|
|
89
|
+
url,
|
|
90
|
+
token
|
|
91
|
+
});
|
|
80
92
|
}
|
|
81
93
|
};
|
|
82
94
|
export {
|
package/dist/nodejs.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-
|
|
2
|
-
export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-
|
|
1
|
+
import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-7jBuY6ad.mjs';
|
|
2
|
+
export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-7jBuY6ad.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Connection credentials for upstash vector.
|
|
@@ -18,7 +18,14 @@ type IndexConfig = {
|
|
|
18
18
|
* The signal will allow aborting requests on the fly.
|
|
19
19
|
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
20
|
*/
|
|
21
|
-
signal?:
|
|
21
|
+
signal?: HttpClientConfig["signal"];
|
|
22
|
+
/**
|
|
23
|
+
* Enable telemetry to help us improve the SDK.
|
|
24
|
+
* The sdk will send the sdk version, platform and node version as telemetry headers.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
enableTelemetry?: boolean;
|
|
22
29
|
} & RequesterConfig;
|
|
23
30
|
/**
|
|
24
31
|
* Serverless vector client for upstash.
|
package/dist/nodejs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-
|
|
2
|
-
export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-
|
|
1
|
+
import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-7jBuY6ad.js';
|
|
2
|
+
export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-7jBuY6ad.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Connection credentials for upstash vector.
|
|
@@ -18,7 +18,14 @@ type IndexConfig = {
|
|
|
18
18
|
* The signal will allow aborting requests on the fly.
|
|
19
19
|
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
20
|
*/
|
|
21
|
-
signal?:
|
|
21
|
+
signal?: HttpClientConfig["signal"];
|
|
22
|
+
/**
|
|
23
|
+
* Enable telemetry to help us improve the SDK.
|
|
24
|
+
* The sdk will send the sdk version, platform and node version as telemetry headers.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
enableTelemetry?: boolean;
|
|
22
29
|
} & RequesterConfig;
|
|
23
30
|
/**
|
|
24
31
|
* Serverless vector client for upstash.
|