@upstash/vector 0.1.0-alpha-9 → 0.1.0-alpha-10

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/README.md CHANGED
@@ -33,7 +33,7 @@ When these environment variables are set, the client constructor does not requir
33
33
  ```typescript
34
34
  import { fromEnv } from "@upstash/vector";
35
35
 
36
- const index = fromEnv();
36
+ const index = new Index();
37
37
  ```
38
38
 
39
39
  #### Using a configuration object
@@ -54,24 +54,20 @@ const index = new Index({
54
54
 
55
55
  Upstash vector indexes support operations for working with vector data using operations such as upsert, query, fetch, and delete.
56
56
 
57
- ### Targeting an index
57
+ ### Accessing an index
58
58
 
59
- To perform data operations on an index, you target it using the `index` method.
59
+ To perform data operations on an index, access it using the `index` method.
60
60
 
61
61
  ```typescript
62
- const index = new Index();
63
-
64
62
  // Now perform index operations
65
63
  await index.fetch([1, 2, 3], { includeMetadata: true, includeVectors: true });
66
64
  ```
67
65
 
68
- ### Targeting an index, with metadata typing
66
+ ### Accesing an index, with metadata typing
69
67
 
70
68
  If you are storing metadata alongside your vector values, you can pass a type parameter to `index()` in order to get proper TypeScript typechecking.
71
69
 
72
70
  ```typescript
73
- const index = new Index();
74
-
75
71
  type Metadata = {
76
72
  title: string,
77
73
  genre: 'sci-fi' | 'fantasy' | 'horror' | 'action'
@@ -123,8 +119,6 @@ type UpstashRecord = {
123
119
  To upsert some records, you can use the client like so:
124
120
 
125
121
  ```typescript
126
- const index = new Index();
127
-
128
122
  // Prepare your data. The length of each array
129
123
  // of vector values must match the dimension of
130
124
  // the index where you plan to store them.
@@ -146,8 +140,6 @@ await index.upsert(records);
146
140
  #### Upsert one
147
141
 
148
142
  ```typescript
149
- const index = new Index();
150
-
151
143
  // Prepare your data. The length of each array
152
144
  // of vector values must match the dimension of
153
145
  // the index where you plan to store them.
@@ -245,3 +237,29 @@ To get statistics of your index, you can use the client like so:
245
237
  ```typescript
246
238
  await index.stats(["id-1", "id-2", "id-3"]);
247
239
  ```
240
+
241
+ ## Contributing
242
+
243
+ ## Preparing the environment
244
+
245
+ This project uses [Bun](https://bun.sh/) for packaging and dependency management. Make sure you have the relevant dependencies.
246
+
247
+ You will also need a vector database on [Upstash](https://console.upstash.com/).
248
+
249
+ ```commandline
250
+ curl -fsSL https://bun.sh/install | bash
251
+ ```
252
+
253
+ ## Code Formatting
254
+
255
+ ```bash
256
+ bun run fmt
257
+ ```
258
+
259
+ ## Running tests
260
+
261
+ To run all the tests, make sure you have the relevant environment variables.
262
+
263
+ ```bash
264
+ bun run test
265
+ ```
package/dist/index.d.mts CHANGED
@@ -297,6 +297,11 @@ declare class Index extends Index$1 {
297
297
  * token: "<UPSTASH_VECTOR_REST_TOKEN>",
298
298
  * });
299
299
  * ```
300
+ * OR
301
+ * This will automatically get environment variables from .env file
302
+ * ```typescript
303
+ * const index = new Index();
304
+ * ```
300
305
  */
301
306
  constructor(config: IndexConfig);
302
307
  /**
package/dist/index.d.ts CHANGED
@@ -297,6 +297,11 @@ declare class Index extends Index$1 {
297
297
  * token: "<UPSTASH_VECTOR_REST_TOKEN>",
298
298
  * });
299
299
  * ```
300
+ * OR
301
+ * This will automatically get environment variables from .env file
302
+ * ```typescript
303
+ * const index = new Index();
304
+ * ```
300
305
  */
301
306
  constructor(config: IndexConfig);
302
307
  /**
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},s=null,x=null;for(let f=0;f<=this.retry.attempts;f++)try{s=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(g){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),C={status:200,statusText:this.options.signal.reason??"Aborted"};s=new Response(b,C);break}x=g,await new Promise(b=>setTimeout(b,this.retry.backoff(f)));}if(!s)throw x??new Error("Exhausted all retries");let y=await s.json();if(!s.ok)throw new n(`${y.error}, command was: ${JSON.stringify(e.body)}`);return {result:y.result,error:y.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:s}=await e.request({body:this.payload,path:[this.endpoint]});if(s)throw new n(s);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 extends r{constructor(){super([],"stats");}};var h=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);stats=()=>new d().exec(this.client)};var R=class o extends h{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 s=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!s)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new o({...e,url:t,token:s})}};
3
+ var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var i=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},r=null,a=null;for(let b=0;b<=this.retry.attempts;b++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(g){if(this.options.signal?.aborted){let R=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),C={status:200,statusText:this.options.signal.reason??"Aborted"};r=new Response(R,C);break}a=g,await new Promise(R=>setTimeout(R,this.retry.backoff(b)));}if(!r)throw a??new Error("Exhausted all retries");let f=await r.json();if(!r.ok)throw new n(`${f.error}, command was: ${JSON.stringify(e.body)}`);return {result:f.result,error:f.error}}};var o=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:r}=await e.request({body:this.payload,path:[this.endpoint]});if(r)throw new n(r);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends o{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var c=class extends o{constructor(e){super(e,"query");}};var u=class extends o{constructor(e){super(e,"upsert");}};var l=class extends o{constructor([e,t]){super({ids:e,...t},"fetch");}};var m=class extends o{constructor(e){super(e,"range");}};var d=class extends o{constructor(){super([],"reset");}};var h=class extends o{constructor(){super([],"stats");}};var y=class{client;constructor(e){this.client=e;}delete=e=>new p(e).exec(this.client);query=e=>new c(e).exec(this.client);upsert=e=>new u(e).exec(this.client);fetch=(...e)=>new l(e).exec(this.client);reset=()=>new d().exec(this.client);range=e=>new m(e).exec(this.client);stats=()=>new h().exec(this.client)};var x=class s extends y{constructor(e){if("request"in e){super(e);return}let t=process.env.UPSTASH_VECTOR_TOKEN??e.token,r=process.env.UPSTASH_VECTOR_REST_URL??e.url;(r.startsWith(" ")||r.endsWith(" ")||/\r|\n/.test(r))&&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 a=new i({baseUrl:r,retry:e.retry,headers:{authorization:`Bearer ${t}`},cache:e.cache||"no-store",signal:e.signal});super(a);}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 r=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!r)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:r})}};
4
4
 
5
- exports.Index = R;
5
+ exports.Index = x;
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},s=null,x=null;for(let f=0;f<=this.retry.attempts;f++)try{s=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(g){if(this.options.signal?.aborted){let b=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),C={status:200,statusText:this.options.signal.reason??"Aborted"};s=new Response(b,C);break}x=g,await new Promise(b=>setTimeout(b,this.retry.backoff(f)));}if(!s)throw x??new Error("Exhausted all retries");let y=await s.json();if(!s.ok)throw new n(`${y.error}, command was: ${JSON.stringify(e.body)}`);return {result:y.result,error:y.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:s}=await e.request({body:this.payload,path:[this.endpoint]});if(s)throw new n(s);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 extends r{constructor(){super([],"stats");}};var h=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);stats=()=>new d().exec(this.client)};var R=class o extends h{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 s=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!s)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new o({...e,url:t,token:s})}};
1
+ var n=class extends Error{constructor(e){super(e),this.name="UpstashError";}};var i=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},r=null,a=null;for(let b=0;b<=this.retry.attempts;b++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(g){if(this.options.signal?.aborted){let R=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),C={status:200,statusText:this.options.signal.reason??"Aborted"};r=new Response(R,C);break}a=g,await new Promise(R=>setTimeout(R,this.retry.backoff(b)));}if(!r)throw a??new Error("Exhausted all retries");let f=await r.json();if(!r.ok)throw new n(`${f.error}, command was: ${JSON.stringify(e.body)}`);return {result:f.result,error:f.error}}};var o=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t;}async exec(e){let{result:t,error:r}=await e.request({body:this.payload,path:[this.endpoint]});if(r)throw new n(r);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends o{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete");}};var c=class extends o{constructor(e){super(e,"query");}};var u=class extends o{constructor(e){super(e,"upsert");}};var l=class extends o{constructor([e,t]){super({ids:e,...t},"fetch");}};var m=class extends o{constructor(e){super(e,"range");}};var d=class extends o{constructor(){super([],"reset");}};var h=class extends o{constructor(){super([],"stats");}};var y=class{client;constructor(e){this.client=e;}delete=e=>new p(e).exec(this.client);query=e=>new c(e).exec(this.client);upsert=e=>new u(e).exec(this.client);fetch=(...e)=>new l(e).exec(this.client);reset=()=>new d().exec(this.client);range=e=>new m(e).exec(this.client);stats=()=>new h().exec(this.client)};var x=class s extends y{constructor(e){if("request"in e){super(e);return}let t=process.env.UPSTASH_VECTOR_TOKEN??e.token,r=process.env.UPSTASH_VECTOR_REST_URL??e.url;(r.startsWith(" ")||r.endsWith(" ")||/\r|\n/.test(r))&&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 a=new i({baseUrl:r,retry:e.retry,headers:{authorization:`Bearer ${t}`},cache:e.cache||"no-store",signal:e.signal});super(a);}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 r=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!r)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new s({...e,url:t,token:r})}};
2
2
 
3
- export { R as Index };
3
+ export { x as Index };
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/vector", "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "module": "./dist/index.mjs", "main": "./dist/index.js", "types": "./dist/index.d.ts", "version": "v0.1.0-alpha-9", "keywords": [ "vector", "upstash", "db" ], "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "license": "MIT", "files": [ "dist" ], "bugs": { "url": "https://github.com/upstash/vector/issues" }, "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts]", "fmt": "bunx biome check --apply ./src", "build": "tsup", "prepare": "husky install" }, "devDependencies": { "typescript": "^5.0.0", "@biomejs/biome": "^1.4.1", "bun-types": "latest", "husky": "^8.0.3", "tsup": "latest" } }
1
+ { "name": "@upstash/vector", "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "module": "./dist/index.mjs", "main": "./dist/index.js", "types": "./dist/index.d.ts", "version": "v0.1.0-alpha-10", "keywords": [ "vector", "upstash", "db" ], "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "license": "MIT", "files": [ "dist" ], "bugs": { "url": "https://github.com/upstash/vector/issues" }, "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts]", "fmt": "bunx biome check --apply ./src", "build": "tsup", "prepare": "husky install" }, "devDependencies": { "typescript": "^5.0.0", "@biomejs/biome": "^1.4.1", "bun-types": "latest", "husky": "^8.0.3", "tsup": "latest" } }