@upstash/vector 0.1.0-alpha-11 → 0.1.0-alpha-13
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 +10 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ UPSTASH_VECTOR_REST_TOKEN="your_rest_token"
|
|
|
31
31
|
When these environment variables are set, the client constructor does not require any additional arguments.
|
|
32
32
|
|
|
33
33
|
```typescript
|
|
34
|
-
import {
|
|
34
|
+
import { Index } from "@upstash/vector";
|
|
35
35
|
|
|
36
36
|
const index = new Index();
|
|
37
37
|
```
|
|
@@ -97,7 +97,7 @@ if (results[0].metadata) {
|
|
|
97
97
|
// Since we passed the Metadata type parameter above,
|
|
98
98
|
// we can interact with metadata fields without having to
|
|
99
99
|
// do any typecasting.
|
|
100
|
-
const { title, genre, category } =
|
|
100
|
+
const { title, genre, category } = results[0].metadata;
|
|
101
101
|
console.log(`The best match in fantasy was ${title}`)
|
|
102
102
|
}
|
|
103
103
|
```
|
|
@@ -238,6 +238,14 @@ To get statistics of your index, you can use the client like so:
|
|
|
238
238
|
await index.stats(["id-1", "id-2", "id-3"]);
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
+
### Reset
|
|
242
|
+
|
|
243
|
+
To delete everything related with that index:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
await index.reset();
|
|
247
|
+
```
|
|
248
|
+
|
|
241
249
|
## Contributing
|
|
242
250
|
|
|
243
251
|
## Preparing the environment
|
package/dist/index.d.mts
CHANGED
|
@@ -166,7 +166,7 @@ declare class Index$1 {
|
|
|
166
166
|
*
|
|
167
167
|
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
168
168
|
*/
|
|
169
|
-
query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<
|
|
169
|
+
query: <TMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
170
170
|
/**
|
|
171
171
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
172
172
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -210,10 +210,10 @@ declare class Index$1 {
|
|
|
210
210
|
*
|
|
211
211
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
212
212
|
*/
|
|
213
|
-
fetch: (ids: string[] | number[], opts: {
|
|
213
|
+
fetch: <TMetadata>(ids: string[] | number[], opts: {
|
|
214
214
|
includeMetadata?: boolean | undefined;
|
|
215
215
|
includeVectors?: boolean | undefined;
|
|
216
|
-
}) => Promise<FetchResult<
|
|
216
|
+
}) => Promise<FetchResult<TMetadata>[]>;
|
|
217
217
|
/**
|
|
218
218
|
* It's used for wiping an entire index.
|
|
219
219
|
*
|
|
@@ -249,7 +249,7 @@ declare class Index$1 {
|
|
|
249
249
|
*
|
|
250
250
|
* @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.
|
|
251
251
|
*/
|
|
252
|
-
range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<
|
|
252
|
+
range: <TMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
253
253
|
/**
|
|
254
254
|
* Retrieves stats from the index.
|
|
255
255
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ declare class Index$1 {
|
|
|
166
166
|
*
|
|
167
167
|
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
168
168
|
*/
|
|
169
|
-
query: (args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<
|
|
169
|
+
query: <TMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
170
170
|
/**
|
|
171
171
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
172
172
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -210,10 +210,10 @@ declare class Index$1 {
|
|
|
210
210
|
*
|
|
211
211
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
212
212
|
*/
|
|
213
|
-
fetch: (ids: string[] | number[], opts: {
|
|
213
|
+
fetch: <TMetadata>(ids: string[] | number[], opts: {
|
|
214
214
|
includeMetadata?: boolean | undefined;
|
|
215
215
|
includeVectors?: boolean | undefined;
|
|
216
|
-
}) => Promise<FetchResult<
|
|
216
|
+
}) => Promise<FetchResult<TMetadata>[]>;
|
|
217
217
|
/**
|
|
218
218
|
* It's used for wiping an entire index.
|
|
219
219
|
*
|
|
@@ -249,7 +249,7 @@ declare class Index$1 {
|
|
|
249
249
|
*
|
|
250
250
|
* @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.
|
|
251
251
|
*/
|
|
252
|
-
range: (args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<
|
|
252
|
+
range: <TMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
253
253
|
/**
|
|
254
254
|
* Retrieves stats from the index.
|
|
255
255
|
*
|
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 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 R=0;R<=this.retry.attempts;R++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(
|
|
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 R=0;R<=this.retry.attempts;R++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let T=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};r=new Response(T,g);break}a=x,await new Promise(T=>setTimeout(T,this.retry.backoff(R)));}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 m=class extends o{constructor([e,t]){super({ids:e,...t},"fetch");}};var l=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 m(e).exec(this.client);reset=()=>new d().exec(this.client);range=e=>new l(e).exec(this.client);stats=()=>new h().exec(this.client)};var b=class s extends y{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,r=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(!r)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(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 =
|
|
5
|
+
exports.Index = b;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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 R=0;R<=this.retry.attempts;R++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(
|
|
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 R=0;R<=this.retry.attempts;R++)try{r=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(x){if(this.options.signal?.aborted){let T=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),g={status:200,statusText:this.options.signal.reason??"Aborted"};r=new Response(T,g);break}a=x,await new Promise(T=>setTimeout(T,this.retry.backoff(R)));}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 m=class extends o{constructor([e,t]){super({ids:e,...t},"fetch");}};var l=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 m(e).exec(this.client);reset=()=>new d().exec(this.client);range=e=>new l(e).exec(this.client);stats=()=>new h().exec(this.client)};var b=class s extends y{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,r=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(!r)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(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 {
|
|
3
|
+
export { b 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-
|
|
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-13", "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" } }
|