@upstash/vector 1.1.5 → 1.1.7
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 +4 -4
- package/dist/chunk-XN6MKCVR.mjs +761 -0
- package/dist/cloudflare.d.mts +2 -2
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +860 -1
- package/dist/cloudflare.mjs +81 -1
- package/dist/nodejs.d.mts +2 -2
- package/dist/nodejs.d.ts +2 -2
- package/dist/nodejs.js +839 -1
- package/dist/nodejs.mjs +60 -1
- package/dist/{vector-wT6XsV3D.d.mts → vector-gR6tGrYi.d.mts} +82 -12
- package/dist/{vector-wT6XsV3D.d.ts → vector-gR6tGrYi.d.ts} +82 -12
- package/package.json +1 -1
- package/dist/chunk-J6ZA44LH.mjs +0 -1
package/dist/nodejs.mjs
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
HttpClient,
|
|
3
|
+
Index
|
|
4
|
+
} from "./chunk-XN6MKCVR.mjs";
|
|
5
|
+
|
|
6
|
+
// src/platforms/nodejs.ts
|
|
7
|
+
var Index2 = class _Index extends Index {
|
|
8
|
+
constructor(configOrRequester) {
|
|
9
|
+
if (configOrRequester !== void 0 && "request" in configOrRequester) {
|
|
10
|
+
super(configOrRequester);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const token = configOrRequester?.token ?? process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN ?? process.env.UPSTASH_VECTOR_REST_TOKEN;
|
|
14
|
+
const url = configOrRequester?.url ?? process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL ?? process.env.UPSTASH_VECTOR_REST_URL;
|
|
15
|
+
if (!token) {
|
|
16
|
+
throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");
|
|
17
|
+
}
|
|
18
|
+
if (!url) {
|
|
19
|
+
throw new Error("UPSTASH_VECTOR_REST_URL is missing!");
|
|
20
|
+
}
|
|
21
|
+
if (url.startsWith(" ") || url.endsWith(" ") || /\r|\n/.test(url)) {
|
|
22
|
+
console.warn("The vector url contains whitespace or newline, which can cause errors!");
|
|
23
|
+
}
|
|
24
|
+
if (token.startsWith(" ") || token.endsWith(" ") || /\r|\n/.test(token)) {
|
|
25
|
+
console.warn("The vector token contains whitespace or newline, which can cause errors!");
|
|
26
|
+
}
|
|
27
|
+
const client = new HttpClient({
|
|
28
|
+
baseUrl: url,
|
|
29
|
+
retry: configOrRequester?.retry,
|
|
30
|
+
headers: { authorization: `Bearer ${token}` },
|
|
31
|
+
cache: configOrRequester?.cache === false ? void 0 : configOrRequester?.cache || "no-store",
|
|
32
|
+
signal: configOrRequester?.signal
|
|
33
|
+
});
|
|
34
|
+
super(client);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
38
|
+
*
|
|
39
|
+
* Use this to automatically load connection secrets from your environment
|
|
40
|
+
* variables. For instance when using the Vercel integration.
|
|
41
|
+
*
|
|
42
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
43
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
44
|
+
* your environment using `process.env`.
|
|
45
|
+
*/
|
|
46
|
+
static fromEnv(env, config) {
|
|
47
|
+
const url = env?.UPSTASH_VECTOR_REST_URL || process?.env.UPSTASH_VECTOR_REST_URL;
|
|
48
|
+
const token = env?.UPSTASH_VECTOR_REST_TOKEN || process?.env.UPSTASH_VECTOR_REST_TOKEN;
|
|
49
|
+
if (!url) {
|
|
50
|
+
throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");
|
|
51
|
+
}
|
|
52
|
+
if (!token) {
|
|
53
|
+
throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");
|
|
54
|
+
}
|
|
55
|
+
return new _Index({ ...config, url, token });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
Index2 as Index
|
|
60
|
+
};
|
|
@@ -10,9 +10,9 @@ type UpstashResponse<TResult> = {
|
|
|
10
10
|
result?: TResult;
|
|
11
11
|
error?: string;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type Requester = {
|
|
14
14
|
request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
type RetryConfig = false | {
|
|
17
17
|
/**
|
|
18
18
|
* The number of retries to attempt before giving up.
|
|
@@ -51,8 +51,8 @@ type Vector<TMetadata = Dict> = {
|
|
|
51
51
|
type NAMESPACE = string;
|
|
52
52
|
type Dict = Record<string, unknown>;
|
|
53
53
|
|
|
54
|
-
declare const
|
|
55
|
-
type EndpointVariants = (typeof
|
|
54
|
+
declare const _ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "resumable-query", "resumable-query-data", "resumable-query-next", "resumable-query-end", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
55
|
+
type EndpointVariants = (typeof _ENDPOINTS)[number] | `${(typeof _ENDPOINTS)[number]}/${NAMESPACE}` | `reset?all`;
|
|
56
56
|
/**
|
|
57
57
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
58
58
|
*/
|
|
@@ -126,6 +126,14 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
|
126
126
|
constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
type ResetCommandOptions = {
|
|
130
|
+
namespace?: string;
|
|
131
|
+
all?: never;
|
|
132
|
+
} | {
|
|
133
|
+
namespace?: never;
|
|
134
|
+
all?: true;
|
|
135
|
+
};
|
|
136
|
+
|
|
129
137
|
type NamespaceTitle = string;
|
|
130
138
|
type NamespaceInfo = {
|
|
131
139
|
vectorCount: number;
|
|
@@ -266,10 +274,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
266
274
|
* @example
|
|
267
275
|
* ```js
|
|
268
276
|
* await index.namespace("ns").delete('test-id')
|
|
277
|
+
* // { deleted: 1 }
|
|
269
278
|
* ```
|
|
270
279
|
*
|
|
271
280
|
* @param id - List of ids or single id
|
|
272
|
-
* @returns
|
|
281
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
273
282
|
*/
|
|
274
283
|
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
275
284
|
deleted: number;
|
|
@@ -312,6 +321,10 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
312
321
|
reset: () => Promise<string>;
|
|
313
322
|
}
|
|
314
323
|
|
|
324
|
+
type ResumableQueryPayload = {
|
|
325
|
+
maxIdle: number;
|
|
326
|
+
} & QueryCommandPayload;
|
|
327
|
+
|
|
315
328
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
316
329
|
/**
|
|
317
330
|
* Serverless vector client for upstash vector db.
|
|
@@ -336,11 +349,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
336
349
|
*
|
|
337
350
|
* @example
|
|
338
351
|
* ```js
|
|
339
|
-
* await index.delete('test-id')
|
|
352
|
+
* const result = await index.delete('test-id');
|
|
353
|
+
* // { deleted: 1 }
|
|
340
354
|
* ```
|
|
341
355
|
*
|
|
342
356
|
* @param id - List of ids or single id
|
|
343
|
-
* @returns
|
|
357
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
344
358
|
*/
|
|
345
359
|
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
346
360
|
namespace?: string;
|
|
@@ -410,6 +424,40 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
410
424
|
queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
|
|
411
425
|
namespace?: string;
|
|
412
426
|
}) => Promise<QueryResult<TMetadata>[][]>;
|
|
427
|
+
/**
|
|
428
|
+
* Initializes a resumable query operation on the vector database.
|
|
429
|
+
* This method allows for querying large result sets in multiple chunks or implementing pagination.
|
|
430
|
+
*
|
|
431
|
+
* @template TMetadata
|
|
432
|
+
* @param {ResumableQueryPayload} args - The arguments for the resumable query.
|
|
433
|
+
* @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
|
|
434
|
+
* @param {number} args.topK - The number of top results to return in each fetch operation.
|
|
435
|
+
* @param {number[]} args.vector - The query vector used for similarity search.
|
|
436
|
+
* @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
|
|
437
|
+
* @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
|
|
438
|
+
* @param {Object} [options] - Additional options for the query.
|
|
439
|
+
* @param {string} [options.namespace] - The namespace to query within.
|
|
440
|
+
* @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
|
|
441
|
+
* @example
|
|
442
|
+
* const { result, fetchNext, stop } = await index.resumableQuery({
|
|
443
|
+
* maxIdle: 3600,
|
|
444
|
+
* topK: 50,
|
|
445
|
+
* vector: [0.1, 0.2, 0.3, ...],
|
|
446
|
+
* includeMetadata: true,
|
|
447
|
+
* includeVectors: true
|
|
448
|
+
* }, { namespace: 'my-namespace' });
|
|
449
|
+
*
|
|
450
|
+
* const firstBatch = await fetchNext(10);
|
|
451
|
+
* const secondBatch = await fetchNext(10);
|
|
452
|
+
* await stop(); // End the query session
|
|
453
|
+
*/
|
|
454
|
+
resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload, options?: {
|
|
455
|
+
namespace?: string;
|
|
456
|
+
}) => Promise<{
|
|
457
|
+
fetchNext: (additionalK: number) => Promise<QueryResult[]>;
|
|
458
|
+
stop: () => Promise<string>;
|
|
459
|
+
result: QueryResult<TMetadata>[];
|
|
460
|
+
}>;
|
|
413
461
|
/**
|
|
414
462
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
415
463
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -494,19 +542,35 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
494
542
|
namespace?: string | undefined;
|
|
495
543
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
496
544
|
/**
|
|
497
|
-
* It's used for wiping
|
|
545
|
+
* It's used for wiping the index.
|
|
546
|
+
*
|
|
547
|
+
* By default, resets the default namespace:
|
|
498
548
|
*
|
|
499
549
|
* @example
|
|
500
550
|
* ```js
|
|
501
551
|
* await index.reset();
|
|
502
|
-
* console.log('
|
|
552
|
+
* console.log('Default namespace has been reset');
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* To reset a namespace, call reset like:
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```js
|
|
559
|
+
* await index.reset({ namespace: "ns" });
|
|
560
|
+
* console.log('Namespace ns has been reset');
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* If you want to reset all namespaces, call reset like:
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```js
|
|
567
|
+
* await index.reset({ all: true });
|
|
568
|
+
* console.log('All namespaces have been reset');
|
|
503
569
|
* ```
|
|
504
570
|
*
|
|
505
571
|
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
506
572
|
*/
|
|
507
|
-
reset: (options?:
|
|
508
|
-
namespace?: string;
|
|
509
|
-
}) => Promise<string>;
|
|
573
|
+
reset: (options?: ResetCommandOptions) => Promise<string>;
|
|
510
574
|
/**
|
|
511
575
|
* Retrieves a range of items from the index.
|
|
512
576
|
*
|
|
@@ -522,6 +586,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
522
586
|
* console.log(rangeResults); // Outputs the result of the range operation
|
|
523
587
|
* ```
|
|
524
588
|
*
|
|
589
|
+
* You can also pass a namespace like:
|
|
590
|
+
*
|
|
591
|
+
* ```js
|
|
592
|
+
* const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
525
595
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
526
596
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
527
597
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
@@ -10,9 +10,9 @@ type UpstashResponse<TResult> = {
|
|
|
10
10
|
result?: TResult;
|
|
11
11
|
error?: string;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type Requester = {
|
|
14
14
|
request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
type RetryConfig = false | {
|
|
17
17
|
/**
|
|
18
18
|
* The number of retries to attempt before giving up.
|
|
@@ -51,8 +51,8 @@ type Vector<TMetadata = Dict> = {
|
|
|
51
51
|
type NAMESPACE = string;
|
|
52
52
|
type Dict = Record<string, unknown>;
|
|
53
53
|
|
|
54
|
-
declare const
|
|
55
|
-
type EndpointVariants = (typeof
|
|
54
|
+
declare const _ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "resumable-query", "resumable-query-data", "resumable-query-next", "resumable-query-end", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
55
|
+
type EndpointVariants = (typeof _ENDPOINTS)[number] | `${(typeof _ENDPOINTS)[number]}/${NAMESPACE}` | `reset?all`;
|
|
56
56
|
/**
|
|
57
57
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
58
58
|
*/
|
|
@@ -126,6 +126,14 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
|
126
126
|
constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
type ResetCommandOptions = {
|
|
130
|
+
namespace?: string;
|
|
131
|
+
all?: never;
|
|
132
|
+
} | {
|
|
133
|
+
namespace?: never;
|
|
134
|
+
all?: true;
|
|
135
|
+
};
|
|
136
|
+
|
|
129
137
|
type NamespaceTitle = string;
|
|
130
138
|
type NamespaceInfo = {
|
|
131
139
|
vectorCount: number;
|
|
@@ -266,10 +274,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
266
274
|
* @example
|
|
267
275
|
* ```js
|
|
268
276
|
* await index.namespace("ns").delete('test-id')
|
|
277
|
+
* // { deleted: 1 }
|
|
269
278
|
* ```
|
|
270
279
|
*
|
|
271
280
|
* @param id - List of ids or single id
|
|
272
|
-
* @returns
|
|
281
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
273
282
|
*/
|
|
274
283
|
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
275
284
|
deleted: number;
|
|
@@ -312,6 +321,10 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
312
321
|
reset: () => Promise<string>;
|
|
313
322
|
}
|
|
314
323
|
|
|
324
|
+
type ResumableQueryPayload = {
|
|
325
|
+
maxIdle: number;
|
|
326
|
+
} & QueryCommandPayload;
|
|
327
|
+
|
|
315
328
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
316
329
|
/**
|
|
317
330
|
* Serverless vector client for upstash vector db.
|
|
@@ -336,11 +349,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
336
349
|
*
|
|
337
350
|
* @example
|
|
338
351
|
* ```js
|
|
339
|
-
* await index.delete('test-id')
|
|
352
|
+
* const result = await index.delete('test-id');
|
|
353
|
+
* // { deleted: 1 }
|
|
340
354
|
* ```
|
|
341
355
|
*
|
|
342
356
|
* @param id - List of ids or single id
|
|
343
|
-
* @returns
|
|
357
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
344
358
|
*/
|
|
345
359
|
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
346
360
|
namespace?: string;
|
|
@@ -410,6 +424,40 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
410
424
|
queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
|
|
411
425
|
namespace?: string;
|
|
412
426
|
}) => Promise<QueryResult<TMetadata>[][]>;
|
|
427
|
+
/**
|
|
428
|
+
* Initializes a resumable query operation on the vector database.
|
|
429
|
+
* This method allows for querying large result sets in multiple chunks or implementing pagination.
|
|
430
|
+
*
|
|
431
|
+
* @template TMetadata
|
|
432
|
+
* @param {ResumableQueryPayload} args - The arguments for the resumable query.
|
|
433
|
+
* @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
|
|
434
|
+
* @param {number} args.topK - The number of top results to return in each fetch operation.
|
|
435
|
+
* @param {number[]} args.vector - The query vector used for similarity search.
|
|
436
|
+
* @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
|
|
437
|
+
* @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
|
|
438
|
+
* @param {Object} [options] - Additional options for the query.
|
|
439
|
+
* @param {string} [options.namespace] - The namespace to query within.
|
|
440
|
+
* @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
|
|
441
|
+
* @example
|
|
442
|
+
* const { result, fetchNext, stop } = await index.resumableQuery({
|
|
443
|
+
* maxIdle: 3600,
|
|
444
|
+
* topK: 50,
|
|
445
|
+
* vector: [0.1, 0.2, 0.3, ...],
|
|
446
|
+
* includeMetadata: true,
|
|
447
|
+
* includeVectors: true
|
|
448
|
+
* }, { namespace: 'my-namespace' });
|
|
449
|
+
*
|
|
450
|
+
* const firstBatch = await fetchNext(10);
|
|
451
|
+
* const secondBatch = await fetchNext(10);
|
|
452
|
+
* await stop(); // End the query session
|
|
453
|
+
*/
|
|
454
|
+
resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload, options?: {
|
|
455
|
+
namespace?: string;
|
|
456
|
+
}) => Promise<{
|
|
457
|
+
fetchNext: (additionalK: number) => Promise<QueryResult[]>;
|
|
458
|
+
stop: () => Promise<string>;
|
|
459
|
+
result: QueryResult<TMetadata>[];
|
|
460
|
+
}>;
|
|
413
461
|
/**
|
|
414
462
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
415
463
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -494,19 +542,35 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
494
542
|
namespace?: string | undefined;
|
|
495
543
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
496
544
|
/**
|
|
497
|
-
* It's used for wiping
|
|
545
|
+
* It's used for wiping the index.
|
|
546
|
+
*
|
|
547
|
+
* By default, resets the default namespace:
|
|
498
548
|
*
|
|
499
549
|
* @example
|
|
500
550
|
* ```js
|
|
501
551
|
* await index.reset();
|
|
502
|
-
* console.log('
|
|
552
|
+
* console.log('Default namespace has been reset');
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* To reset a namespace, call reset like:
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```js
|
|
559
|
+
* await index.reset({ namespace: "ns" });
|
|
560
|
+
* console.log('Namespace ns has been reset');
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* If you want to reset all namespaces, call reset like:
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```js
|
|
567
|
+
* await index.reset({ all: true });
|
|
568
|
+
* console.log('All namespaces have been reset');
|
|
503
569
|
* ```
|
|
504
570
|
*
|
|
505
571
|
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
506
572
|
*/
|
|
507
|
-
reset: (options?:
|
|
508
|
-
namespace?: string;
|
|
509
|
-
}) => Promise<string>;
|
|
573
|
+
reset: (options?: ResetCommandOptions) => Promise<string>;
|
|
510
574
|
/**
|
|
511
575
|
* Retrieves a range of items from the index.
|
|
512
576
|
*
|
|
@@ -522,6 +586,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
522
586
|
* console.log(rangeResults); // Outputs the result of the range operation
|
|
523
587
|
* ```
|
|
524
588
|
*
|
|
589
|
+
* You can also pass a namespace like:
|
|
590
|
+
*
|
|
591
|
+
* ```js
|
|
592
|
+
* const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
525
595
|
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
526
596
|
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
527
597
|
* @param {number} args.limit - The maximum number of items to return in this range.
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.1.
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.7", "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 && vitest run --typecheck", "fmt": "prettier --write .", "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix", "build": "tsup", "prepare": "husky install" } }
|
package/dist/chunk-J6ZA44LH.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var E=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,s=null;for(let M=0;M<=this.retry.attempts;M++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(A){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),P={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,P);break}s=A,await new Promise(g=>setTimeout(g,this.retry.backoff(M)))}if(!a)throw s??new Error("Exhausted all retries");let o=await a.json();if(!a.ok)throw new i(`${o.error}`);return{result:o.result,error:o.error}}};var n=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends n{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let s=[];Array.isArray(e)?s.push(...e):s.push(e),super(s,a)}};var f=class extends n{constructor(e,t){let a="query";a=e.some(o=>o.data)?"query-data":"query",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var d=class extends n{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var m=class extends n{constructor(e,t){let a="upsert";Array.isArray(e)?a=e.some(o=>b(o))?"upsert":"upsert-data":a=b(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},b=r=>"vector"in r;var c=class extends n{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends n{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var C=class extends n{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new d(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var y=class extends n{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var x=class extends n{constructor(){super([],"list-namespaces")}};var T=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var R=class{client;constructor(e){this.client=e}namespace=e=>new h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);queryMany=(e,t)=>new f(e,t).exec(this.client);upsert=(e,t)=>new m(e,t).exec(this.client);update=(e,t)=>new y(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new C().exec(this.client);listNamespaces=()=>new x().exec(this.client);deleteNamespace=e=>new T(e).exec(this.client)};export{E as a,R as b};
|