@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
|
@@ -41,6 +41,12 @@ type RequesterConfig = {
|
|
|
41
41
|
*/
|
|
42
42
|
cache?: CacheSetting;
|
|
43
43
|
};
|
|
44
|
+
type HttpClientConfig = {
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
baseUrl: string;
|
|
47
|
+
retry?: RetryConfig;
|
|
48
|
+
signal?: AbortSignal | (() => AbortSignal);
|
|
49
|
+
} & RequesterConfig;
|
|
44
50
|
|
|
45
51
|
type Vector<TMetadata = Dict> = {
|
|
46
52
|
id: string;
|
|
@@ -71,10 +77,20 @@ declare class Command<TResult> {
|
|
|
71
77
|
exec(client: Requester): Promise<TResult>;
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
type IdsPayload = (number[] | string[]) | number | string;
|
|
81
|
+
type ObjectPayload = {
|
|
82
|
+
ids: number[] | string[];
|
|
83
|
+
} | {
|
|
84
|
+
prefix: string;
|
|
85
|
+
} | {
|
|
86
|
+
filter: string;
|
|
87
|
+
};
|
|
88
|
+
type DeleteCommandPayload = IdsPayload | ObjectPayload;
|
|
89
|
+
|
|
74
90
|
declare class DeleteCommand extends Command<{
|
|
75
91
|
deleted: number;
|
|
76
92
|
}> {
|
|
77
|
-
constructor(
|
|
93
|
+
constructor(payload: DeleteCommandPayload, options?: {
|
|
78
94
|
namespace?: string;
|
|
79
95
|
});
|
|
80
96
|
}
|
|
@@ -238,6 +254,7 @@ type RangeCommandPayload = {
|
|
|
238
254
|
includeVectors?: boolean;
|
|
239
255
|
includeMetadata?: boolean;
|
|
240
256
|
includeData?: boolean;
|
|
257
|
+
prefix?: string;
|
|
241
258
|
};
|
|
242
259
|
type RangeCommandOptions = {
|
|
243
260
|
namespace?: string;
|
|
@@ -259,19 +276,34 @@ type ResetCommandOptions = {
|
|
|
259
276
|
};
|
|
260
277
|
|
|
261
278
|
type NamespaceTitle = string;
|
|
279
|
+
type SimilarityFunction = "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
|
|
262
280
|
type NamespaceInfo = {
|
|
263
281
|
vectorCount: number;
|
|
264
282
|
pendingVectorCount: number;
|
|
265
283
|
};
|
|
284
|
+
type DenseIndexInfo = {
|
|
285
|
+
dimension: number;
|
|
286
|
+
similarityFunction: SimilarityFunction;
|
|
287
|
+
embeddingModel?: string;
|
|
288
|
+
};
|
|
289
|
+
type SparseIndexInfo = {
|
|
290
|
+
embeddingModel?: string;
|
|
291
|
+
};
|
|
266
292
|
type InfoResult = {
|
|
267
293
|
vectorCount: number;
|
|
268
294
|
pendingVectorCount: number;
|
|
269
295
|
indexSize: number;
|
|
270
296
|
dimension: number;
|
|
271
|
-
similarityFunction:
|
|
297
|
+
similarityFunction: SimilarityFunction;
|
|
298
|
+
denseIndex?: DenseIndexInfo;
|
|
299
|
+
sparseIndex?: SparseIndexInfo;
|
|
272
300
|
namespaces: Record<NamespaceTitle, NamespaceInfo>;
|
|
273
301
|
};
|
|
274
302
|
|
|
303
|
+
type ResumableQueryPayload = {
|
|
304
|
+
maxIdle: number;
|
|
305
|
+
} & QueryCommandPayload;
|
|
306
|
+
|
|
275
307
|
declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
276
308
|
protected client: Requester;
|
|
277
309
|
protected namespace: string;
|
|
@@ -366,19 +398,21 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
366
398
|
updated: number;
|
|
367
399
|
}>;
|
|
368
400
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
401
|
+
* Fetches specific items from the index by their IDs or by an id prefix.
|
|
402
|
+
*
|
|
403
|
+
* Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
|
|
371
404
|
*
|
|
372
405
|
* @example
|
|
373
406
|
* ```js
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
407
|
+
* // Using ids
|
|
408
|
+
* await index.namespace("ns").fetch(["test-1", "test-2"], { includeMetadata: true });
|
|
409
|
+
*
|
|
410
|
+
* // Using id prefix
|
|
411
|
+
* await index.namespace("ns").fetch({ prefix: "test-" });
|
|
378
412
|
* ```
|
|
379
413
|
*
|
|
380
414
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
381
|
-
* @param {
|
|
415
|
+
* @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
|
|
382
416
|
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
383
417
|
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
384
418
|
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
@@ -386,7 +420,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
386
420
|
*
|
|
387
421
|
* @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
422
|
*/
|
|
389
|
-
fetch: <TMetadata extends Dict = TIndexMetadata>(
|
|
423
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
|
|
424
|
+
ids: number[] | string[];
|
|
425
|
+
} | {
|
|
426
|
+
prefix: string;
|
|
427
|
+
}), opts?: {
|
|
390
428
|
includeMetadata?: boolean | undefined;
|
|
391
429
|
includeVectors?: boolean | undefined;
|
|
392
430
|
includeData?: boolean | undefined;
|
|
@@ -417,36 +455,83 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
417
455
|
*/
|
|
418
456
|
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
419
457
|
/**
|
|
420
|
-
*
|
|
458
|
+
* Initializes a resumable query operation on the vector database.
|
|
459
|
+
* This method allows for querying large result sets in multiple chunks or implementing pagination.
|
|
460
|
+
*
|
|
461
|
+
* @template TMetadata
|
|
462
|
+
* @param {ResumableQueryPayload} args - The arguments for the resumable query.
|
|
463
|
+
* @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
|
|
464
|
+
* @param {number} args.topK - The number of top results to return in each fetch operation.
|
|
465
|
+
* @param {number[]} args.vector - The query vector used for similarity search.
|
|
466
|
+
* @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
|
|
467
|
+
* @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
|
|
468
|
+
* @param {Object} [options] - Additional options for the query.
|
|
469
|
+
* @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
|
|
470
|
+
* @example
|
|
471
|
+
* const { result, fetchNext, stop } = await index.namespace("ns").resumableQuery({
|
|
472
|
+
* maxIdle: 3600,
|
|
473
|
+
* topK: 50,
|
|
474
|
+
* vector: [0.1, 0.2, 0.3, ...],
|
|
475
|
+
* includeMetadata: true,
|
|
476
|
+
* includeVectors: true
|
|
477
|
+
* }, { namespace: 'my-namespace' });
|
|
478
|
+
*
|
|
479
|
+
* const firstBatch = await fetchNext(10);
|
|
480
|
+
* const secondBatch = await fetchNext(10);
|
|
481
|
+
* await stop(); // End the query session
|
|
482
|
+
*/
|
|
483
|
+
resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload) => Promise<{
|
|
484
|
+
fetchNext: (additionalK: number) => Promise<QueryResult[]>;
|
|
485
|
+
stop: () => Promise<string>;
|
|
486
|
+
result: QueryResult<TMetadata>[];
|
|
487
|
+
}>;
|
|
488
|
+
/**
|
|
489
|
+
* Deletes items from the index namespace by id, by id prefix, or by filter.
|
|
421
490
|
*
|
|
422
491
|
* @example
|
|
423
492
|
* ```js
|
|
424
|
-
*
|
|
425
|
-
*
|
|
493
|
+
* // Delete by id
|
|
494
|
+
* await index.namespace("ns").delete("test-id");
|
|
495
|
+
|
|
496
|
+
* // Delete by ids
|
|
497
|
+
* await index.namespace("ns").delete(["test-id1", "test-id2"]);
|
|
498
|
+
|
|
499
|
+
* // Delete by id prefix
|
|
500
|
+
* await index.namespace("ns").delete({ prefix: "test-" });
|
|
501
|
+
|
|
502
|
+
* // Delete by filter
|
|
503
|
+
* await index.namespace("ns").delete({ filter: "age >= 23" });
|
|
426
504
|
* ```
|
|
427
505
|
*
|
|
428
|
-
* @param
|
|
429
|
-
* @returns Number of deleted vectors
|
|
506
|
+
* @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
|
|
507
|
+
* @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
|
|
430
508
|
*/
|
|
431
509
|
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
432
510
|
deleted: number;
|
|
433
511
|
}>;
|
|
434
512
|
/**
|
|
435
|
-
* Retrieves a range of items from the index.
|
|
513
|
+
* Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
|
|
514
|
+
* Returns items in batches with a cursor for pagination.
|
|
436
515
|
*
|
|
437
516
|
* @example
|
|
438
517
|
* ```js
|
|
439
|
-
* const
|
|
440
|
-
* cursor: 0,
|
|
518
|
+
* const args = {
|
|
441
519
|
* limit: 10,
|
|
442
520
|
* includeVectors: true,
|
|
443
521
|
* includeMetadata: false
|
|
444
522
|
* };
|
|
445
|
-
*
|
|
446
|
-
*
|
|
523
|
+
* await index.namespace("ns").range(args);
|
|
524
|
+
*
|
|
525
|
+
* // Use the cursor to get the next page of results
|
|
526
|
+
* const nextPage = await index.namespace("ns").range({
|
|
527
|
+
* // You have to pass the arguments from the first call
|
|
528
|
+
* ...args,
|
|
529
|
+
* cursor: rangeResult.nextCursor,
|
|
530
|
+
* });
|
|
447
531
|
* ```
|
|
448
532
|
*
|
|
449
533
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
534
|
+
* @param {string} [args.prefix] - The prefix of the items to be fetched.
|
|
450
535
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
451
536
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
452
537
|
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
@@ -469,10 +554,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
469
554
|
reset: () => Promise<string>;
|
|
470
555
|
}
|
|
471
556
|
|
|
472
|
-
type ResumableQueryPayload = {
|
|
473
|
-
maxIdle: number;
|
|
474
|
-
} & QueryCommandPayload;
|
|
475
|
-
|
|
476
557
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
477
558
|
/**
|
|
478
559
|
* Serverless vector client for upstash vector db.
|
|
@@ -493,16 +574,25 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
493
574
|
constructor(client: Requester);
|
|
494
575
|
namespace: (namespace: string) => Namespace<TIndexMetadata>;
|
|
495
576
|
/**
|
|
496
|
-
* Deletes
|
|
577
|
+
* Deletes items from the index by id, by id prefix, or by filter.
|
|
497
578
|
*
|
|
498
579
|
* @example
|
|
499
580
|
* ```js
|
|
500
|
-
*
|
|
501
|
-
*
|
|
581
|
+
* // Delete by id
|
|
582
|
+
* await index.delete("test-id");
|
|
583
|
+
|
|
584
|
+
* // Delete by ids
|
|
585
|
+
* await index.delete(["test-id1", "test-id2"]);
|
|
586
|
+
|
|
587
|
+
* // Delete by id prefix
|
|
588
|
+
* await index.delete({ prefix: "test-" });
|
|
589
|
+
|
|
590
|
+
* // Delete by filter
|
|
591
|
+
* await index.delete({ filter: "age >= 23" });
|
|
502
592
|
* ```
|
|
503
593
|
*
|
|
504
|
-
* @param
|
|
505
|
-
* @returns Number of deleted vectors
|
|
594
|
+
* @param args - A single id, an array of ids, a prefix, or a filter to delete items from the index.
|
|
595
|
+
* @returns Number of deleted vectors in the format `{ deleted: number }`.If no vectors are deleted, returns `{ deleted: 0 }`.
|
|
506
596
|
*/
|
|
507
597
|
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
508
598
|
namespace?: string;
|
|
@@ -687,27 +777,33 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
687
777
|
updated: number;
|
|
688
778
|
}>;
|
|
689
779
|
/**
|
|
690
|
-
*
|
|
691
|
-
*
|
|
780
|
+
* Fetches specific items from the index by their IDs or by an id prefix.
|
|
781
|
+
*
|
|
782
|
+
* Note: While using id prefix, the paginated `range` command is recommended to prevent timeouts on large result sets.
|
|
692
783
|
*
|
|
693
784
|
* @example
|
|
694
785
|
* ```js
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
786
|
+
* // Using ids
|
|
787
|
+
* await index.fetch(["test-1", "test-2"], { includeMetadata: true });
|
|
788
|
+
*
|
|
789
|
+
* // Using id prefix
|
|
790
|
+
* await index.fetch({ prefix: "test-" });
|
|
699
791
|
* ```
|
|
700
792
|
*
|
|
701
793
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
702
|
-
* @param {
|
|
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 {
|
|
794
|
+
* @param {FetchPayload} args[0] - An array of IDs or the id prefix of the items to be fetched.
|
|
795
|
+
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
796
|
+
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
797
|
+
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
798
|
+
* @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
|
|
707
799
|
*
|
|
708
800
|
* @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
801
|
*/
|
|
710
|
-
fetch: <TMetadata extends Dict = TIndexMetadata>(
|
|
802
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(payload: (number[] | string[]) | ({
|
|
803
|
+
ids: number[] | string[];
|
|
804
|
+
} | {
|
|
805
|
+
prefix: string;
|
|
806
|
+
}), opts?: {
|
|
711
807
|
includeMetadata?: boolean | undefined;
|
|
712
808
|
includeVectors?: boolean | undefined;
|
|
713
809
|
includeData?: boolean | undefined;
|
|
@@ -744,27 +840,28 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
744
840
|
*/
|
|
745
841
|
reset: (options?: ResetCommandOptions) => Promise<string>;
|
|
746
842
|
/**
|
|
747
|
-
* Retrieves a range of items from the index.
|
|
843
|
+
* Retrieves a paginated range of items from the index. Optionally filter results by an id prefix.
|
|
844
|
+
* Returns items in batches with a cursor for pagination.
|
|
748
845
|
*
|
|
749
846
|
* @example
|
|
750
847
|
* ```js
|
|
751
|
-
* const
|
|
752
|
-
* cursor: 0,
|
|
848
|
+
* const args = {
|
|
753
849
|
* limit: 10,
|
|
754
850
|
* includeVectors: true,
|
|
755
851
|
* includeMetadata: false
|
|
756
852
|
* };
|
|
757
|
-
*
|
|
758
|
-
* console.log(rangeResults); // Outputs the result of the range operation
|
|
759
|
-
* ```
|
|
853
|
+
* await index.range(args);
|
|
760
854
|
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
855
|
+
* // Use the cursor to get the next page of results
|
|
856
|
+
* const nextPage = await index.range({
|
|
857
|
+
* // You have to pass the arguments from the first call
|
|
858
|
+
* ...args,
|
|
859
|
+
* cursor: rangeResult.nextCursor,
|
|
860
|
+
* });
|
|
765
861
|
* ```
|
|
766
862
|
*
|
|
767
863
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
864
|
+
* @param {string} [args.prefix] - The prefix of the items to be fetched.
|
|
768
865
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
769
866
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
770
867
|
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
@@ -814,4 +911,4 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
814
911
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
815
912
|
}
|
|
816
913
|
|
|
817
|
-
export { type Dict as D, FusionAlgorithm as F, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
|
|
914
|
+
export { type Dict as D, FusionAlgorithm as F, type HttpClientConfig as H, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.2.
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.2.2", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "exports": { ".": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "require": "./dist/cloudflare.js" }, "./nodejs": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" } }, "main": "./dist/nodejs.js", "module": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts", "devDependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "bun-types": "latest", "eslint": "9.10.0", "eslint-plugin-unicorn": "^55.0.0", "husky": "^8.0.3", "prettier": "^3.3.3", "tsup": "latest", "typescript": "^5.0.0", "vitest": "^1.2.2" }, "bugs": { "url": "https://github.com/upstash/vector/issues" }, "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "files": [ "dist" ], "homepage": "https://upstash.com/vector", "keywords": [ "vector", "upstash", "db" ], "license": "MIT", "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000", "fmt": "prettier --write .", "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix", "build": "tsup ", "prepare": "husky install" } }
|