@upstash/vector 1.1.0 → 1.1.1

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 CHANGED
@@ -149,27 +149,26 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
149
149
  */
150
150
  constructor(client: Requester, namespace: string);
151
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.
152
+ * Upserts (Updates and Inserts) specific items into the index namespace.
153
+ * It's used for adding new items to the index namespace or updating existing ones.
154
154
  *
155
155
  * @example
156
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
- * });
157
+ * const upsertArgs = {
158
+ * id: '123',
159
+ * vector: [0.42, 0.87, ...],
160
+ * metadata: { property1: 'value1', property2: 'value2' }
161
+ * };
162
+ * const upsertResult = await index.namespace("ns").upsert(upsertArgs);
163
+ * console.log(upsertResult); // Outputs the result of the upsert operation
162
164
  * ```
163
165
  *
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.
166
+ * @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
167
+ * @param {number|string} args.id - The unique identifier for the item being upserted.
168
+ * @param {number[]} args.vector - The feature vector associated with the item.
169
+ * @param {Dict} [args.metadata] - Optional metadata to be associated with the item.
171
170
  *
172
- * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
171
+ * @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
173
172
  */
174
173
  upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
175
174
  id: string | number;
@@ -212,32 +211,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
212
211
  vector: number[];
213
212
  data?: undefined;
214
213
  }))[]) => 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
214
  /**
242
215
  * It's used for retrieving specific items from the index namespace, optionally including
243
216
  * their metadata and feature vectors.
@@ -255,9 +228,38 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
255
228
  * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
256
229
  * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
257
230
  * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
231
+ * @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
258
232
  *
259
233
  * @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
234
  */
235
+ fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
236
+ includeMetadata?: boolean | undefined;
237
+ includeVectors?: boolean | undefined;
238
+ namespace?: string | undefined;
239
+ } | undefined) => Promise<FetchResult<TMetadata>[]>;
240
+ /**
241
+ * Queries an index namespace with specified parameters.
242
+ * This method creates and executes a query command on an index based on the provided arguments.
243
+ *
244
+ * @example
245
+ * ```js
246
+ * await index.namespace("ns").query({
247
+ * topK: 3,
248
+ * vector: [ 0.22, 0.66 ],
249
+ * filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
250
+ * });
251
+ * ```
252
+ *
253
+ * @param {Object} args - The arguments for the query command.
254
+ * @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
255
+ * This vector is utilized to find the most relevant items in the index.
256
+ * @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
257
+ * @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.
258
+ * @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
259
+ * @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
260
+ *
261
+ * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
262
+ */
261
263
  query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
262
264
  /**
263
265
  * Deletes a specific item or items from the index namespace by their ID(s). *
@@ -460,6 +462,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
460
462
  fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
461
463
  includeMetadata?: boolean | undefined;
462
464
  includeVectors?: boolean | undefined;
465
+ namespace?: string | undefined;
463
466
  } | undefined) => Promise<FetchResult<TMetadata>[]>;
464
467
  /**
465
468
  * It's used for wiping an entire index.
package/dist/index.d.ts CHANGED
@@ -149,27 +149,26 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
149
149
  */
150
150
  constructor(client: Requester, namespace: string);
151
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.
152
+ * Upserts (Updates and Inserts) specific items into the index namespace.
153
+ * It's used for adding new items to the index namespace or updating existing ones.
154
154
  *
155
155
  * @example
156
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
- * });
157
+ * const upsertArgs = {
158
+ * id: '123',
159
+ * vector: [0.42, 0.87, ...],
160
+ * metadata: { property1: 'value1', property2: 'value2' }
161
+ * };
162
+ * const upsertResult = await index.namespace("ns").upsert(upsertArgs);
163
+ * console.log(upsertResult); // Outputs the result of the upsert operation
162
164
  * ```
163
165
  *
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.
166
+ * @param {CommandArgs<typeof UpsertCommand>} args - The arguments for the upsert command.
167
+ * @param {number|string} args.id - The unique identifier for the item being upserted.
168
+ * @param {number[]} args.vector - The feature vector associated with the item.
169
+ * @param {Dict} [args.metadata] - Optional metadata to be associated with the item.
171
170
  *
172
- * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
171
+ * @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
173
172
  */
174
173
  upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
175
174
  id: string | number;
@@ -212,32 +211,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
212
211
  vector: number[];
213
212
  data?: undefined;
214
213
  }))[]) => 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
214
  /**
242
215
  * It's used for retrieving specific items from the index namespace, optionally including
243
216
  * their metadata and feature vectors.
@@ -255,9 +228,38 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
255
228
  * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
256
229
  * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
257
230
  * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
231
+ * @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
258
232
  *
259
233
  * @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
234
  */
235
+ fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
236
+ includeMetadata?: boolean | undefined;
237
+ includeVectors?: boolean | undefined;
238
+ namespace?: string | undefined;
239
+ } | undefined) => Promise<FetchResult<TMetadata>[]>;
240
+ /**
241
+ * Queries an index namespace with specified parameters.
242
+ * This method creates and executes a query command on an index based on the provided arguments.
243
+ *
244
+ * @example
245
+ * ```js
246
+ * await index.namespace("ns").query({
247
+ * topK: 3,
248
+ * vector: [ 0.22, 0.66 ],
249
+ * filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
250
+ * });
251
+ * ```
252
+ *
253
+ * @param {Object} args - The arguments for the query command.
254
+ * @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
255
+ * This vector is utilized to find the most relevant items in the index.
256
+ * @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
257
+ * @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.
258
+ * @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
259
+ * @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
260
+ *
261
+ * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
262
+ */
261
263
  query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
262
264
  /**
263
265
  * Deletes a specific item or items from the index namespace by their ID(s). *
@@ -460,6 +462,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
460
462
  fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
461
463
  includeMetadata?: boolean | undefined;
462
464
  includeVectors?: boolean | undefined;
465
+ namespace?: string | undefined;
463
466
  } | undefined) => Promise<FetchResult<TMetadata>[]>;
464
467
  /**
465
468
  * It's used for wiping an entire index.
package/dist/index.js CHANGED
@@ -1 +1 @@
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});
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 m=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 d=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]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};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 d(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new m(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 m(e,t).exec(this.client);upsert=(e,t)=>new d(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 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};
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,o=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}o=M,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}if(!a)throw o??new Error("Exhausted all retries");let s=await a.json();if(!a.ok)throw new i(`${s.error}`);return{result:s.result,error:s.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 o=[];Array.isArray(e)?o.push(...e):o.push(e),super(o,a)}};var m=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 d=class extends n{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(s=>"data"in s&&s.data)){a="upsert-data";for(let s of e)!("metadata"in s)&&"data"in s&&(s.metadata={data:s.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]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends n{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var y=class extends n{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new m(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 m(e,t).exec(this.client);upsert=(e,t)=>new d(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 o=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(o)}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.1.0", "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" }
1
+ { "name": "@upstash/vector", "version": "v1.1.1", "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" }