@upstash/vector 1.0.7 → 1.1.0-canary
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/dist/index.d.mts +289 -33
- package/dist/index.d.ts +289 -33
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -42,15 +42,23 @@ type RequesterConfig = {
|
|
|
42
42
|
cache?: CacheSetting;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
type Vector<TMetadata = Dict> = {
|
|
46
|
+
id: string;
|
|
47
|
+
vector: number[];
|
|
48
|
+
metadata?: TMetadata;
|
|
49
|
+
};
|
|
50
|
+
type NAMESPACE = string;
|
|
51
|
+
type Dict = Record<string, unknown>;
|
|
52
|
+
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
|
+
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
47
55
|
/**
|
|
48
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
49
57
|
*/
|
|
50
58
|
declare class Command<TResult> {
|
|
51
|
-
readonly payload:
|
|
59
|
+
readonly payload: Dict | unknown[];
|
|
52
60
|
readonly endpoint: EndpointVariants;
|
|
53
|
-
constructor(command:
|
|
61
|
+
constructor(command: Dict | unknown[], endpoint: EndpointVariants);
|
|
54
62
|
/**
|
|
55
63
|
* Execute the command using a client.
|
|
56
64
|
*/
|
|
@@ -60,17 +68,11 @@ declare class Command<TResult> {
|
|
|
60
68
|
declare class DeleteCommand extends Command<{
|
|
61
69
|
deleted: number;
|
|
62
70
|
}> {
|
|
63
|
-
constructor(id: (number[] | string[]) | number | string
|
|
71
|
+
constructor(id: (number[] | string[]) | number | string, options?: {
|
|
72
|
+
namespace?: string;
|
|
73
|
+
});
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
type Vector<TMetadata = Record<string, unknown>> = {
|
|
67
|
-
id: string;
|
|
68
|
-
vector: number[];
|
|
69
|
-
metadata?: TMetadata;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
type FetchResult<TMetadata = Record<string, unknown>> = Vector<TMetadata> | null;
|
|
73
|
-
|
|
74
76
|
type QueryCommandPayload = {
|
|
75
77
|
topK: number;
|
|
76
78
|
filter?: string;
|
|
@@ -83,43 +85,237 @@ type QueryCommandPayload = {
|
|
|
83
85
|
data: string;
|
|
84
86
|
vector?: never;
|
|
85
87
|
});
|
|
86
|
-
type QueryResult<TMetadata =
|
|
88
|
+
type QueryResult<TMetadata = Dict> = {
|
|
87
89
|
id: number | string;
|
|
88
90
|
score: number;
|
|
89
91
|
vector: number[];
|
|
90
92
|
metadata?: TMetadata;
|
|
91
93
|
};
|
|
94
|
+
type QueryCommandOptions = {
|
|
95
|
+
namespace?: string;
|
|
96
|
+
};
|
|
92
97
|
declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
|
|
93
|
-
constructor(payload: QueryCommandPayload);
|
|
98
|
+
constructor(payload: QueryCommandPayload, options?: QueryCommandOptions);
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
type FetchResult<TMetadata = Dict> = Vector<TMetadata> | null;
|
|
102
|
+
|
|
96
103
|
type RangeCommandPayload = {
|
|
97
104
|
cursor: number | string;
|
|
98
105
|
limit: number;
|
|
99
106
|
includeVectors?: boolean;
|
|
100
107
|
includeMetadata?: boolean;
|
|
101
108
|
};
|
|
102
|
-
type
|
|
109
|
+
type RangeCommandOptions = {
|
|
110
|
+
namespace?: string;
|
|
111
|
+
};
|
|
112
|
+
type RangeResult<TMetadata = Dict> = {
|
|
103
113
|
nextCursor: string;
|
|
104
114
|
vectors: Vector<TMetadata>[];
|
|
105
115
|
};
|
|
106
116
|
declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
107
|
-
constructor(payload: RangeCommandPayload);
|
|
117
|
+
constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
|
|
108
118
|
}
|
|
109
119
|
|
|
120
|
+
type NamespaceTitle = string;
|
|
121
|
+
type NamespaceInfo = {
|
|
122
|
+
vectorCount: number;
|
|
123
|
+
pendingVectorCount: number;
|
|
124
|
+
};
|
|
110
125
|
type InfoResult = {
|
|
111
126
|
vectorCount: number;
|
|
112
127
|
pendingVectorCount: number;
|
|
113
128
|
indexSize: number;
|
|
114
129
|
dimension: number;
|
|
115
130
|
similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
|
|
131
|
+
namespaces: Record<NamespaceTitle, NamespaceInfo>;
|
|
116
132
|
};
|
|
117
133
|
|
|
134
|
+
declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
135
|
+
protected client: Requester;
|
|
136
|
+
protected namespace: string;
|
|
137
|
+
/**
|
|
138
|
+
* Create a new index namespace client
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const index = new Index({
|
|
143
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
144
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const namespace = index.namespace("ns");
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
constructor(client: Requester, namespace: string);
|
|
151
|
+
/**
|
|
152
|
+
* Queries an index namespace with specified parameters.
|
|
153
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```js
|
|
157
|
+
* await index.namespace("ns").query({
|
|
158
|
+
* topK: 3,
|
|
159
|
+
* vector: [ 0.22, 0.66 ],
|
|
160
|
+
* filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @param {Object} args - The arguments for the query command.
|
|
165
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
166
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
167
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
168
|
+
* @param {string} [args.filter] - An optional filter string to be used in the query. The filter string is used to narrow down the query results.
|
|
169
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
170
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
171
|
+
*
|
|
172
|
+
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
173
|
+
*/
|
|
174
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
175
|
+
id: string | number;
|
|
176
|
+
} & ({
|
|
177
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
178
|
+
data: string;
|
|
179
|
+
vector?: undefined;
|
|
180
|
+
} | {
|
|
181
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
182
|
+
data: string;
|
|
183
|
+
vector?: undefined;
|
|
184
|
+
})) | ({
|
|
185
|
+
id: string | number;
|
|
186
|
+
} & ({
|
|
187
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
188
|
+
vector?: number[] | undefined;
|
|
189
|
+
data?: undefined;
|
|
190
|
+
} | {
|
|
191
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
192
|
+
vector: number[];
|
|
193
|
+
data?: undefined;
|
|
194
|
+
})) | ({
|
|
195
|
+
id: string | number;
|
|
196
|
+
} & ({
|
|
197
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
198
|
+
data: string;
|
|
199
|
+
vector?: undefined;
|
|
200
|
+
} | {
|
|
201
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
202
|
+
data: string;
|
|
203
|
+
vector?: undefined;
|
|
204
|
+
}))[] | ({
|
|
205
|
+
id: string | number;
|
|
206
|
+
} & ({
|
|
207
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
208
|
+
vector?: number[] | undefined;
|
|
209
|
+
data?: undefined;
|
|
210
|
+
} | {
|
|
211
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
+
vector: number[];
|
|
213
|
+
data?: undefined;
|
|
214
|
+
}))[]) => Promise<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Upserts (Updates and Inserts) specific items into the index namespace.
|
|
217
|
+
* It's used for adding new items to the index namespace or updating existing ones.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```js
|
|
221
|
+
* const upsertArgs = {
|
|
222
|
+
* id: '123',
|
|
223
|
+
* vector: [0.42, 0.87, ...],
|
|
224
|
+
* metadata: { property1: 'value1', property2: 'value2' }
|
|
225
|
+
* };
|
|
226
|
+
* const upsertResult = await index.namespace("ns").upsert(upsertArgs);
|
|
227
|
+
* console.log(upsertResult); // Outputs the result of the upsert operation
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
|
|
231
|
+
* @param {number|string} args.id - The unique identifier for the item being upserted.
|
|
232
|
+
* @param {number[]} args.vector - The feature vector associated with the item.
|
|
233
|
+
* @param {Dict} [args.metadata] - Optional metadata to be associated with the item.
|
|
234
|
+
*
|
|
235
|
+
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
236
|
+
*/
|
|
237
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
238
|
+
includeMetadata?: boolean | undefined;
|
|
239
|
+
includeVectors?: boolean | undefined;
|
|
240
|
+
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
241
|
+
/**
|
|
242
|
+
* It's used for retrieving specific items from the index namespace, optionally including
|
|
243
|
+
* their metadata and feature vectors.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```js
|
|
247
|
+
* const fetchIds = ['123', '456'];
|
|
248
|
+
* const fetchOptions = { includeMetadata: true, includeVectors: false };
|
|
249
|
+
* const fetchResults = await index.namespace("ns").fetch(fetchIds, fetchOptions);
|
|
250
|
+
* console.log(fetchResults); // Outputs the fetched items
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
254
|
+
* @param {(number[]|string[])} args[0] - An array of IDs of the items to be fetched.
|
|
255
|
+
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
256
|
+
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
257
|
+
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
258
|
+
*
|
|
259
|
+
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
260
|
+
*/
|
|
261
|
+
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
262
|
+
/**
|
|
263
|
+
* Deletes a specific item or items from the index namespace by their ID(s). *
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```js
|
|
267
|
+
* await index.namespace("ns").delete('test-id')
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @param id - List of ids or single id
|
|
271
|
+
* @returns A promise that resolves when the request to delete the index is completed.
|
|
272
|
+
*/
|
|
273
|
+
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
274
|
+
deleted: number;
|
|
275
|
+
}>;
|
|
276
|
+
/**
|
|
277
|
+
* Retrieves a range of items from the index.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```js
|
|
281
|
+
* const rangeArgs = {
|
|
282
|
+
* cursor: 0,
|
|
283
|
+
* limit: 10,
|
|
284
|
+
* includeVectors: true,
|
|
285
|
+
* includeMetadata: false
|
|
286
|
+
* };
|
|
287
|
+
* const rangeResults = await index.namespace("ns").range(rangeArgs);
|
|
288
|
+
* console.log(rangeResults); // Outputs the result of the range operation
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
292
|
+
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
293
|
+
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
294
|
+
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
295
|
+
* @param {boolean} [args.includeMetadata=false] - Optionally include additional metadata of the items in the response.
|
|
296
|
+
*
|
|
297
|
+
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
|
|
298
|
+
*/
|
|
299
|
+
range: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
300
|
+
/**
|
|
301
|
+
* It's used for wiping all the vectors in a index namespace.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```js
|
|
305
|
+
* await index.namespace("ns").reset();
|
|
306
|
+
* console.log('Index namespace has been reset');
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
310
|
+
*/
|
|
311
|
+
reset: () => Promise<string>;
|
|
312
|
+
}
|
|
313
|
+
|
|
118
314
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
119
315
|
/**
|
|
120
316
|
* Serverless vector client for upstash vector db.
|
|
121
317
|
*/
|
|
122
|
-
declare class Index$1<TIndexMetadata extends
|
|
318
|
+
declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
123
319
|
protected client: Requester;
|
|
124
320
|
/**
|
|
125
321
|
* Create a new vector db client
|
|
@@ -133,6 +329,7 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
133
329
|
* ```
|
|
134
330
|
*/
|
|
135
331
|
constructor(client: Requester);
|
|
332
|
+
namespace: (namespace: string) => Namespace<TIndexMetadata>;
|
|
136
333
|
/**
|
|
137
334
|
* Deletes a specific item or items from the index by their ID(s). *
|
|
138
335
|
*
|
|
@@ -144,7 +341,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
144
341
|
* @param id - List of ids or single id
|
|
145
342
|
* @returns A promise that resolves when the request to delete the index is completed.
|
|
146
343
|
*/
|
|
147
|
-
delete: (args: CommandArgs<typeof DeleteCommand
|
|
344
|
+
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
345
|
+
namespace?: string;
|
|
346
|
+
}) => Promise<{
|
|
148
347
|
deleted: number;
|
|
149
348
|
}>;
|
|
150
349
|
/**
|
|
@@ -170,7 +369,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
170
369
|
*
|
|
171
370
|
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
172
371
|
*/
|
|
173
|
-
query: <TMetadata extends
|
|
372
|
+
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>, options?: {
|
|
373
|
+
namespace?: string;
|
|
374
|
+
}) => Promise<QueryResult<TMetadata>[]>;
|
|
174
375
|
/**
|
|
175
376
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
176
377
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -193,23 +394,49 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
193
394
|
*
|
|
194
395
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
195
396
|
*/
|
|
196
|
-
upsert: <TMetadata extends
|
|
197
|
-
id: string | number;
|
|
198
|
-
vector: number[];
|
|
199
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
200
|
-
} | {
|
|
397
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
201
398
|
id: string | number;
|
|
399
|
+
} & ({
|
|
400
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
202
401
|
data: string;
|
|
402
|
+
vector?: undefined;
|
|
403
|
+
} | {
|
|
203
404
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
204
|
-
|
|
405
|
+
data: string;
|
|
406
|
+
vector?: undefined;
|
|
407
|
+
})) | ({
|
|
205
408
|
id: string | number;
|
|
206
|
-
|
|
409
|
+
} & ({
|
|
410
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
411
|
+
vector?: number[] | undefined;
|
|
412
|
+
data?: undefined;
|
|
413
|
+
} | {
|
|
207
414
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
208
|
-
|
|
415
|
+
vector: number[];
|
|
416
|
+
data?: undefined;
|
|
417
|
+
})) | ({
|
|
209
418
|
id: string | number;
|
|
419
|
+
} & ({
|
|
420
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
421
|
+
data: string;
|
|
422
|
+
vector?: undefined;
|
|
423
|
+
} | {
|
|
424
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
210
425
|
data: string;
|
|
426
|
+
vector?: undefined;
|
|
427
|
+
}))[] | ({
|
|
428
|
+
id: string | number;
|
|
429
|
+
} & ({
|
|
430
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
431
|
+
vector?: number[] | undefined;
|
|
432
|
+
data?: undefined;
|
|
433
|
+
} | {
|
|
211
434
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
-
|
|
435
|
+
vector: number[];
|
|
436
|
+
data?: undefined;
|
|
437
|
+
}))[], options?: {
|
|
438
|
+
namespace?: string;
|
|
439
|
+
}) => Promise<string>;
|
|
213
440
|
/**
|
|
214
441
|
* It's used for retrieving specific items from the index, optionally including
|
|
215
442
|
* their metadata and feature vectors.
|
|
@@ -230,7 +457,7 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
230
457
|
*
|
|
231
458
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
232
459
|
*/
|
|
233
|
-
fetch: <TMetadata extends
|
|
460
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
234
461
|
includeMetadata?: boolean | undefined;
|
|
235
462
|
includeVectors?: boolean | undefined;
|
|
236
463
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
@@ -245,7 +472,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
245
472
|
*
|
|
246
473
|
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
247
474
|
*/
|
|
248
|
-
reset: (
|
|
475
|
+
reset: (options?: {
|
|
476
|
+
namespace?: string;
|
|
477
|
+
}) => Promise<string>;
|
|
249
478
|
/**
|
|
250
479
|
* Retrieves a range of items from the index.
|
|
251
480
|
*
|
|
@@ -269,7 +498,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
269
498
|
*
|
|
270
499
|
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
|
|
271
500
|
*/
|
|
272
|
-
range: <TMetadata extends
|
|
501
|
+
range: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof RangeCommand>, options?: {
|
|
502
|
+
namespace?: string;
|
|
503
|
+
}) => Promise<RangeResult<TMetadata>>;
|
|
273
504
|
/**
|
|
274
505
|
* Retrieves info from the index.
|
|
275
506
|
*
|
|
@@ -282,6 +513,31 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
282
513
|
* @returns {Promise<InfoResult>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize, dimension count and similarity algorithm after the command is executed.
|
|
283
514
|
*/
|
|
284
515
|
info: () => Promise<InfoResult>;
|
|
516
|
+
/**
|
|
517
|
+
* List all namespaces in the vector database.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```js
|
|
521
|
+
* const namespaces = await index.listNamespaces();
|
|
522
|
+
* console.log(namespaces); // Outputs the list of namespaces
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* @returns {Promise<string[]>} A promise that resolves with an array of namespaces after the command is executed.
|
|
526
|
+
*/
|
|
527
|
+
listNamespaces: () => Promise<string[]>;
|
|
528
|
+
/**
|
|
529
|
+
* Deletes a namespace from the vector database.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```js
|
|
533
|
+
* await index.deleteNamespace('namespace');
|
|
534
|
+
* console.log('Namespace has been deleted');
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @param {string} namespace - The name of the namespace to be deleted.
|
|
538
|
+
* @returns {Promise<string>} A promise that resolves with the result of the delete operation after the command is executed.
|
|
539
|
+
*/
|
|
540
|
+
deleteNamespace: (namespace: string) => Promise<string>;
|
|
285
541
|
}
|
|
286
542
|
|
|
287
543
|
/**
|
|
@@ -306,7 +562,7 @@ type IndexConfig = {
|
|
|
306
562
|
/**
|
|
307
563
|
* Serverless vector client for upstash.
|
|
308
564
|
*/
|
|
309
|
-
declare class Index<TIndexMetadata extends
|
|
565
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
310
566
|
/**
|
|
311
567
|
* Create a new vector client by providing the url and token
|
|
312
568
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -42,15 +42,23 @@ type RequesterConfig = {
|
|
|
42
42
|
cache?: CacheSetting;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
type Vector<TMetadata = Dict> = {
|
|
46
|
+
id: string;
|
|
47
|
+
vector: number[];
|
|
48
|
+
metadata?: TMetadata;
|
|
49
|
+
};
|
|
50
|
+
type NAMESPACE = string;
|
|
51
|
+
type Dict = Record<string, unknown>;
|
|
52
|
+
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
|
+
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
47
55
|
/**
|
|
48
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
49
57
|
*/
|
|
50
58
|
declare class Command<TResult> {
|
|
51
|
-
readonly payload:
|
|
59
|
+
readonly payload: Dict | unknown[];
|
|
52
60
|
readonly endpoint: EndpointVariants;
|
|
53
|
-
constructor(command:
|
|
61
|
+
constructor(command: Dict | unknown[], endpoint: EndpointVariants);
|
|
54
62
|
/**
|
|
55
63
|
* Execute the command using a client.
|
|
56
64
|
*/
|
|
@@ -60,17 +68,11 @@ declare class Command<TResult> {
|
|
|
60
68
|
declare class DeleteCommand extends Command<{
|
|
61
69
|
deleted: number;
|
|
62
70
|
}> {
|
|
63
|
-
constructor(id: (number[] | string[]) | number | string
|
|
71
|
+
constructor(id: (number[] | string[]) | number | string, options?: {
|
|
72
|
+
namespace?: string;
|
|
73
|
+
});
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
type Vector<TMetadata = Record<string, unknown>> = {
|
|
67
|
-
id: string;
|
|
68
|
-
vector: number[];
|
|
69
|
-
metadata?: TMetadata;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
type FetchResult<TMetadata = Record<string, unknown>> = Vector<TMetadata> | null;
|
|
73
|
-
|
|
74
76
|
type QueryCommandPayload = {
|
|
75
77
|
topK: number;
|
|
76
78
|
filter?: string;
|
|
@@ -83,43 +85,237 @@ type QueryCommandPayload = {
|
|
|
83
85
|
data: string;
|
|
84
86
|
vector?: never;
|
|
85
87
|
});
|
|
86
|
-
type QueryResult<TMetadata =
|
|
88
|
+
type QueryResult<TMetadata = Dict> = {
|
|
87
89
|
id: number | string;
|
|
88
90
|
score: number;
|
|
89
91
|
vector: number[];
|
|
90
92
|
metadata?: TMetadata;
|
|
91
93
|
};
|
|
94
|
+
type QueryCommandOptions = {
|
|
95
|
+
namespace?: string;
|
|
96
|
+
};
|
|
92
97
|
declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
|
|
93
|
-
constructor(payload: QueryCommandPayload);
|
|
98
|
+
constructor(payload: QueryCommandPayload, options?: QueryCommandOptions);
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
type FetchResult<TMetadata = Dict> = Vector<TMetadata> | null;
|
|
102
|
+
|
|
96
103
|
type RangeCommandPayload = {
|
|
97
104
|
cursor: number | string;
|
|
98
105
|
limit: number;
|
|
99
106
|
includeVectors?: boolean;
|
|
100
107
|
includeMetadata?: boolean;
|
|
101
108
|
};
|
|
102
|
-
type
|
|
109
|
+
type RangeCommandOptions = {
|
|
110
|
+
namespace?: string;
|
|
111
|
+
};
|
|
112
|
+
type RangeResult<TMetadata = Dict> = {
|
|
103
113
|
nextCursor: string;
|
|
104
114
|
vectors: Vector<TMetadata>[];
|
|
105
115
|
};
|
|
106
116
|
declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
107
|
-
constructor(payload: RangeCommandPayload);
|
|
117
|
+
constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
|
|
108
118
|
}
|
|
109
119
|
|
|
120
|
+
type NamespaceTitle = string;
|
|
121
|
+
type NamespaceInfo = {
|
|
122
|
+
vectorCount: number;
|
|
123
|
+
pendingVectorCount: number;
|
|
124
|
+
};
|
|
110
125
|
type InfoResult = {
|
|
111
126
|
vectorCount: number;
|
|
112
127
|
pendingVectorCount: number;
|
|
113
128
|
indexSize: number;
|
|
114
129
|
dimension: number;
|
|
115
130
|
similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
|
|
131
|
+
namespaces: Record<NamespaceTitle, NamespaceInfo>;
|
|
116
132
|
};
|
|
117
133
|
|
|
134
|
+
declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
135
|
+
protected client: Requester;
|
|
136
|
+
protected namespace: string;
|
|
137
|
+
/**
|
|
138
|
+
* Create a new index namespace client
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const index = new Index({
|
|
143
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
144
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const namespace = index.namespace("ns");
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
constructor(client: Requester, namespace: string);
|
|
151
|
+
/**
|
|
152
|
+
* Queries an index namespace with specified parameters.
|
|
153
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```js
|
|
157
|
+
* await index.namespace("ns").query({
|
|
158
|
+
* topK: 3,
|
|
159
|
+
* vector: [ 0.22, 0.66 ],
|
|
160
|
+
* filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @param {Object} args - The arguments for the query command.
|
|
165
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
166
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
167
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
168
|
+
* @param {string} [args.filter] - An optional filter string to be used in the query. The filter string is used to narrow down the query results.
|
|
169
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
170
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
171
|
+
*
|
|
172
|
+
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
173
|
+
*/
|
|
174
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
175
|
+
id: string | number;
|
|
176
|
+
} & ({
|
|
177
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
178
|
+
data: string;
|
|
179
|
+
vector?: undefined;
|
|
180
|
+
} | {
|
|
181
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
182
|
+
data: string;
|
|
183
|
+
vector?: undefined;
|
|
184
|
+
})) | ({
|
|
185
|
+
id: string | number;
|
|
186
|
+
} & ({
|
|
187
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
188
|
+
vector?: number[] | undefined;
|
|
189
|
+
data?: undefined;
|
|
190
|
+
} | {
|
|
191
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
192
|
+
vector: number[];
|
|
193
|
+
data?: undefined;
|
|
194
|
+
})) | ({
|
|
195
|
+
id: string | number;
|
|
196
|
+
} & ({
|
|
197
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
198
|
+
data: string;
|
|
199
|
+
vector?: undefined;
|
|
200
|
+
} | {
|
|
201
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
202
|
+
data: string;
|
|
203
|
+
vector?: undefined;
|
|
204
|
+
}))[] | ({
|
|
205
|
+
id: string | number;
|
|
206
|
+
} & ({
|
|
207
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
208
|
+
vector?: number[] | undefined;
|
|
209
|
+
data?: undefined;
|
|
210
|
+
} | {
|
|
211
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
+
vector: number[];
|
|
213
|
+
data?: undefined;
|
|
214
|
+
}))[]) => Promise<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Upserts (Updates and Inserts) specific items into the index namespace.
|
|
217
|
+
* It's used for adding new items to the index namespace or updating existing ones.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```js
|
|
221
|
+
* const upsertArgs = {
|
|
222
|
+
* id: '123',
|
|
223
|
+
* vector: [0.42, 0.87, ...],
|
|
224
|
+
* metadata: { property1: 'value1', property2: 'value2' }
|
|
225
|
+
* };
|
|
226
|
+
* const upsertResult = await index.namespace("ns").upsert(upsertArgs);
|
|
227
|
+
* console.log(upsertResult); // Outputs the result of the upsert operation
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
|
|
231
|
+
* @param {number|string} args.id - The unique identifier for the item being upserted.
|
|
232
|
+
* @param {number[]} args.vector - The feature vector associated with the item.
|
|
233
|
+
* @param {Dict} [args.metadata] - Optional metadata to be associated with the item.
|
|
234
|
+
*
|
|
235
|
+
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
236
|
+
*/
|
|
237
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
238
|
+
includeMetadata?: boolean | undefined;
|
|
239
|
+
includeVectors?: boolean | undefined;
|
|
240
|
+
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
241
|
+
/**
|
|
242
|
+
* It's used for retrieving specific items from the index namespace, optionally including
|
|
243
|
+
* their metadata and feature vectors.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```js
|
|
247
|
+
* const fetchIds = ['123', '456'];
|
|
248
|
+
* const fetchOptions = { includeMetadata: true, includeVectors: false };
|
|
249
|
+
* const fetchResults = await index.namespace("ns").fetch(fetchIds, fetchOptions);
|
|
250
|
+
* console.log(fetchResults); // Outputs the fetched items
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
254
|
+
* @param {(number[]|string[])} args[0] - An array of IDs of the items to be fetched.
|
|
255
|
+
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
256
|
+
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
257
|
+
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
258
|
+
*
|
|
259
|
+
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
260
|
+
*/
|
|
261
|
+
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
262
|
+
/**
|
|
263
|
+
* Deletes a specific item or items from the index namespace by their ID(s). *
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```js
|
|
267
|
+
* await index.namespace("ns").delete('test-id')
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @param id - List of ids or single id
|
|
271
|
+
* @returns A promise that resolves when the request to delete the index is completed.
|
|
272
|
+
*/
|
|
273
|
+
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
274
|
+
deleted: number;
|
|
275
|
+
}>;
|
|
276
|
+
/**
|
|
277
|
+
* Retrieves a range of items from the index.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```js
|
|
281
|
+
* const rangeArgs = {
|
|
282
|
+
* cursor: 0,
|
|
283
|
+
* limit: 10,
|
|
284
|
+
* includeVectors: true,
|
|
285
|
+
* includeMetadata: false
|
|
286
|
+
* };
|
|
287
|
+
* const rangeResults = await index.namespace("ns").range(rangeArgs);
|
|
288
|
+
* console.log(rangeResults); // Outputs the result of the range operation
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
|
|
292
|
+
* @param {number|string} args.cursor - The starting point (cursor) for the range query.
|
|
293
|
+
* @param {number} args.limit - The maximum number of items to return in this range.
|
|
294
|
+
* @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
|
|
295
|
+
* @param {boolean} [args.includeMetadata=false] - Optionally include additional metadata of the items in the response.
|
|
296
|
+
*
|
|
297
|
+
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
|
|
298
|
+
*/
|
|
299
|
+
range: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
300
|
+
/**
|
|
301
|
+
* It's used for wiping all the vectors in a index namespace.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```js
|
|
305
|
+
* await index.namespace("ns").reset();
|
|
306
|
+
* console.log('Index namespace has been reset');
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
310
|
+
*/
|
|
311
|
+
reset: () => Promise<string>;
|
|
312
|
+
}
|
|
313
|
+
|
|
118
314
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
119
315
|
/**
|
|
120
316
|
* Serverless vector client for upstash vector db.
|
|
121
317
|
*/
|
|
122
|
-
declare class Index$1<TIndexMetadata extends
|
|
318
|
+
declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
123
319
|
protected client: Requester;
|
|
124
320
|
/**
|
|
125
321
|
* Create a new vector db client
|
|
@@ -133,6 +329,7 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
133
329
|
* ```
|
|
134
330
|
*/
|
|
135
331
|
constructor(client: Requester);
|
|
332
|
+
namespace: (namespace: string) => Namespace<TIndexMetadata>;
|
|
136
333
|
/**
|
|
137
334
|
* Deletes a specific item or items from the index by their ID(s). *
|
|
138
335
|
*
|
|
@@ -144,7 +341,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
144
341
|
* @param id - List of ids or single id
|
|
145
342
|
* @returns A promise that resolves when the request to delete the index is completed.
|
|
146
343
|
*/
|
|
147
|
-
delete: (args: CommandArgs<typeof DeleteCommand
|
|
344
|
+
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
345
|
+
namespace?: string;
|
|
346
|
+
}) => Promise<{
|
|
148
347
|
deleted: number;
|
|
149
348
|
}>;
|
|
150
349
|
/**
|
|
@@ -170,7 +369,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
170
369
|
*
|
|
171
370
|
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
172
371
|
*/
|
|
173
|
-
query: <TMetadata extends
|
|
372
|
+
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>, options?: {
|
|
373
|
+
namespace?: string;
|
|
374
|
+
}) => Promise<QueryResult<TMetadata>[]>;
|
|
174
375
|
/**
|
|
175
376
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
176
377
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -193,23 +394,49 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
193
394
|
*
|
|
194
395
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
195
396
|
*/
|
|
196
|
-
upsert: <TMetadata extends
|
|
197
|
-
id: string | number;
|
|
198
|
-
vector: number[];
|
|
199
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
200
|
-
} | {
|
|
397
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
201
398
|
id: string | number;
|
|
399
|
+
} & ({
|
|
400
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
202
401
|
data: string;
|
|
402
|
+
vector?: undefined;
|
|
403
|
+
} | {
|
|
203
404
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
204
|
-
|
|
405
|
+
data: string;
|
|
406
|
+
vector?: undefined;
|
|
407
|
+
})) | ({
|
|
205
408
|
id: string | number;
|
|
206
|
-
|
|
409
|
+
} & ({
|
|
410
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
411
|
+
vector?: number[] | undefined;
|
|
412
|
+
data?: undefined;
|
|
413
|
+
} | {
|
|
207
414
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
208
|
-
|
|
415
|
+
vector: number[];
|
|
416
|
+
data?: undefined;
|
|
417
|
+
})) | ({
|
|
209
418
|
id: string | number;
|
|
419
|
+
} & ({
|
|
420
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
421
|
+
data: string;
|
|
422
|
+
vector?: undefined;
|
|
423
|
+
} | {
|
|
424
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
210
425
|
data: string;
|
|
426
|
+
vector?: undefined;
|
|
427
|
+
}))[] | ({
|
|
428
|
+
id: string | number;
|
|
429
|
+
} & ({
|
|
430
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
431
|
+
vector?: number[] | undefined;
|
|
432
|
+
data?: undefined;
|
|
433
|
+
} | {
|
|
211
434
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
-
|
|
435
|
+
vector: number[];
|
|
436
|
+
data?: undefined;
|
|
437
|
+
}))[], options?: {
|
|
438
|
+
namespace?: string;
|
|
439
|
+
}) => Promise<string>;
|
|
213
440
|
/**
|
|
214
441
|
* It's used for retrieving specific items from the index, optionally including
|
|
215
442
|
* their metadata and feature vectors.
|
|
@@ -230,7 +457,7 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
230
457
|
*
|
|
231
458
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
232
459
|
*/
|
|
233
|
-
fetch: <TMetadata extends
|
|
460
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
234
461
|
includeMetadata?: boolean | undefined;
|
|
235
462
|
includeVectors?: boolean | undefined;
|
|
236
463
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
@@ -245,7 +472,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
245
472
|
*
|
|
246
473
|
* @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
|
|
247
474
|
*/
|
|
248
|
-
reset: (
|
|
475
|
+
reset: (options?: {
|
|
476
|
+
namespace?: string;
|
|
477
|
+
}) => Promise<string>;
|
|
249
478
|
/**
|
|
250
479
|
* Retrieves a range of items from the index.
|
|
251
480
|
*
|
|
@@ -269,7 +498,9 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
269
498
|
*
|
|
270
499
|
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
|
|
271
500
|
*/
|
|
272
|
-
range: <TMetadata extends
|
|
501
|
+
range: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof RangeCommand>, options?: {
|
|
502
|
+
namespace?: string;
|
|
503
|
+
}) => Promise<RangeResult<TMetadata>>;
|
|
273
504
|
/**
|
|
274
505
|
* Retrieves info from the index.
|
|
275
506
|
*
|
|
@@ -282,6 +513,31 @@ declare class Index$1<TIndexMetadata extends Record<string, unknown> = Record<st
|
|
|
282
513
|
* @returns {Promise<InfoResult>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize, dimension count and similarity algorithm after the command is executed.
|
|
283
514
|
*/
|
|
284
515
|
info: () => Promise<InfoResult>;
|
|
516
|
+
/**
|
|
517
|
+
* List all namespaces in the vector database.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```js
|
|
521
|
+
* const namespaces = await index.listNamespaces();
|
|
522
|
+
* console.log(namespaces); // Outputs the list of namespaces
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* @returns {Promise<string[]>} A promise that resolves with an array of namespaces after the command is executed.
|
|
526
|
+
*/
|
|
527
|
+
listNamespaces: () => Promise<string[]>;
|
|
528
|
+
/**
|
|
529
|
+
* Deletes a namespace from the vector database.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```js
|
|
533
|
+
* await index.deleteNamespace('namespace');
|
|
534
|
+
* console.log('Namespace has been deleted');
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @param {string} namespace - The name of the namespace to be deleted.
|
|
538
|
+
* @returns {Promise<string>} A promise that resolves with the result of the delete operation after the command is executed.
|
|
539
|
+
*/
|
|
540
|
+
deleteNamespace: (namespace: string) => Promise<string>;
|
|
285
541
|
}
|
|
286
542
|
|
|
287
543
|
/**
|
|
@@ -306,7 +562,7 @@ type IndexConfig = {
|
|
|
306
562
|
/**
|
|
307
563
|
* Serverless vector client for upstash.
|
|
308
564
|
*/
|
|
309
|
-
declare class Index<TIndexMetadata extends
|
|
565
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
310
566
|
/**
|
|
311
567
|
* Create a new vector client by providing the url and token
|
|
312
568
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)R(n,t,{get:e[t],enumerable:!0})},U=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!w.call(n,s)&&s!==t&&R(n,s,{get:()=>e[s],enumerable:!(a=S(e,s))||a.enumerable});return n};var D=n=>U(R({},"__esModule",{value:!0}),n);var I={};N(I,{Index:()=>M});module.exports=D(I);var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var f=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 x=0;x<=this.retry.attempts;x++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(b){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),A={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,A);break}s=b,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}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 r=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 r{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 d=class extends r{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 r{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(o=>"data"in o&&o.data)){a="upsert-data";for(let o of e)!("metadata"in o)&&"data"in o&&(o.metadata={data:o.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends r{constructor([e,t],a){let s="fetch";a?.namespace&&(s=`${s}/${a.namespace}`),super({ids:e,...t},s)}};var l=class extends r{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends r{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var y=class extends r{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);fetch=(...e)=>new c(e,{namespace:this.namespace}).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 T=class extends r{constructor(){super([],"list-namespaces")}};var C=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=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);upsert=(e,t)=>new m(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 y().exec(this.client);listNamespaces=()=>new T().exec(this.client);deleteNamespace=e=>new C(e).exec(this.client)};var M=class n extends E{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let s=new f({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(s)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let a=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new n({...e,url:t,token:a})}};0&&(module.exports={Index});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var f=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 x=0;x<=this.retry.attempts;x++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(M){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),b={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,b);break}s=M,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}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 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";if(Array.isArray(e)){if(e.some(o=>"data"in o&&o.data)){a="upsert-data";for(let o of e)!("metadata"in o)&&"data"in o&&(o.metadata={data:o.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends n{constructor([e,t],a){let s="fetch";a?.namespace&&(s=`${s}/${a.namespace}`),super({ids:e,...t},s)}};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 y=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);fetch=(...e)=>new c(e,{namespace:this.namespace}).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 T=class extends n{constructor(){super([],"list-namespaces")}};var C=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=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);upsert=(e,t)=>new m(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 y().exec(this.client);listNamespaces=()=>new T().exec(this.client);deleteNamespace=e=>new C(e).exec(this.client)};var R=class r extends E{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let s=new f({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(s)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let a=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new r({...e,url:t,token:a})}};export{R as Index};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.0
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.0-canary", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "main": "./dist/index.js", "module": "./dist/index.mjs", "devDependencies": { "@biomejs/biome": "^1.4.1", "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "bun-types": "latest", "husky": "^8.0.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": "bunx biome check --apply ./src", "build": "tsup", "prepare": "husky install" }, "types": "./dist/index.d.ts" }
|