@upstash/vector 0.1.0-alpha-3 → 0.1.0-alpha-5

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
@@ -69,13 +69,13 @@ type QueryCommandPayload = {
69
69
  includeVectors?: boolean;
70
70
  includeMetadata?: boolean;
71
71
  };
72
- type QueryReturnResponse<TMetadata> = {
72
+ type QueryResponse<TMetadata> = {
73
73
  id: number | string;
74
74
  score: number;
75
75
  vector: number[];
76
76
  metadata?: TMetadata;
77
77
  };
78
- declare class QueryCommand<TMetadata> extends Command<QueryReturnResponse<TMetadata>[]> {
78
+ declare class QueryCommand<TMetadata> extends Command<QueryResponse<TMetadata>[]> {
79
79
  constructor(payload: QueryCommandPayload);
80
80
  }
81
81
 
@@ -94,7 +94,7 @@ type Vector<TMetadata> = {
94
94
  metadata?: TMetadata;
95
95
  };
96
96
 
97
- type FetchReturnResponse<TMetadata> = Vector<TMetadata> | null;
97
+ type FetchResponse<TMetadata> = Vector<TMetadata> | null;
98
98
 
99
99
  type RangeCommandPayload = {
100
100
  cursor: number | string;
@@ -102,11 +102,11 @@ type RangeCommandPayload = {
102
102
  includeVectors?: boolean;
103
103
  includeMetadata?: boolean;
104
104
  };
105
- type RangeReturnResponse<TMetadata> = {
105
+ type RangeResponse<TMetadata> = {
106
106
  nextCursor: string;
107
107
  vectors: Vector<TMetadata>[];
108
108
  };
109
- declare class RangeCommand<TMetadata> extends Command<RangeReturnResponse<TMetadata>> {
109
+ declare class RangeCommand<TMetadata> extends Command<RangeResponse<TMetadata>> {
110
110
  constructor(payload: RangeCommandPayload);
111
111
  }
112
112
 
@@ -160,7 +160,7 @@ declare class Index$1 {
160
160
  *
161
161
  * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
162
162
  */
163
- query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryReturnResponse<unknown>[]>;
163
+ query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryResponse<unknown>[]>;
164
164
  /**
165
165
  * Upserts (Updates and Inserts) specific items into the index.
166
166
  * It's used for adding new items to the index or updating existing ones.
@@ -207,7 +207,7 @@ declare class Index$1 {
207
207
  fetch: (ids: string[] | number[], opts: {
208
208
  includeMetadata?: boolean | undefined;
209
209
  includeVectors?: boolean | undefined;
210
- }) => Promise<FetchReturnResponse<unknown>[]>;
210
+ }) => Promise<FetchResponse<unknown>[]>;
211
211
  /**
212
212
  * It's used for wiping an entire index.
213
213
  *
@@ -243,7 +243,7 @@ declare class Index$1 {
243
243
  *
244
244
  * @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.
245
245
  */
246
- range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeReturnResponse<unknown>>;
246
+ range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeResponse<unknown>>;
247
247
  }
248
248
 
249
249
  /**
@@ -311,4 +311,4 @@ declare class Index extends Index$1 {
311
311
  static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
312
312
  }
313
313
 
314
- export { type FetchReturnResponse, Index, type IndexConfig, type QueryReturnResponse, type RangeReturnResponse, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
314
+ export { type FetchResponse as FetchReturnResponse, Index, type IndexConfig, type QueryResponse as QueryReturnResponse, type RangeResponse as RangeReturnResponse, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
package/dist/index.d.ts CHANGED
@@ -69,13 +69,13 @@ type QueryCommandPayload = {
69
69
  includeVectors?: boolean;
70
70
  includeMetadata?: boolean;
71
71
  };
72
- type QueryReturnResponse<TMetadata> = {
72
+ type QueryResponse<TMetadata> = {
73
73
  id: number | string;
74
74
  score: number;
75
75
  vector: number[];
76
76
  metadata?: TMetadata;
77
77
  };
78
- declare class QueryCommand<TMetadata> extends Command<QueryReturnResponse<TMetadata>[]> {
78
+ declare class QueryCommand<TMetadata> extends Command<QueryResponse<TMetadata>[]> {
79
79
  constructor(payload: QueryCommandPayload);
80
80
  }
81
81
 
@@ -94,7 +94,7 @@ type Vector<TMetadata> = {
94
94
  metadata?: TMetadata;
95
95
  };
96
96
 
97
- type FetchReturnResponse<TMetadata> = Vector<TMetadata> | null;
97
+ type FetchResponse<TMetadata> = Vector<TMetadata> | null;
98
98
 
99
99
  type RangeCommandPayload = {
100
100
  cursor: number | string;
@@ -102,11 +102,11 @@ type RangeCommandPayload = {
102
102
  includeVectors?: boolean;
103
103
  includeMetadata?: boolean;
104
104
  };
105
- type RangeReturnResponse<TMetadata> = {
105
+ type RangeResponse<TMetadata> = {
106
106
  nextCursor: string;
107
107
  vectors: Vector<TMetadata>[];
108
108
  };
109
- declare class RangeCommand<TMetadata> extends Command<RangeReturnResponse<TMetadata>> {
109
+ declare class RangeCommand<TMetadata> extends Command<RangeResponse<TMetadata>> {
110
110
  constructor(payload: RangeCommandPayload);
111
111
  }
112
112
 
@@ -160,7 +160,7 @@ declare class Index$1 {
160
160
  *
161
161
  * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
162
162
  */
163
- query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryReturnResponse<unknown>[]>;
163
+ query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryResponse<unknown>[]>;
164
164
  /**
165
165
  * Upserts (Updates and Inserts) specific items into the index.
166
166
  * It's used for adding new items to the index or updating existing ones.
@@ -207,7 +207,7 @@ declare class Index$1 {
207
207
  fetch: (ids: string[] | number[], opts: {
208
208
  includeMetadata?: boolean | undefined;
209
209
  includeVectors?: boolean | undefined;
210
- }) => Promise<FetchReturnResponse<unknown>[]>;
210
+ }) => Promise<FetchResponse<unknown>[]>;
211
211
  /**
212
212
  * It's used for wiping an entire index.
213
213
  *
@@ -243,7 +243,7 @@ declare class Index$1 {
243
243
  *
244
244
  * @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.
245
245
  */
246
- range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeReturnResponse<unknown>>;
246
+ range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeResponse<unknown>>;
247
247
  }
248
248
 
249
249
  /**
@@ -311,4 +311,4 @@ declare class Index extends Index$1 {
311
311
  static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
312
312
  }
313
313
 
314
- export { type FetchReturnResponse, Index, type IndexConfig, type QueryReturnResponse, type RangeReturnResponse, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
314
+ export { type FetchResponse as FetchReturnResponse, Index, type IndexConfig, type QueryResponse as QueryReturnResponse, type RangeResponse as RangeReturnResponse, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var a=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},o=null,f=null;for(let y=0;y<=this.retry.attempts;y++)try{o=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};o=new Response(b,g);break}f=x,await new Promise(b=>setTimeout(b,this.retry.backoff(y)));}if(!o)throw f??new Error("Exhausted all retries");let h=await o.json();if(!o.ok)throw new n(`${h.error}, command was: ${JSON.stringify(e.body)}`);return {result:h.result,error:h.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:o}=await e.request({body:this.payload,path:[this.endpoint]});if(o)throw new n(o);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var i=class extends r{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var p=class extends r{constructor(e){super(e,"query");}};var c=class extends r{constructor(e){super(e,"upsert");}};var u=class extends r{constructor([e,t]){super({ids:e,...t},"fetch");}};var l=class extends r{constructor(e){super(e,"range");}};var m=class extends r{constructor(){super([],"reset");}};var d=class{client;constructor(e){this.client=e;}delete=e=>new i(e).exec(this.client);query=e=>new p(e).exec(this.client);upsert=e=>new c(e).exec(this.client);fetch=(...e)=>new u(e).exec(this.client);reset=()=>new m().exec(this.client);range=e=>new l(e).exec(this.client)};var R=class s extends d{constructor(e){if("request"in e){super(e);return}(e.url.startsWith(" ")||e.url.endsWith(" ")||/\r|\n/.test(e.url))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(e.token.startsWith(" ")||e.token.endsWith(" ")||/\r|\n/.test(e.token))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let t=new a({baseUrl:e.url,retry:e.retry,headers:{authorization:`Bearer ${e.token}`},cache:e.cache||"no-store",signal:e.signal});super(t);}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 o=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:o})}};
3
+ var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var a=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},o=null,f=null;for(let y=0;y<=this.retry.attempts;y++)try{o=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};o=new Response(b,g);break}f=x,await new Promise(b=>setTimeout(b,this.retry.backoff(y)));}if(!o)throw f??new Error("Exhausted all retries");let h=await o.json();if(!o.ok)throw new n(`${h.error}, command was: ${JSON.stringify(e.body)}`);return {result:h.result,error:h.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:o}=await e.request({body:this.payload,path:[this.endpoint]});if(o)throw new n(o);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var i=class extends r{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var p=class extends r{constructor(e){super(e,"query");}};var c=class extends r{constructor(e){super(e,"upsert");}};var l=class extends r{constructor([e,t]){super({ids:e,...t},"fetch");}};var u=class extends r{constructor(e){super(e,"range");}};var m=class extends r{constructor(){super([],"reset");}};var d=class{client;constructor(e){this.client=e;}delete=e=>new i(e).exec(this.client);query=e=>new p(e).exec(this.client);upsert=e=>new c(e).exec(this.client);fetch=(...e)=>new l(e).exec(this.client);reset=()=>new m().exec(this.client);range=e=>new u(e).exec(this.client)};var R=class s extends d{constructor(e){if("request"in e){super(e);return}(e.url.startsWith(" ")||e.url.endsWith(" ")||/\r|\n/.test(e.url))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(e.token.startsWith(" ")||e.token.endsWith(" ")||/\r|\n/.test(e.token))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let t=new a({baseUrl:e.url,retry:e.retry,headers:{authorization:`Bearer ${e.token}`},cache:e.cache||"no-store",signal:e.signal});super(t);}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 o=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:o})}};
4
4
 
5
5
  exports.Index = R;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var a=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},o=null,f=null;for(let y=0;y<=this.retry.attempts;y++)try{o=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};o=new Response(b,g);break}f=x,await new Promise(b=>setTimeout(b,this.retry.backoff(y)));}if(!o)throw f??new Error("Exhausted all retries");let h=await o.json();if(!o.ok)throw new n(`${h.error}, command was: ${JSON.stringify(e.body)}`);return {result:h.result,error:h.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:o}=await e.request({body:this.payload,path:[this.endpoint]});if(o)throw new n(o);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var i=class extends r{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var p=class extends r{constructor(e){super(e,"query");}};var c=class extends r{constructor(e){super(e,"upsert");}};var u=class extends r{constructor([e,t]){super({ids:e,...t},"fetch");}};var l=class extends r{constructor(e){super(e,"range");}};var m=class extends r{constructor(){super([],"reset");}};var d=class{client;constructor(e){this.client=e;}delete=e=>new i(e).exec(this.client);query=e=>new p(e).exec(this.client);upsert=e=>new c(e).exec(this.client);fetch=(...e)=>new u(e).exec(this.client);reset=()=>new m().exec(this.client);range=e=>new l(e).exec(this.client)};var R=class s extends d{constructor(e){if("request"in e){super(e);return}(e.url.startsWith(" ")||e.url.endsWith(" ")||/\r|\n/.test(e.url))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(e.token.startsWith(" ")||e.token.endsWith(" ")||/\r|\n/.test(e.token))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let t=new a({baseUrl:e.url,retry:e.retry,headers:{authorization:`Bearer ${e.token}`},cache:e.cache||"no-store",signal:e.signal});super(t);}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 o=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:o})}};
1
+ var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var a=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},o=null,f=null;for(let y=0;y<=this.retry.attempts;y++)try{o=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};o=new Response(b,g);break}f=x,await new Promise(b=>setTimeout(b,this.retry.backoff(y)));}if(!o)throw f??new Error("Exhausted all retries");let h=await o.json();if(!o.ok)throw new n(`${h.error}, command was: ${JSON.stringify(e.body)}`);return {result:h.result,error:h.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:o}=await e.request({body:this.payload,path:[this.endpoint]});if(o)throw new n(o);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var i=class extends r{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var p=class extends r{constructor(e){super(e,"query");}};var c=class extends r{constructor(e){super(e,"upsert");}};var l=class extends r{constructor([e,t]){super({ids:e,...t},"fetch");}};var u=class extends r{constructor(e){super(e,"range");}};var m=class extends r{constructor(){super([],"reset");}};var d=class{client;constructor(e){this.client=e;}delete=e=>new i(e).exec(this.client);query=e=>new p(e).exec(this.client);upsert=e=>new c(e).exec(this.client);fetch=(...e)=>new l(e).exec(this.client);reset=()=>new m().exec(this.client);range=e=>new u(e).exec(this.client)};var R=class s extends d{constructor(e){if("request"in e){super(e);return}(e.url.startsWith(" ")||e.url.endsWith(" ")||/\r|\n/.test(e.url))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(e.token.startsWith(" ")||e.token.endsWith(" ")||/\r|\n/.test(e.token))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let t=new a({baseUrl:e.url,retry:e.retry,headers:{authorization:`Bearer ${e.token}`},cache:e.cache||"no-store",signal:e.signal});super(t);}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 o=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:o})}};
2
2
 
3
3
  export { R as Index };
package/package.json CHANGED
@@ -3,20 +3,8 @@
3
3
  "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.",
4
4
  "module": "./dist/index.mjs",
5
5
  "main": "./dist/index.js",
6
- "version": "v0.1.0-alpha-3",
7
- "exports": {
8
- ".": {
9
- "import": "./nodejs.js",
10
- "require": "./nodejs.mjs"
11
- },
12
- "./node": {
13
- "import": "./nodejs.js",
14
- "require": "./nodejs.mjs"
15
- },
16
- "./node.js": "./node.js",
17
- "./node.mjs": "./node.mjs"
18
- },
19
- "types": "./nodejs.d.ts",
6
+ "types": "./dist/index.d.ts",
7
+ "version": "v0.1.0-alpha-5",
20
8
  "keywords": [
21
9
  "vector",
22
10
  "upstash",