@upstash/vector 1.1.6 → 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.
@@ -0,0 +1,761 @@
1
+ // src/error/index.ts
2
+ var UpstashError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "UpstashError";
6
+ }
7
+ };
8
+
9
+ // src/http/index.ts
10
+ var HttpClient = class {
11
+ baseUrl;
12
+ headers;
13
+ options;
14
+ retry;
15
+ constructor(config) {
16
+ this.options = {
17
+ cache: config.cache,
18
+ signal: config.signal
19
+ };
20
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
21
+ this.headers = {
22
+ "Content-Type": "application/json",
23
+ ...config.headers
24
+ };
25
+ this.retry = typeof config?.retry === "boolean" && config?.retry === false ? {
26
+ attempts: 1,
27
+ backoff: () => 0
28
+ } : {
29
+ attempts: config?.retry?.retries ?? 5,
30
+ backoff: config?.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
31
+ };
32
+ }
33
+ async request(req) {
34
+ const requestOptions = {
35
+ cache: this.options.cache,
36
+ method: "POST",
37
+ headers: this.headers,
38
+ body: JSON.stringify(req.body),
39
+ keepalive: true,
40
+ signal: this.options.signal
41
+ };
42
+ let res = null;
43
+ let error = null;
44
+ for (let i = 0; i <= this.retry.attempts; i++) {
45
+ try {
46
+ res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
47
+ break;
48
+ } catch (error_) {
49
+ if (this.options.signal?.aborted) {
50
+ const myBlob = new Blob([
51
+ JSON.stringify({ result: this.options.signal.reason ?? "Aborted" })
52
+ ]);
53
+ const myOptions = {
54
+ status: 200,
55
+ statusText: this.options.signal.reason ?? "Aborted"
56
+ };
57
+ res = new Response(myBlob, myOptions);
58
+ break;
59
+ }
60
+ error = error_;
61
+ await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
62
+ }
63
+ }
64
+ if (!res) {
65
+ throw error ?? new Error("Exhausted all retries");
66
+ }
67
+ const body = await res.json();
68
+ if (!res.ok) {
69
+ throw new UpstashError(`${body.error}`);
70
+ }
71
+ return { result: body.result, error: body.error };
72
+ }
73
+ };
74
+
75
+ // src/commands/command.ts
76
+ var Command = class {
77
+ payload;
78
+ endpoint;
79
+ constructor(command, endpoint) {
80
+ this.payload = command;
81
+ this.endpoint = endpoint;
82
+ }
83
+ /**
84
+ * Execute the command using a client.
85
+ */
86
+ async exec(client) {
87
+ const { result, error } = await client.request({
88
+ body: this.payload,
89
+ path: [this.endpoint]
90
+ });
91
+ if (error) {
92
+ throw new UpstashError(error);
93
+ }
94
+ if (result === void 0) {
95
+ throw new TypeError("Request did not return a result");
96
+ }
97
+ return result;
98
+ }
99
+ };
100
+
101
+ // src/commands/client/delete/index.ts
102
+ var DeleteCommand = class extends Command {
103
+ constructor(id, options) {
104
+ let endpoint = "delete";
105
+ if (options?.namespace) {
106
+ endpoint = `${endpoint}/${options.namespace}`;
107
+ }
108
+ const finalArr = [];
109
+ if (Array.isArray(id)) {
110
+ finalArr.push(...id);
111
+ } else {
112
+ finalArr.push(id);
113
+ }
114
+ super(finalArr, endpoint);
115
+ }
116
+ };
117
+
118
+ // src/commands/client/query/query-many/index.ts
119
+ var QueryManyCommand = class extends Command {
120
+ constructor(payload, options) {
121
+ let endpoint = "query";
122
+ const hasData = payload.some((p) => p.data);
123
+ endpoint = hasData ? "query-data" : "query";
124
+ if (options?.namespace) {
125
+ endpoint = `${endpoint}/${options.namespace}`;
126
+ }
127
+ super(payload, endpoint);
128
+ }
129
+ };
130
+
131
+ // src/commands/client/query/query-single/index.ts
132
+ var QueryCommand = class extends Command {
133
+ constructor(payload, options) {
134
+ let endpoint = "query";
135
+ if ("data" in payload) {
136
+ endpoint = "query-data";
137
+ }
138
+ if (options?.namespace) {
139
+ endpoint = `${endpoint}/${options.namespace}`;
140
+ }
141
+ super(payload, endpoint);
142
+ }
143
+ };
144
+
145
+ // src/commands/client/upsert/index.ts
146
+ var UpsertCommand = class extends Command {
147
+ constructor(payload, opts) {
148
+ let endpoint = "upsert";
149
+ if (Array.isArray(payload)) {
150
+ const isUpsert = payload.some((p) => isVectorPayload(p));
151
+ endpoint = isUpsert ? "upsert" : "upsert-data";
152
+ } else {
153
+ endpoint = isVectorPayload(payload) ? "upsert" : "upsert-data";
154
+ }
155
+ if (opts?.namespace) {
156
+ endpoint = `${endpoint}/${opts.namespace}`;
157
+ }
158
+ super(payload, endpoint);
159
+ }
160
+ };
161
+ var isVectorPayload = (payload) => {
162
+ return "vector" in payload;
163
+ };
164
+
165
+ // src/commands/client/fetch/index.ts
166
+ var FetchCommand = class extends Command {
167
+ constructor([ids, opts]) {
168
+ let endpoint = "fetch";
169
+ if (opts?.namespace) {
170
+ endpoint = `${endpoint}/${opts.namespace}`;
171
+ delete opts.namespace;
172
+ }
173
+ super({ ids, ...opts }, endpoint);
174
+ }
175
+ };
176
+
177
+ // src/commands/client/range/index.ts
178
+ var RangeCommand = class extends Command {
179
+ constructor(payload, options) {
180
+ let endpoint = "range";
181
+ if (options?.namespace) {
182
+ endpoint = `${endpoint}/${options.namespace}`;
183
+ }
184
+ super(payload, endpoint);
185
+ }
186
+ };
187
+
188
+ // src/commands/client/reset/index.ts
189
+ var ResetCommand = class extends Command {
190
+ constructor(options) {
191
+ let endpoint = "reset";
192
+ if (options?.namespace) {
193
+ endpoint = `${endpoint}/${options.namespace}`;
194
+ } else if (options?.all) {
195
+ endpoint = `${endpoint}?all`;
196
+ }
197
+ super([], endpoint);
198
+ }
199
+ };
200
+
201
+ // src/commands/client/info/index.ts
202
+ var InfoCommand = class extends Command {
203
+ constructor() {
204
+ const endpoint = "info";
205
+ super([], endpoint);
206
+ }
207
+ };
208
+
209
+ // src/commands/client/namespace/index.ts
210
+ var Namespace = class {
211
+ client;
212
+ namespace;
213
+ /**
214
+ * Create a new index namespace client
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * const index = new Index({
219
+ * url: "<UPSTASH_VECTOR_REST_URL>",
220
+ * token: "<UPSTASH_VECTOR_REST_TOKEN>",
221
+ * });
222
+ *
223
+ * const namespace = index.namespace("ns");
224
+ * ```
225
+ */
226
+ constructor(client, namespace) {
227
+ this.client = client;
228
+ this.namespace = namespace;
229
+ }
230
+ /**
231
+ * Upserts (Updates and Inserts) specific items into the index namespace.
232
+ * It's used for adding new items to the index namespace or updating existing ones.
233
+ *
234
+ * @example
235
+ * ```js
236
+ * const upsertArgs = {
237
+ * id: '123',
238
+ * vector: [0.42, 0.87, ...],
239
+ * metadata: { property1: 'value1', property2: 'value2' }
240
+ * };
241
+ * const upsertResult = await index.namespace("ns").upsert(upsertArgs);
242
+ * console.log(upsertResult); // Outputs the result of the upsert operation
243
+ * ```
244
+ *
245
+ * @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
246
+ * @param {number|string} args.id - The unique identifier for the item being upserted.
247
+ * @param {number[]} args.vector - The feature vector associated with the item.
248
+ * @param {Dict} [args.metadata] - Optional metadata to be associated with the item.
249
+ *
250
+ * @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
251
+ */
252
+ upsert = (args) => new UpsertCommand(args, { namespace: this.namespace }).exec(this.client);
253
+ /*
254
+ * Updates specific items in the index.
255
+ * It's used for updating existing items in the index.
256
+ *
257
+ * @example
258
+ * ```js
259
+ * const updateArgs = {
260
+ * id: '123',
261
+ * metadata: { updatedProperty: 'value1' }
262
+ * };
263
+ * const updateResult = await index.update(updateArgs);
264
+ * console.log(updateResult); // Outputs the result of the update operation
265
+ * ```
266
+ *
267
+ * @param {CommandArgs<typeof UpdateCommand>} args - The arguments for the update command.
268
+ * @param {number|string} args.id - The unique identifier for the item being updated.
269
+ * @param {number[]} args.vector - The feature vector associated with the item.
270
+ * @param {Record<string, unknown>} [args.metadata] - Optional metadata to be associated with the item.
271
+ *
272
+ * @returns {Promise<{updated: number}>} A promise that returns the number of items successfully updated.
273
+ */
274
+ update = (args) => new UpdateCommand(args, { namespace: this.namespace }).exec(this.client);
275
+ /**
276
+ * It's used for retrieving specific items from the index namespace, optionally including
277
+ * their metadata and feature vectors.
278
+ *
279
+ * @example
280
+ * ```js
281
+ * const fetchIds = ['123', '456'];
282
+ * const fetchOptions = { includeMetadata: true, includeVectors: false };
283
+ * const fetchResults = await index.namespace("ns").fetch(fetchIds, fetchOptions);
284
+ * console.log(fetchResults); // Outputs the fetched items
285
+ * ```
286
+ *
287
+ * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
288
+ * @param {(number[]|string[])} args[0] - An array of IDs of the items to be fetched.
289
+ * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
290
+ * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
291
+ * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
292
+ * @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
293
+ *
294
+ * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
295
+ */
296
+ fetch = (...args) => {
297
+ if (args[1]) {
298
+ args[1].namespace = this.namespace;
299
+ } else {
300
+ args[1] = { namespace: this.namespace };
301
+ }
302
+ return new FetchCommand(args).exec(this.client);
303
+ };
304
+ /**
305
+ * Queries an index namespace with specified parameters.
306
+ * This method creates and executes a query command on an index based on the provided arguments.
307
+ *
308
+ * @example
309
+ * ```js
310
+ * await index.namespace("ns").query({
311
+ * topK: 3,
312
+ * vector: [ 0.22, 0.66 ],
313
+ * filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
314
+ * });
315
+ * ```
316
+ *
317
+ * @param {Object} args - The arguments for the query command.
318
+ * @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
319
+ * This vector is utilized to find the most relevant items in the index.
320
+ * @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
321
+ * @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.
322
+ * @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
323
+ * @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
324
+ *
325
+ * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
326
+ */
327
+ query = (args) => new QueryCommand(args, { namespace: this.namespace }).exec(this.client);
328
+ /**
329
+ * Deletes a specific item or items from the index namespace by their ID(s). *
330
+ *
331
+ * @example
332
+ * ```js
333
+ * await index.namespace("ns").delete('test-id')
334
+ * // { deleted: 1 }
335
+ * ```
336
+ *
337
+ * @param id - List of ids or single id
338
+ * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
339
+ */
340
+ delete = (args) => new DeleteCommand(args, { namespace: this.namespace }).exec(this.client);
341
+ /**
342
+ * Retrieves a range of items from the index.
343
+ *
344
+ * @example
345
+ * ```js
346
+ * const rangeArgs = {
347
+ * cursor: 0,
348
+ * limit: 10,
349
+ * includeVectors: true,
350
+ * includeMetadata: false
351
+ * };
352
+ * const rangeResults = await index.namespace("ns").range(rangeArgs);
353
+ * console.log(rangeResults); // Outputs the result of the range operation
354
+ * ```
355
+ *
356
+ * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
357
+ * @param {number|string} args.cursor - The starting point (cursor) for the range query.
358
+ * @param {number} args.limit - The maximum number of items to return in this range.
359
+ * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
360
+ * @param {boolean} [args.includeMetadata=false] - Optionally include additional metadata of the items in the response.
361
+ *
362
+ * @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.
363
+ */
364
+ range = (args) => new RangeCommand(args, { namespace: this.namespace }).exec(this.client);
365
+ /**
366
+ * It's used for wiping all the vectors in a index namespace.
367
+ *
368
+ * @example
369
+ * ```js
370
+ * await index.namespace("ns").reset();
371
+ * console.log('Index namespace has been reset');
372
+ * ```
373
+ *
374
+ * @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
375
+ */
376
+ reset = () => new ResetCommand({ namespace: this.namespace }).exec(this.client);
377
+ };
378
+
379
+ // src/commands/client/update/index.ts
380
+ var UpdateCommand = class extends Command {
381
+ constructor(payload, opts) {
382
+ let endpoint = "update";
383
+ if (opts?.namespace) {
384
+ endpoint = `${endpoint}/${opts.namespace}`;
385
+ }
386
+ super(payload, endpoint);
387
+ }
388
+ };
389
+
390
+ // src/commands/client/resumable-query/resume.ts
391
+ var ResumeQueryCommand = class extends Command {
392
+ constructor(payload) {
393
+ super(payload, "resumable-query-next");
394
+ }
395
+ };
396
+
397
+ // src/commands/client/resumable-query/start.ts
398
+ var StartResumableQueryCommand = class extends Command {
399
+ constructor(payload, namespace) {
400
+ let endpoint = "resumable-query";
401
+ if ("data" in payload) {
402
+ endpoint = "resumable-query-data";
403
+ }
404
+ if (namespace) {
405
+ endpoint = `${endpoint}/${namespace}`;
406
+ }
407
+ super(payload, endpoint);
408
+ }
409
+ };
410
+
411
+ // src/commands/client/resumable-query/stop.ts
412
+ var StopResumableQueryCommand = class extends Command {
413
+ constructor(payload) {
414
+ super(payload, "resumable-query-end");
415
+ }
416
+ };
417
+
418
+ // src/commands/client/resumable-query/index.ts
419
+ var ResumableQuery = class {
420
+ uuid;
421
+ start;
422
+ fetchNext;
423
+ stop;
424
+ constructor(payload, client, namespace) {
425
+ this.start = async () => {
426
+ const result = await new StartResumableQueryCommand(payload, namespace).exec(
427
+ client
428
+ );
429
+ this.uuid = result.uuid;
430
+ return result;
431
+ };
432
+ this.fetchNext = (additionalK) => {
433
+ if (!this.uuid) {
434
+ throw new Error(
435
+ "The resumable query has already been stopped. Please start another resumable query."
436
+ );
437
+ }
438
+ return new ResumeQueryCommand({ uuid: this.uuid, additionalK }).exec(client);
439
+ };
440
+ this.stop = async () => {
441
+ if (!this.uuid) {
442
+ throw new Error("Resumable query has not been started. Call start() first.");
443
+ }
444
+ const result = await new StopResumableQueryCommand({ uuid: this.uuid }).exec(client);
445
+ this.uuid = "";
446
+ return result;
447
+ };
448
+ }
449
+ };
450
+
451
+ // src/commands/management/namespaces/list/index.ts
452
+ var ListNamespacesCommand = class extends Command {
453
+ constructor() {
454
+ const endpoint = "list-namespaces";
455
+ super([], endpoint);
456
+ }
457
+ };
458
+
459
+ // src/commands/management/namespaces/delete/index.ts
460
+ var DeleteNamespaceCommand = class extends Command {
461
+ constructor(namespace) {
462
+ const endpoint = `delete-namespace/${namespace}`;
463
+ super([], endpoint);
464
+ }
465
+ };
466
+
467
+ // src/vector.ts
468
+ var Index = class {
469
+ client;
470
+ /**
471
+ * Create a new vector db client
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * const index = new Index({
476
+ * url: "<UPSTASH_VECTOR_REST_URL>",
477
+ * token: "<UPSTASH_VECTOR_REST_TOKEN>",
478
+ * });
479
+ * ```
480
+ */
481
+ constructor(client) {
482
+ this.client = client;
483
+ }
484
+ namespace = (namespace) => new Namespace(this.client, namespace);
485
+ /**
486
+ * Deletes a specific item or items from the index by their ID(s). *
487
+ *
488
+ * @example
489
+ * ```js
490
+ * const result = await index.delete('test-id');
491
+ * // { deleted: 1 }
492
+ * ```
493
+ *
494
+ * @param id - List of ids or single id
495
+ * @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
496
+ */
497
+ delete = (args, options) => new DeleteCommand(args, options).exec(this.client);
498
+ /**
499
+ * Queries an index with specified parameters.
500
+ * This method creates and executes a query command on an index based on the provided arguments.
501
+ *
502
+ * @example
503
+ * ```js
504
+ * await index.query({
505
+ * topK: 3,
506
+ * vector: [ 0.22, 0.66 ],
507
+ * filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
508
+ * });
509
+ * ```
510
+ *
511
+ * @param {Object} args - The arguments for the query command.
512
+ * @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
513
+ * This vector is utilized to find the most relevant items in the index.
514
+ * @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
515
+ * @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.
516
+ * @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
517
+ * @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
518
+ * @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
519
+ *
520
+ * A promise that resolves with an array of query result objects when the request to query the index is completed.
521
+ */
522
+ query = (args, options) => new QueryCommand(args, options).exec(this.client);
523
+ /**
524
+ * Queries an index with specified parameters.
525
+ * This method creates and executes a query command on an index based on the provided arguments.
526
+ *
527
+ * @example
528
+ * ```js
529
+ * await index.queryMany([
530
+ * {
531
+ * topK: 3,
532
+ * vector: [0.22, 0.66],
533
+ * filter: "age >= 23 and (type = 'turtle' OR type = 'cat')",
534
+ * },
535
+ * {
536
+ * topK: 3,
537
+ * vector: [0.45, 0.52],
538
+ * filter: "age >= 27 and (type = 'rabbit' OR type = 'dog')",
539
+ * },
540
+ * ]);
541
+ *
542
+ * ```
543
+ *
544
+ * @param {Object} args - The arguments for the query command.
545
+ * @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
546
+ * This vector is utilized to find the most relevant items in the index.
547
+ * @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
548
+ * @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.
549
+ * @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
550
+ * @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
551
+ * @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
552
+ *
553
+ * A promise that resolves with an array of arrays of query result objects,
554
+ * where each inner array represents a group of results matching a specific query condition.
555
+ */
556
+ queryMany = (args, options) => new QueryManyCommand(args, options).exec(this.client);
557
+ /**
558
+ * Initializes a resumable query operation on the vector database.
559
+ * This method allows for querying large result sets in multiple chunks or implementing pagination.
560
+ *
561
+ * @template TMetadata
562
+ * @param {ResumableQueryPayload} args - The arguments for the resumable query.
563
+ * @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
564
+ * @param {number} args.topK - The number of top results to return in each fetch operation.
565
+ * @param {number[]} args.vector - The query vector used for similarity search.
566
+ * @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
567
+ * @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
568
+ * @param {Object} [options] - Additional options for the query.
569
+ * @param {string} [options.namespace] - The namespace to query within.
570
+ * @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
571
+ * @example
572
+ * const { result, fetchNext, stop } = await index.resumableQuery({
573
+ * maxIdle: 3600,
574
+ * topK: 50,
575
+ * vector: [0.1, 0.2, 0.3, ...],
576
+ * includeMetadata: true,
577
+ * includeVectors: true
578
+ * }, { namespace: 'my-namespace' });
579
+ *
580
+ * const firstBatch = await fetchNext(10);
581
+ * const secondBatch = await fetchNext(10);
582
+ * await stop(); // End the query session
583
+ */
584
+ resumableQuery = async (args, options) => {
585
+ const resumableQuery = new ResumableQuery(args, this.client, options?.namespace);
586
+ const initialQuery = await resumableQuery.start();
587
+ const { fetchNext, stop } = resumableQuery;
588
+ return { fetchNext, stop, result: initialQuery.scores };
589
+ };
590
+ /**
591
+ * Upserts (Updates and Inserts) specific items into the index.
592
+ * It's used for adding new items to the index or updating existing ones.
593
+ *
594
+ * @example
595
+ * ```js
596
+ * const upsertArgs = {
597
+ * id: '123',
598
+ * vector: [0.42, 0.87, ...],
599
+ * metadata: { property1: 'value1', property2: 'value2' }
600
+ * };
601
+ * const upsertResult = await index.upsert(upsertArgs);
602
+ * console.log(upsertResult); // Outputs the result of the upsert operation
603
+ * ```
604
+ *
605
+ * @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
606
+ * @param {number|string} args.id - The unique identifier for the item being upserted.
607
+ * @param {number[]} args.vector - The feature vector associated with the item.
608
+ * @param {Record<string, unknown>} [args.metadata] - Optional metadata to be associated with the item.
609
+ *
610
+ * @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
611
+ */
612
+ upsert = (args, options) => new UpsertCommand(args, options).exec(this.client);
613
+ /*
614
+ * Updates specific items in the index.
615
+ * It's used for updating existing items in the index.
616
+ *
617
+ * @example
618
+ * ```js
619
+ * const updateArgs = {
620
+ * id: '123',
621
+ * vector: [0.42, 0.87, ...],
622
+ * metadata: { property1: 'value1', property2: 'value2' }
623
+ * };
624
+ * const updateResult = await index.update(updateArgs);
625
+ * console.log(updateResult); // Outputs the result of the update operation
626
+ * ```
627
+ *
628
+ * @param {CommandArgs<typeof UpdateCommand>} args - The arguments for the update command.
629
+ * @param {number|string} args.id - The unique identifier for the item being updated.
630
+ * @param {number[]} args.vector - The feature vector associated with the item.
631
+ * @param {Record<string, unknown>} [args.metadata] - Optional metadata to be associated with the item.
632
+ * @param {string} [args.namespace] - The namespace to update the item in.
633
+ *
634
+ * @returns {Promise<{updated: number}>} A promise that returns the number of items successfully updated.
635
+ */
636
+ update = (args, options) => new UpdateCommand(args, options).exec(this.client);
637
+ /**
638
+ * It's used for retrieving specific items from the index, optionally including
639
+ * their metadata and feature vectors.
640
+ *
641
+ * @example
642
+ * ```js
643
+ * const fetchIds = ['123', '456'];
644
+ * const fetchOptions = { includeMetadata: true, includeVectors: false };
645
+ * const fetchResults = await index.fetch(fetchIds, fetchOptions);
646
+ * console.log(fetchResults); // Outputs the fetched items
647
+ * ```
648
+ *
649
+ * @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
650
+ * @param {(number[]|string[])} args - An array of IDs of the items to be fetched.
651
+ * @param {FetchCommandOptions} args - Options for the fetch operation.
652
+ * @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
653
+ * @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
654
+ * @param {boolean} [args.metadataUpdateMode="OVERWRITE"] - Specifies whether to overwrite or patch the metadata values.
655
+ *
656
+ * @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
657
+ */
658
+ fetch = (...args) => new FetchCommand(args).exec(this.client);
659
+ /**
660
+ * It's used for wiping the index.
661
+ *
662
+ * By default, resets the default namespace:
663
+ *
664
+ * @example
665
+ * ```js
666
+ * await index.reset();
667
+ * console.log('Default namespace has been reset');
668
+ * ```
669
+ *
670
+ * To reset a namespace, call reset like:
671
+ *
672
+ * @example
673
+ * ```js
674
+ * await index.reset({ namespace: "ns" });
675
+ * console.log('Namespace ns has been reset');
676
+ * ```
677
+ *
678
+ * If you want to reset all namespaces, call reset like:
679
+ *
680
+ * @example
681
+ * ```js
682
+ * await index.reset({ all: true });
683
+ * console.log('All namespaces have been reset');
684
+ * ```
685
+ *
686
+ * @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
687
+ */
688
+ reset = (options) => new ResetCommand(options).exec(this.client);
689
+ /**
690
+ * Retrieves a range of items from the index.
691
+ *
692
+ * @example
693
+ * ```js
694
+ * const rangeArgs = {
695
+ * cursor: 0,
696
+ * limit: 10,
697
+ * includeVectors: true,
698
+ * includeMetadata: false
699
+ * };
700
+ * const rangeResults = await index.range(rangeArgs);
701
+ * console.log(rangeResults); // Outputs the result of the range operation
702
+ * ```
703
+ *
704
+ * You can also pass a namespace like:
705
+ *
706
+ * ```js
707
+ * const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
708
+ * ```
709
+ *
710
+ * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
711
+ * @param {number|string} args.cursor - The starting point (cursor) for the range query.
712
+ * @param {number} args.limit - The maximum number of items to return in this range.
713
+ * @param {boolean} [args.includeVectors=false] - Optionally include the feature vectors of the items in the response.
714
+ * @param {boolean} [args.includeMetadata=false] - Optionally include additional metadata of the items in the response.
715
+ *
716
+ * @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.
717
+ */
718
+ range = (args, options) => new RangeCommand(args, options).exec(this.client);
719
+ /**
720
+ * Retrieves info from the index.
721
+ *
722
+ * @example
723
+ * ```js
724
+ * const infoResults = await index.info();
725
+ * console.log(infoResults); // Outputs the result of the info operation
726
+ * ```
727
+ *
728
+ * @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.
729
+ */
730
+ info = () => new InfoCommand().exec(this.client);
731
+ /**
732
+ * List all namespaces in the vector database.
733
+ *
734
+ * @example
735
+ * ```js
736
+ * const namespaces = await index.listNamespaces();
737
+ * console.log(namespaces); // Outputs the list of namespaces
738
+ * ```
739
+ *
740
+ * @returns {Promise<string[]>} A promise that resolves with an array of namespaces after the command is executed.
741
+ */
742
+ listNamespaces = () => new ListNamespacesCommand().exec(this.client);
743
+ /**
744
+ * Deletes a namespace from the vector database.
745
+ *
746
+ * @example
747
+ * ```js
748
+ * await index.deleteNamespace('namespace');
749
+ * console.log('Namespace has been deleted');
750
+ * ```
751
+ *
752
+ * @param {string} namespace - The name of the namespace to be deleted.
753
+ * @returns {Promise<string>} A promise that resolves with the result of the delete operation after the command is executed.
754
+ */
755
+ deleteNamespace = (namespace) => new DeleteNamespaceCommand(namespace).exec(this.client);
756
+ };
757
+
758
+ export {
759
+ HttpClient,
760
+ Index
761
+ };