@upstash/vector 1.2.1 → 1.2.3

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.
@@ -31,13 +31,15 @@ var HttpClient = class {
31
31
  };
32
32
  }
33
33
  async request(req) {
34
+ const signal = this.options.signal;
35
+ const isSignalFunction = typeof signal === "function";
34
36
  const requestOptions = {
35
37
  cache: this.options.cache,
36
38
  method: "POST",
37
39
  headers: this.headers,
38
40
  body: JSON.stringify(req.body),
39
41
  keepalive: true,
40
- signal: this.options.signal
42
+ signal: isSignalFunction ? signal() : signal
41
43
  };
42
44
  let res = null;
43
45
  let error = null;
@@ -46,13 +48,15 @@ var HttpClient = class {
46
48
  res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
47
49
  break;
48
50
  } catch (error_) {
49
- if (this.options.signal?.aborted) {
51
+ if (requestOptions.signal?.aborted && isSignalFunction) {
52
+ throw error_;
53
+ } else if (requestOptions.signal?.aborted) {
50
54
  const myBlob = new Blob([
51
- JSON.stringify({ result: this.options.signal.reason ?? "Aborted" })
55
+ JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
52
56
  ]);
53
57
  const myOptions = {
54
58
  status: 200,
55
- statusText: this.options.signal.reason ?? "Aborted"
59
+ statusText: requestOptions.signal.reason ?? "Aborted"
56
60
  };
57
61
  res = new Response(myBlob, myOptions);
58
62
  break;
@@ -119,6 +123,7 @@ var Command = class {
119
123
 
120
124
  // src/commands/client/query/query-many/index.ts
121
125
  var QueryManyCommand = class extends Command {
126
+ queryCount;
122
127
  constructor(payload, options) {
123
128
  let endpoint = "query";
124
129
  const hasData = payload.some((p) => p.data);
@@ -127,6 +132,21 @@ var QueryManyCommand = class extends Command {
127
132
  endpoint = `${endpoint}/${options.namespace}`;
128
133
  }
129
134
  super(payload, endpoint);
135
+ this.queryCount = payload.length;
136
+ }
137
+ /**
138
+ * Override exec to normalize the API response.
139
+ *
140
+ * When a single query is sent via queryMany, the API returns a flat
141
+ * array of results instead of a nested array. This ensures the return
142
+ * type is always QueryResult<TMetadata>[][] regardless of query count.
143
+ */
144
+ async exec(client) {
145
+ const result = await super.exec(client);
146
+ if (this.queryCount === 1 && result.length > 0 && !Array.isArray(result[0])) {
147
+ return [result];
148
+ }
149
+ return result;
130
150
  }
131
151
  };
132
152
 
@@ -855,7 +875,7 @@ var Index = class {
855
875
  };
856
876
 
857
877
  // version.ts
858
- var VERSION = "v1.2.1";
878
+ var VERSION = "1.2.3";
859
879
 
860
880
  export {
861
881
  HttpClient,
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-1qEMEEQL.mjs';
2
- export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, a as Requester, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-1qEMEEQL.mjs';
1
+ import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1 } from './vector-3yYKIF78.mjs';
2
+ export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, a as Requester, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-3yYKIF78.mjs';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -18,7 +18,7 @@ type IndexConfig = {
18
18
  * The signal will allow aborting requests on the fly.
19
19
  * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
20
20
  */
21
- signal?: AbortSignal;
21
+ signal?: HttpClientConfig["signal"];
22
22
  /**
23
23
  * Enable telemetry to help us improve the SDK.
24
24
  * The sdk will send the sdk version, platform and node version as telemetry headers.
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-1qEMEEQL.js';
2
- export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, a as Requester, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-1qEMEEQL.js';
1
+ import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1 } from './vector-3yYKIF78.js';
2
+ export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, a as Requester, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-3yYKIF78.js';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -18,7 +18,7 @@ type IndexConfig = {
18
18
  * The signal will allow aborting requests on the fly.
19
19
  * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
20
20
  */
21
- signal?: AbortSignal;
21
+ signal?: HttpClientConfig["signal"];
22
22
  /**
23
23
  * Enable telemetry to help us improve the SDK.
24
24
  * The sdk will send the sdk version, platform and node version as telemetry headers.
@@ -60,13 +60,15 @@ var HttpClient = class {
60
60
  };
61
61
  }
62
62
  async request(req) {
63
+ const signal = this.options.signal;
64
+ const isSignalFunction = typeof signal === "function";
63
65
  const requestOptions = {
64
66
  cache: this.options.cache,
65
67
  method: "POST",
66
68
  headers: this.headers,
67
69
  body: JSON.stringify(req.body),
68
70
  keepalive: true,
69
- signal: this.options.signal
71
+ signal: isSignalFunction ? signal() : signal
70
72
  };
71
73
  let res = null;
72
74
  let error = null;
@@ -75,13 +77,15 @@ var HttpClient = class {
75
77
  res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
76
78
  break;
77
79
  } catch (error_) {
78
- if (this.options.signal?.aborted) {
80
+ if (requestOptions.signal?.aborted && isSignalFunction) {
81
+ throw error_;
82
+ } else if (requestOptions.signal?.aborted) {
79
83
  const myBlob = new Blob([
80
- JSON.stringify({ result: this.options.signal.reason ?? "Aborted" })
84
+ JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
81
85
  ]);
82
86
  const myOptions = {
83
87
  status: 200,
84
- statusText: this.options.signal.reason ?? "Aborted"
88
+ statusText: requestOptions.signal.reason ?? "Aborted"
85
89
  };
86
90
  res = new Response(myBlob, myOptions);
87
91
  break;
@@ -158,6 +162,7 @@ var DeleteCommand = class extends Command {
158
162
 
159
163
  // src/commands/client/query/query-many/index.ts
160
164
  var QueryManyCommand = class extends Command {
165
+ queryCount;
161
166
  constructor(payload, options) {
162
167
  let endpoint = "query";
163
168
  const hasData = payload.some((p) => p.data);
@@ -166,6 +171,21 @@ var QueryManyCommand = class extends Command {
166
171
  endpoint = `${endpoint}/${options.namespace}`;
167
172
  }
168
173
  super(payload, endpoint);
174
+ this.queryCount = payload.length;
175
+ }
176
+ /**
177
+ * Override exec to normalize the API response.
178
+ *
179
+ * When a single query is sent via queryMany, the API returns a flat
180
+ * array of results instead of a nested array. This ensures the return
181
+ * type is always QueryResult<TMetadata>[][] regardless of query count.
182
+ */
183
+ async exec(client) {
184
+ const result = await super.exec(client);
185
+ if (this.queryCount === 1 && result.length > 0 && !Array.isArray(result[0])) {
186
+ return [result];
187
+ }
188
+ return result;
169
189
  }
170
190
  };
171
191
 
@@ -884,7 +904,7 @@ var Index = class {
884
904
  };
885
905
 
886
906
  // version.ts
887
- var VERSION = "v1.2.1";
907
+ var VERSION = "1.2.3";
888
908
 
889
909
  // src/platforms/cloudflare.ts
890
910
  var Index2 = class _Index extends Index {
@@ -5,7 +5,7 @@ import {
5
5
  QueryMode,
6
6
  VERSION,
7
7
  WeightingStrategy
8
- } from "./chunk-HESEGT2A.mjs";
8
+ } from "./chunk-VZUGHHBV.mjs";
9
9
 
10
10
  // src/platforms/cloudflare.ts
11
11
  var Index2 = class _Index extends Index {
package/dist/nodejs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-1qEMEEQL.mjs';
2
- export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-1qEMEEQL.mjs';
1
+ import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-3yYKIF78.mjs';
2
+ export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-3yYKIF78.mjs';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -18,7 +18,7 @@ type IndexConfig = {
18
18
  * The signal will allow aborting requests on the fly.
19
19
  * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
20
20
  */
21
- signal?: AbortSignal;
21
+ signal?: HttpClientConfig["signal"];
22
22
  /**
23
23
  * Enable telemetry to help us improve the SDK.
24
24
  * The sdk will send the sdk version, platform and node version as telemetry headers.
package/dist/nodejs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-1qEMEEQL.js';
2
- export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-1qEMEEQL.js';
1
+ import { H as HttpClientConfig, R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-3yYKIF78.js';
2
+ export { d as FetchResult, F as FusionAlgorithm, f as InfoResult, Q as QueryMode, e as QueryResult, c as RangeResult, S as SparseVector, U as UpstashRequest, b as UpstashResponse, V as Vector, W as WeightingStrategy } from './vector-3yYKIF78.js';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -18,7 +18,7 @@ type IndexConfig = {
18
18
  * The signal will allow aborting requests on the fly.
19
19
  * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
20
20
  */
21
- signal?: AbortSignal;
21
+ signal?: HttpClientConfig["signal"];
22
22
  /**
23
23
  * Enable telemetry to help us improve the SDK.
24
24
  * The sdk will send the sdk version, platform and node version as telemetry headers.
package/dist/nodejs.js CHANGED
@@ -60,13 +60,15 @@ var HttpClient = class {
60
60
  };
61
61
  }
62
62
  async request(req) {
63
+ const signal = this.options.signal;
64
+ const isSignalFunction = typeof signal === "function";
63
65
  const requestOptions = {
64
66
  cache: this.options.cache,
65
67
  method: "POST",
66
68
  headers: this.headers,
67
69
  body: JSON.stringify(req.body),
68
70
  keepalive: true,
69
- signal: this.options.signal
71
+ signal: isSignalFunction ? signal() : signal
70
72
  };
71
73
  let res = null;
72
74
  let error = null;
@@ -75,13 +77,15 @@ var HttpClient = class {
75
77
  res = await fetch([this.baseUrl, ...req.path ?? []].join("/"), requestOptions);
76
78
  break;
77
79
  } catch (error_) {
78
- if (this.options.signal?.aborted) {
80
+ if (requestOptions.signal?.aborted && isSignalFunction) {
81
+ throw error_;
82
+ } else if (requestOptions.signal?.aborted) {
79
83
  const myBlob = new Blob([
80
- JSON.stringify({ result: this.options.signal.reason ?? "Aborted" })
84
+ JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
81
85
  ]);
82
86
  const myOptions = {
83
87
  status: 200,
84
- statusText: this.options.signal.reason ?? "Aborted"
88
+ statusText: requestOptions.signal.reason ?? "Aborted"
85
89
  };
86
90
  res = new Response(myBlob, myOptions);
87
91
  break;
@@ -158,6 +162,7 @@ var DeleteCommand = class extends Command {
158
162
 
159
163
  // src/commands/client/query/query-many/index.ts
160
164
  var QueryManyCommand = class extends Command {
165
+ queryCount;
161
166
  constructor(payload, options) {
162
167
  let endpoint = "query";
163
168
  const hasData = payload.some((p) => p.data);
@@ -166,6 +171,21 @@ var QueryManyCommand = class extends Command {
166
171
  endpoint = `${endpoint}/${options.namespace}`;
167
172
  }
168
173
  super(payload, endpoint);
174
+ this.queryCount = payload.length;
175
+ }
176
+ /**
177
+ * Override exec to normalize the API response.
178
+ *
179
+ * When a single query is sent via queryMany, the API returns a flat
180
+ * array of results instead of a nested array. This ensures the return
181
+ * type is always QueryResult<TMetadata>[][] regardless of query count.
182
+ */
183
+ async exec(client) {
184
+ const result = await super.exec(client);
185
+ if (this.queryCount === 1 && result.length > 0 && !Array.isArray(result[0])) {
186
+ return [result];
187
+ }
188
+ return result;
169
189
  }
170
190
  };
171
191
 
@@ -884,7 +904,7 @@ var Index = class {
884
904
  };
885
905
 
886
906
  // version.ts
887
- var VERSION = "v1.2.1";
907
+ var VERSION = "1.2.3";
888
908
 
889
909
  // src/utils/get-runtime.ts
890
910
  function getRuntime() {
package/dist/nodejs.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  QueryMode,
6
6
  VERSION,
7
7
  WeightingStrategy
8
- } from "./chunk-HESEGT2A.mjs";
8
+ } from "./chunk-VZUGHHBV.mjs";
9
9
 
10
10
  // src/utils/get-runtime.ts
11
11
  function getRuntime() {
@@ -41,6 +41,12 @@ type RequesterConfig = {
41
41
  */
42
42
  cache?: CacheSetting;
43
43
  };
44
+ type HttpClientConfig = {
45
+ headers?: Record<string, string>;
46
+ baseUrl: string;
47
+ retry?: RetryConfig;
48
+ signal?: AbortSignal | (() => AbortSignal);
49
+ } & RequesterConfig;
44
50
 
45
51
  type Vector<TMetadata = Dict> = {
46
52
  id: string;
@@ -233,7 +239,16 @@ declare enum QueryMode {
233
239
  }
234
240
 
235
241
  declare class QueryManyCommand<TMetadata> extends Command<QueryResult<TMetadata>[][]> {
242
+ private queryCount;
236
243
  constructor(payload: QueryCommandPayload[], options?: QueryCommandOptions);
244
+ /**
245
+ * Override exec to normalize the API response.
246
+ *
247
+ * When a single query is sent via queryMany, the API returns a flat
248
+ * array of results instead of a nested array. This ensures the return
249
+ * type is always QueryResult<TMetadata>[][] regardless of query count.
250
+ */
251
+ exec(client: Requester): Promise<QueryResult<TMetadata>[][]>;
237
252
  }
238
253
 
239
254
  declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
@@ -905,4 +920,4 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
905
920
  deleteNamespace: (namespace: string) => Promise<string>;
906
921
  }
907
922
 
908
- export { type Dict as D, FusionAlgorithm as F, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
923
+ export { type Dict as D, FusionAlgorithm as F, type HttpClientConfig as H, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
@@ -41,6 +41,12 @@ type RequesterConfig = {
41
41
  */
42
42
  cache?: CacheSetting;
43
43
  };
44
+ type HttpClientConfig = {
45
+ headers?: Record<string, string>;
46
+ baseUrl: string;
47
+ retry?: RetryConfig;
48
+ signal?: AbortSignal | (() => AbortSignal);
49
+ } & RequesterConfig;
44
50
 
45
51
  type Vector<TMetadata = Dict> = {
46
52
  id: string;
@@ -233,7 +239,16 @@ declare enum QueryMode {
233
239
  }
234
240
 
235
241
  declare class QueryManyCommand<TMetadata> extends Command<QueryResult<TMetadata>[][]> {
242
+ private queryCount;
236
243
  constructor(payload: QueryCommandPayload[], options?: QueryCommandOptions);
244
+ /**
245
+ * Override exec to normalize the API response.
246
+ *
247
+ * When a single query is sent via queryMany, the API returns a flat
248
+ * array of results instead of a nested array. This ensures the return
249
+ * type is always QueryResult<TMetadata>[][] regardless of query count.
250
+ */
251
+ exec(client: Requester): Promise<QueryResult<TMetadata>[][]>;
237
252
  }
238
253
 
239
254
  declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
@@ -905,4 +920,4 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
905
920
  deleteNamespace: (namespace: string) => Promise<string>;
906
921
  }
907
922
 
908
- export { type Dict as D, FusionAlgorithm as F, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
923
+ export { type Dict as D, FusionAlgorithm as F, type HttpClientConfig as H, Index as I, QueryMode as Q, type RequesterConfig as R, type SparseVector as S, type UpstashRequest as U, type Vector as V, WeightingStrategy as W, type Requester as a, type UpstashResponse as b, type RangeResult as c, type FetchResult as d, type QueryResult as e, type InfoResult as f };
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/vector", "version": "v1.2.1", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "exports": { ".": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "require": "./dist/cloudflare.js" }, "./nodejs": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" } }, "main": "./dist/nodejs.js", "module": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts", "devDependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "bun-types": "latest", "eslint": "9.10.0", "eslint-plugin-unicorn": "^55.0.0", "husky": "^8.0.3", "prettier": "^3.3.3", "tsup": "latest", "typescript": "^5.0.0", "vitest": "^1.2.2" }, "bugs": { "url": "https://github.com/upstash/vector/issues" }, "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "files": [ "dist" ], "homepage": "https://upstash.com/vector", "keywords": [ "vector", "upstash", "db" ], "license": "MIT", "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000", "fmt": "prettier --write .", "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix", "build": "tsup ", "prepare": "husky install" } }
1
+ { "name": "@upstash/vector", "version": "1.2.3", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "git@github.com:upstash/vector-js.git" }, "exports": { ".": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "require": "./dist/cloudflare.js" }, "./nodejs": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" } }, "main": "./dist/nodejs.js", "module": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts", "devDependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "bun-types": "latest", "eslint": "9.10.0", "eslint-plugin-unicorn": "^55.0.0", "husky": "^8.0.3", "prettier": "^3.3.3", "tsup": "latest", "typescript": "^5.0.0", "vitest": "^1.2.2" }, "bugs": { "url": "https://github.com/upstash/vector/issues" }, "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "files": [ "dist" ], "homepage": "https://upstash.com/vector", "keywords": [ "vector", "upstash", "db" ], "license": "MIT", "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000", "fmt": "prettier --write .", "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix", "build": "tsup ", "prepare": "husky install" } }