@upstash/vector 1.2.0 → 1.2.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.
@@ -71,10 +71,20 @@ declare class Command<TResult> {
71
71
  exec(client: Requester): Promise<TResult>;
72
72
  }
73
73
 
74
+ type IdsPayload = (number[] | string[]) | number | string;
75
+ type ObjectPayload = {
76
+ ids: number[] | string[];
77
+ } | {
78
+ prefix: string;
79
+ } | {
80
+ filter: string;
81
+ };
82
+ type DeleteCommandPayload = IdsPayload | ObjectPayload;
83
+
74
84
  declare class DeleteCommand extends Command<{
75
85
  deleted: number;
76
86
  }> {
77
- constructor(id: (number[] | string[]) | number | string, options?: {
87
+ constructor(payload: DeleteCommandPayload, options?: {
78
88
  namespace?: string;
79
89
  });
80
90
  }
@@ -238,6 +248,7 @@ type RangeCommandPayload = {
238
248
  includeVectors?: boolean;
239
249
  includeMetadata?: boolean;
240
250
  includeData?: boolean;
251
+ prefix?: string;
241
252
  };
242
253
  type RangeCommandOptions = {
243
254
  namespace?: string;
@@ -259,19 +270,34 @@ type ResetCommandOptions = {
259
270
  };
260
271
 
261
272
  type NamespaceTitle = string;
273
+ type SimilarityFunction = "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
262
274
  type NamespaceInfo = {
263
275
  vectorCount: number;
264
276
  pendingVectorCount: number;
265
277
  };
278
+ type DenseIndexInfo = {
279
+ dimension: number;
280
+ similarityFunction: SimilarityFunction;
281
+ embeddingModel?: string;
282
+ };
283
+ type SparseIndexInfo = {
284
+ embeddingModel?: string;
285
+ };
266
286
  type InfoResult = {
267
287
  vectorCount: number;
268
288
  pendingVectorCount: number;
269
289
  indexSize: number;
270
290
  dimension: number;
271
- similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
291
+ similarityFunction: SimilarityFunction;
292
+ denseIndex?: DenseIndexInfo;
293
+ sparseIndex?: SparseIndexInfo;
272
294
  namespaces: Record<NamespaceTitle, NamespaceInfo>;
273
295
  };
274
296
 
297
+ type ResumableQueryPayload = {
298
+ maxIdle: number;
299
+ } & QueryCommandPayload;
300
+
275
301
  declare class Namespace<TIndexMetadata extends Dict = Dict> {
276
302
  protected client: Requester;
277
303
  protected namespace: string;
@@ -366,19 +392,21 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
366
392
  updated: number;
367
393
  }>;
368
394
  /**
369
- * It's used for retrieving specific items from the index namespace, optionally including
370
- * their metadata and feature vectors.
395
+ * Fetches specific items from the index by their IDs or by an id prefix.
396
+ *
397
+ * Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
371
398
  *
372
399
  * @example
373
400
  * ```js
374
- * const fetchIds = ['123', '456'];
375
- * const fetchOptions = { includeMetadata: true, includeVectors: false };
376
- * const fetchResults = await index.namespace("ns").fetch(fetchIds, fetchOptions);
377
- * console.log(fetchResults); // Outputs the fetched items
401
+ * // Using ids
402
+ * await index.namespace("ns").fetch(["test-1", "test-2"], { includeMetadata: true });
403
+ *
404
+ * // Using id prefix
405
+ * await index.namespace("ns").fetch({ prefix: "test-" });
378
406
  * ```
379
407
  *
380
408
  * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
381
- * @param {(number[]|string[])} args[0] - An array of IDs of the items to be fetched.
409
+ * @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
382
410
  * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
383
411
  * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
384
412
  * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
@@ -386,7 +414,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
386
414
  *
387
415
  * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
388
416
  */
389
- fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
417
+ fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
418
+ ids: number[] | string[];
419
+ } | {
420
+ prefix: string;
421
+ }), opts?: {
390
422
  includeMetadata?: boolean | undefined;
391
423
  includeVectors?: boolean | undefined;
392
424
  includeData?: boolean | undefined;
@@ -417,36 +449,83 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
417
449
  */
418
450
  query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
419
451
  /**
420
- * Deletes a specific item or items from the index namespace by their ID(s). *
452
+ * Initializes a resumable query operation on the vector database.
453
+ * This method allows for querying large result sets in multiple chunks or implementing pagination.
454
+ *
455
+ * @template TMetadata
456
+ * @param {ResumableQueryPayload} args - The arguments for the resumable query.
457
+ * @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
458
+ * @param {number} args.topK - The number of top results to return in each fetch operation.
459
+ * @param {number[]} args.vector - The query vector used for similarity search.
460
+ * @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
461
+ * @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
462
+ * @param {Object} [options] - Additional options for the query.
463
+ * @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
464
+ * @example
465
+ * const { result, fetchNext, stop } = await index.namespace("ns").resumableQuery({
466
+ * maxIdle: 3600,
467
+ * topK: 50,
468
+ * vector: [0.1, 0.2, 0.3, ...],
469
+ * includeMetadata: true,
470
+ * includeVectors: true
471
+ * }, { namespace: 'my-namespace' });
472
+ *
473
+ * const firstBatch = await fetchNext(10);
474
+ * const secondBatch = await fetchNext(10);
475
+ * await stop(); // End the query session
476
+ */
477
+ resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload) => Promise<{
478
+ fetchNext: (additionalK: number) => Promise<QueryResult[]>;
479
+ stop: () => Promise<string>;
480
+ result: QueryResult<TMetadata>[];
481
+ }>;
482
+ /**
483
+ * Deletes items from the index namespace by id, by id prefix, or by filter.
421
484
  *
422
485
  * @example
423
486
  * ```js
424
- * await index.namespace("ns").delete('test-id')
425
- * // { deleted: 1 }
487
+ * // Delete by id
488
+ * await index.namespace("ns").delete("test-id");
489
+
490
+ * // Delete by ids
491
+ * await index.namespace("ns").delete(["test-id1", "test-id2"]);
492
+
493
+ * // Delete by id prefix
494
+ * await index.namespace("ns").delete({ prefix: "test-" });
495
+
496
+ * // Delete by filter
497
+ * await index.namespace("ns").delete({ filter: "age >= 23" });
426
498
  * ```
427
499
  *
428
- * @param id - List of ids or single id
429
- * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
500
+ * @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
501
+ * @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
430
502
  */
431
503
  delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
432
504
  deleted: number;
433
505
  }>;
434
506
  /**
435
- * Retrieves a range of items from the index.
507
+ * Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
508
+ * Returns items in batches with a cursor for pagination.
436
509
  *
437
510
  * @example
438
511
  * ```js
439
- * const rangeArgs = {
440
- * cursor: 0,
512
+ * const args = {
441
513
  * limit: 10,
442
514
  * includeVectors: true,
443
515
  * includeMetadata: false
444
516
  * };
445
- * const rangeResults = await index.namespace("ns").range(rangeArgs);
446
- * console.log(rangeResults); // Outputs the result of the range operation
517
+ * await index.namespace("ns").range(args);
518
+ *
519
+ * // Use the cursor to get the next page of results
520
+ * const nextPage = await index.namespace("ns").range({
521
+ * // You have to pass the arguments from the first call
522
+ * ...args,
523
+ * cursor: rangeResult.nextCursor,
524
+ * });
447
525
  * ```
448
526
  *
449
527
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
528
+ * @param {string} [args.prefix] - The prefix of the items to be fetched.
450
529
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
451
530
  * @param {number} args.limit - The maximum number of items to return in this range.
452
531
  * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
@@ -469,10 +548,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
469
548
  reset: () => Promise<string>;
470
549
  }
471
550
 
472
- type ResumableQueryPayload = {
473
- maxIdle: number;
474
- } & QueryCommandPayload;
475
-
476
551
  type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
477
552
  /**
478
553
  * Serverless vector client for upstash vector db.
@@ -493,16 +568,25 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
493
568
  constructor(client: Requester);
494
569
  namespace: (namespace: string) => Namespace<TIndexMetadata>;
495
570
  /**
496
- * Deletes a specific item or items from the index by their ID(s). *
571
+ * Deletes items from the index by id, by id prefix, or by filter.
497
572
  *
498
573
  * @example
499
574
  * ```js
500
- * const result = await index.delete('test-id');
501
- * // { deleted: 1 }
575
+ * // Delete by id
576
+ * await index.delete("test-id");
577
+
578
+ * // Delete by ids
579
+ * await index.delete(["test-id1", "test-id2"]);
580
+
581
+ * // Delete by id prefix
582
+ * await index.delete({ prefix: "test-" });
583
+
584
+ * // Delete by filter
585
+ * await index.delete({ filter: "age >= 23" });
502
586
  * ```
503
587
  *
504
- * @param id - List of ids or single id
505
- * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
588
+ * @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
589
+ * @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
506
590
  */
507
591
  delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
508
592
  namespace?: string;
@@ -687,27 +771,33 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
687
771
  updated: number;
688
772
  }>;
689
773
  /**
690
- * It's used for retrieving specific items from the index, optionally including
691
- * their metadata and feature vectors.
774
+ * Fetches specific items from the index by their IDs or by an id prefix.
775
+ *
776
+ * Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
692
777
  *
693
778
  * @example
694
779
  * ```js
695
- * const fetchIds = ['123', '456'];
696
- * const fetchOptions = { includeMetadata: true, includeVectors: false };
697
- * const fetchResults = await index.fetch(fetchIds, fetchOptions);
698
- * console.log(fetchResults); // Outputs the fetched items
780
+ * // Using ids
781
+ * await index.fetch(["test-1", "test-2"], { includeMetadata: true });
782
+ *
783
+ * // Using id prefix
784
+ * await index.fetch({ prefix: "test-" });
699
785
  * ```
700
786
  *
701
787
  * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
702
- * @param {(number[]|string[])} args - An array of IDs of the items to be fetched.
703
- * @param {FetchCommandOptions} args - Options for the fetch operation.
704
- * @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
705
- * @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
706
- * @param {boolean} [args.metadataUpdateMode="OVERWRITE"] - Specifies whether to overwrite or patch the metadata values.
788
+ * @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
789
+ * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
790
+ * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
791
+ * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
792
+ * @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
707
793
  *
708
794
  * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
709
795
  */
710
- fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
796
+ fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
797
+ ids: number[] | string[];
798
+ } | {
799
+ prefix: string;
800
+ }), opts?: {
711
801
  includeMetadata?: boolean | undefined;
712
802
  includeVectors?: boolean | undefined;
713
803
  includeData?: boolean | undefined;
@@ -744,27 +834,28 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
744
834
  */
745
835
  reset: (options?: ResetCommandOptions) => Promise<string>;
746
836
  /**
747
- * Retrieves a range of items from the index.
837
+ * Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
838
+ * Returns items in batches with a cursor for pagination.
748
839
  *
749
840
  * @example
750
841
  * ```js
751
- * const rangeArgs = {
752
- * cursor: 0,
842
+ * const args = {
753
843
  * limit: 10,
754
844
  * includeVectors: true,
755
845
  * includeMetadata: false
756
846
  * };
757
- * const rangeResults = await index.range(rangeArgs);
758
- * console.log(rangeResults); // Outputs the result of the range operation
759
- * ```
847
+ * await index.range(args);
760
848
  *
761
- * You can also pass a namespace like:
762
- *
763
- * ```js
764
- * const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
849
+ * // Use the cursor to get the next page of results
850
+ * const nextPage = await index.range({
851
+ * // You have to pass the arguments from the first call
852
+ * ...args,
853
+ * cursor: rangeResult.nextCursor,
854
+ * });
765
855
  * ```
766
856
  *
767
857
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
858
+ * @param {string} [args.prefix] - The prefix of the items to be fetched.
768
859
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
769
860
  * @param {number} args.limit - The maximum number of items to return in this range.
770
861
  * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
@@ -71,10 +71,20 @@ declare class Command<TResult> {
71
71
  exec(client: Requester): Promise<TResult>;
72
72
  }
73
73
 
74
+ type IdsPayload = (number[] | string[]) | number | string;
75
+ type ObjectPayload = {
76
+ ids: number[] | string[];
77
+ } | {
78
+ prefix: string;
79
+ } | {
80
+ filter: string;
81
+ };
82
+ type DeleteCommandPayload = IdsPayload | ObjectPayload;
83
+
74
84
  declare class DeleteCommand extends Command<{
75
85
  deleted: number;
76
86
  }> {
77
- constructor(id: (number[] | string[]) | number | string, options?: {
87
+ constructor(payload: DeleteCommandPayload, options?: {
78
88
  namespace?: string;
79
89
  });
80
90
  }
@@ -238,6 +248,7 @@ type RangeCommandPayload = {
238
248
  includeVectors?: boolean;
239
249
  includeMetadata?: boolean;
240
250
  includeData?: boolean;
251
+ prefix?: string;
241
252
  };
242
253
  type RangeCommandOptions = {
243
254
  namespace?: string;
@@ -259,19 +270,34 @@ type ResetCommandOptions = {
259
270
  };
260
271
 
261
272
  type NamespaceTitle = string;
273
+ type SimilarityFunction = "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
262
274
  type NamespaceInfo = {
263
275
  vectorCount: number;
264
276
  pendingVectorCount: number;
265
277
  };
278
+ type DenseIndexInfo = {
279
+ dimension: number;
280
+ similarityFunction: SimilarityFunction;
281
+ embeddingModel?: string;
282
+ };
283
+ type SparseIndexInfo = {
284
+ embeddingModel?: string;
285
+ };
266
286
  type InfoResult = {
267
287
  vectorCount: number;
268
288
  pendingVectorCount: number;
269
289
  indexSize: number;
270
290
  dimension: number;
271
- similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
291
+ similarityFunction: SimilarityFunction;
292
+ denseIndex?: DenseIndexInfo;
293
+ sparseIndex?: SparseIndexInfo;
272
294
  namespaces: Record<NamespaceTitle, NamespaceInfo>;
273
295
  };
274
296
 
297
+ type ResumableQueryPayload = {
298
+ maxIdle: number;
299
+ } & QueryCommandPayload;
300
+
275
301
  declare class Namespace<TIndexMetadata extends Dict = Dict> {
276
302
  protected client: Requester;
277
303
  protected namespace: string;
@@ -366,19 +392,21 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
366
392
  updated: number;
367
393
  }>;
368
394
  /**
369
- * It's used for retrieving specific items from the index namespace, optionally including
370
- * their metadata and feature vectors.
395
+ * Fetches specific items from the index by their IDs or by an id prefix.
396
+ *
397
+ * Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
371
398
  *
372
399
  * @example
373
400
  * ```js
374
- * const fetchIds = ['123', '456'];
375
- * const fetchOptions = { includeMetadata: true, includeVectors: false };
376
- * const fetchResults = await index.namespace("ns").fetch(fetchIds, fetchOptions);
377
- * console.log(fetchResults); // Outputs the fetched items
401
+ * // Using ids
402
+ * await index.namespace("ns").fetch(["test-1", "test-2"], { includeMetadata: true });
403
+ *
404
+ * // Using id prefix
405
+ * await index.namespace("ns").fetch({ prefix: "test-" });
378
406
  * ```
379
407
  *
380
408
  * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
381
- * @param {(number[]|string[])} args[0] - An array of IDs of the items to be fetched.
409
+ * @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
382
410
  * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
383
411
  * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
384
412
  * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
@@ -386,7 +414,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
386
414
  *
387
415
  * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
388
416
  */
389
- fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
417
+ fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
418
+ ids: number[] | string[];
419
+ } | {
420
+ prefix: string;
421
+ }), opts?: {
390
422
  includeMetadata?: boolean | undefined;
391
423
  includeVectors?: boolean | undefined;
392
424
  includeData?: boolean | undefined;
@@ -417,36 +449,83 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
417
449
  */
418
450
  query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
419
451
  /**
420
- * Deletes a specific item or items from the index namespace by their ID(s). *
452
+ * Initializes a resumable query operation on the vector database.
453
+ * This method allows for querying large result sets in multiple chunks or implementing pagination.
454
+ *
455
+ * @template TMetadata
456
+ * @param {ResumableQueryPayload} args - The arguments for the resumable query.
457
+ * @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
458
+ * @param {number} args.topK - The number of top results to return in each fetch operation.
459
+ * @param {number[]} args.vector - The query vector used for similarity search.
460
+ * @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
461
+ * @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
462
+ * @param {Object} [options] - Additional options for the query.
463
+ * @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
464
+ * @example
465
+ * const { result, fetchNext, stop } = await index.namespace("ns").resumableQuery({
466
+ * maxIdle: 3600,
467
+ * topK: 50,
468
+ * vector: [0.1, 0.2, 0.3, ...],
469
+ * includeMetadata: true,
470
+ * includeVectors: true
471
+ * }, { namespace: 'my-namespace' });
472
+ *
473
+ * const firstBatch = await fetchNext(10);
474
+ * const secondBatch = await fetchNext(10);
475
+ * await stop(); // End the query session
476
+ */
477
+ resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload) => Promise<{
478
+ fetchNext: (additionalK: number) => Promise<QueryResult[]>;
479
+ stop: () => Promise<string>;
480
+ result: QueryResult<TMetadata>[];
481
+ }>;
482
+ /**
483
+ * Deletes items from the index namespace by id, by id prefix, or by filter.
421
484
  *
422
485
  * @example
423
486
  * ```js
424
- * await index.namespace("ns").delete('test-id')
425
- * // { deleted: 1 }
487
+ * // Delete by id
488
+ * await index.namespace("ns").delete("test-id");
489
+
490
+ * // Delete by ids
491
+ * await index.namespace("ns").delete(["test-id1", "test-id2"]);
492
+
493
+ * // Delete by id prefix
494
+ * await index.namespace("ns").delete({ prefix: "test-" });
495
+
496
+ * // Delete by filter
497
+ * await index.namespace("ns").delete({ filter: "age >= 23" });
426
498
  * ```
427
499
  *
428
- * @param id - List of ids or single id
429
- * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
500
+ * @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
501
+ * @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
430
502
  */
431
503
  delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
432
504
  deleted: number;
433
505
  }>;
434
506
  /**
435
- * Retrieves a range of items from the index.
507
+ * Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
508
+ * Returns items in batches with a cursor for pagination.
436
509
  *
437
510
  * @example
438
511
  * ```js
439
- * const rangeArgs = {
440
- * cursor: 0,
512
+ * const args = {
441
513
  * limit: 10,
442
514
  * includeVectors: true,
443
515
  * includeMetadata: false
444
516
  * };
445
- * const rangeResults = await index.namespace("ns").range(rangeArgs);
446
- * console.log(rangeResults); // Outputs the result of the range operation
517
+ * await index.namespace("ns").range(args);
518
+ *
519
+ * // Use the cursor to get the next page of results
520
+ * const nextPage = await index.namespace("ns").range({
521
+ * // You have to pass the arguments from the first call
522
+ * ...args,
523
+ * cursor: rangeResult.nextCursor,
524
+ * });
447
525
  * ```
448
526
  *
449
527
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
528
+ * @param {string} [args.prefix] - The prefix of the items to be fetched.
450
529
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
451
530
  * @param {number} args.limit - The maximum number of items to return in this range.
452
531
  * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
@@ -469,10 +548,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
469
548
  reset: () => Promise<string>;
470
549
  }
471
550
 
472
- type ResumableQueryPayload = {
473
- maxIdle: number;
474
- } & QueryCommandPayload;
475
-
476
551
  type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
477
552
  /**
478
553
  * Serverless vector client for upstash vector db.
@@ -493,16 +568,25 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
493
568
  constructor(client: Requester);
494
569
  namespace: (namespace: string) => Namespace<TIndexMetadata>;
495
570
  /**
496
- * Deletes a specific item or items from the index by their ID(s). *
571
+ * Deletes items from the index by id, by id prefix, or by filter.
497
572
  *
498
573
  * @example
499
574
  * ```js
500
- * const result = await index.delete('test-id');
501
- * // { deleted: 1 }
575
+ * // Delete by id
576
+ * await index.delete("test-id");
577
+
578
+ * // Delete by ids
579
+ * await index.delete(["test-id1", "test-id2"]);
580
+
581
+ * // Delete by id prefix
582
+ * await index.delete({ prefix: "test-" });
583
+
584
+ * // Delete by filter
585
+ * await index.delete({ filter: "age >= 23" });
502
586
  * ```
503
587
  *
504
- * @param id - List of ids or single id
505
- * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
588
+ * @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
589
+ * @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
506
590
  */
507
591
  delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
508
592
  namespace?: string;
@@ -687,27 +771,33 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
687
771
  updated: number;
688
772
  }>;
689
773
  /**
690
- * It's used for retrieving specific items from the index, optionally including
691
- * their metadata and feature vectors.
774
+ * Fetches specific items from the index by their IDs or by an id prefix.
775
+ *
776
+ * Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
692
777
  *
693
778
  * @example
694
779
  * ```js
695
- * const fetchIds = ['123', '456'];
696
- * const fetchOptions = { includeMetadata: true, includeVectors: false };
697
- * const fetchResults = await index.fetch(fetchIds, fetchOptions);
698
- * console.log(fetchResults); // Outputs the fetched items
780
+ * // Using ids
781
+ * await index.fetch(["test-1", "test-2"], { includeMetadata: true });
782
+ *
783
+ * // Using id prefix
784
+ * await index.fetch({ prefix: "test-" });
699
785
  * ```
700
786
  *
701
787
  * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
702
- * @param {(number[]|string[])} args - An array of IDs of the items to be fetched.
703
- * @param {FetchCommandOptions} args - Options for the fetch operation.
704
- * @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
705
- * @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
706
- * @param {boolean} [args.metadataUpdateMode="OVERWRITE"] - Specifies whether to overwrite or patch the metadata values.
788
+ * @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
789
+ * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
790
+ * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
791
+ * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
792
+ * @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
707
793
  *
708
794
  * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
709
795
  */
710
- fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
796
+ fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
797
+ ids: number[] | string[];
798
+ } | {
799
+ prefix: string;
800
+ }), opts?: {
711
801
  includeMetadata?: boolean | undefined;
712
802
  includeVectors?: boolean | undefined;
713
803
  includeData?: boolean | undefined;
@@ -744,27 +834,28 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
744
834
  */
745
835
  reset: (options?: ResetCommandOptions) => Promise<string>;
746
836
  /**
747
- * Retrieves a range of items from the index.
837
+ * Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
838
+ * Returns items in batches with a cursor for pagination.
748
839
  *
749
840
  * @example
750
841
  * ```js
751
- * const rangeArgs = {
752
- * cursor: 0,
842
+ * const args = {
753
843
  * limit: 10,
754
844
  * includeVectors: true,
755
845
  * includeMetadata: false
756
846
  * };
757
- * const rangeResults = await index.range(rangeArgs);
758
- * console.log(rangeResults); // Outputs the result of the range operation
759
- * ```
847
+ * await index.range(args);
760
848
  *
761
- * You can also pass a namespace like:
762
- *
763
- * ```js
764
- * const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
849
+ * // Use the cursor to get the next page of results
850
+ * const nextPage = await index.range({
851
+ * // You have to pass the arguments from the first call
852
+ * ...args,
853
+ * cursor: rangeResult.nextCursor,
854
+ * });
765
855
  * ```
766
856
  *
767
857
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
858
+ * @param {string} [args.prefix] - The prefix of the items to be fetched.
768
859
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
769
860
  * @param {number} args.limit - The maximum number of items to return in this range.
770
861
  * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.