@upstash/vector 1.0.0 → 1.0.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/README.md +2 -2
- package/dist/index.d.mts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +1 -5
- package/dist/index.mjs +1 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -230,12 +230,12 @@ await index.delete("id-to-delete");
|
|
|
230
230
|
await index.delete(["id-1", "id-2", "id-3"]);
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
###
|
|
233
|
+
### Info
|
|
234
234
|
|
|
235
235
|
To get statistics of your index, you can use the client like so:
|
|
236
236
|
|
|
237
237
|
```typescript
|
|
238
|
-
await index.
|
|
238
|
+
await index.info(["id-1", "id-2", "id-3"]);
|
|
239
239
|
```
|
|
240
240
|
|
|
241
241
|
### Reset
|
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,7 @@ type RequesterConfig = {
|
|
|
42
42
|
cache?: CacheSetting;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "
|
|
45
|
+
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info"];
|
|
46
46
|
type EndpointVariants = (typeof ENDPOINTS)[number];
|
|
47
47
|
/**
|
|
48
48
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -110,10 +110,12 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
|
110
110
|
constructor(payload: RangeCommandPayload);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
type
|
|
113
|
+
type InfoResult = {
|
|
114
114
|
vectorCount: number;
|
|
115
115
|
pendingVectorCount: number;
|
|
116
116
|
indexSize: number;
|
|
117
|
+
dimension: number;
|
|
118
|
+
similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
@@ -251,17 +253,17 @@ declare class Index$1 {
|
|
|
251
253
|
*/
|
|
252
254
|
range: <TMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
253
255
|
/**
|
|
254
|
-
* Retrieves
|
|
256
|
+
* Retrieves info from the index.
|
|
255
257
|
*
|
|
256
258
|
* @example
|
|
257
259
|
* ```js
|
|
258
|
-
* const
|
|
259
|
-
* console.log(
|
|
260
|
+
* const infoResults = await index.info();
|
|
261
|
+
* console.log(infoResults); // Outputs the result of the info operation
|
|
260
262
|
* ```
|
|
261
263
|
*
|
|
262
|
-
* @returns {Promise<
|
|
264
|
+
* @returns {Promise<InfoResult>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize, dimension count and similarity algorithm after the command is executed.
|
|
263
265
|
*/
|
|
264
|
-
|
|
266
|
+
info: () => Promise<InfoResult>;
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
/**
|
|
@@ -334,4 +336,4 @@ declare class Index extends Index$1 {
|
|
|
334
336
|
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
export { type FetchResult, Index, type IndexConfig, type
|
|
339
|
+
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ type RequesterConfig = {
|
|
|
42
42
|
cache?: CacheSetting;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "
|
|
45
|
+
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info"];
|
|
46
46
|
type EndpointVariants = (typeof ENDPOINTS)[number];
|
|
47
47
|
/**
|
|
48
48
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -110,10 +110,12 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
|
|
|
110
110
|
constructor(payload: RangeCommandPayload);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
type
|
|
113
|
+
type InfoResult = {
|
|
114
114
|
vectorCount: number;
|
|
115
115
|
pendingVectorCount: number;
|
|
116
116
|
indexSize: number;
|
|
117
|
+
dimension: number;
|
|
118
|
+
similarityFunction: "COSINE" | "EUCLIDEAN" | "DOT_PRODUCT";
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
@@ -251,17 +253,17 @@ declare class Index$1 {
|
|
|
251
253
|
*/
|
|
252
254
|
range: <TMetadata>(args: CommandArgs<typeof RangeCommand>) => Promise<RangeResult<TMetadata>>;
|
|
253
255
|
/**
|
|
254
|
-
* Retrieves
|
|
256
|
+
* Retrieves info from the index.
|
|
255
257
|
*
|
|
256
258
|
* @example
|
|
257
259
|
* ```js
|
|
258
|
-
* const
|
|
259
|
-
* console.log(
|
|
260
|
+
* const infoResults = await index.info();
|
|
261
|
+
* console.log(infoResults); // Outputs the result of the info operation
|
|
260
262
|
* ```
|
|
261
263
|
*
|
|
262
|
-
* @returns {Promise<
|
|
264
|
+
* @returns {Promise<InfoResult>} A promise that resolves with the response containing the vectorCount, pendingVectorCount, indexSize, dimension count and similarity algorithm after the command is executed.
|
|
263
265
|
*/
|
|
264
|
-
|
|
266
|
+
info: () => Promise<InfoResult>;
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
/**
|
|
@@ -334,4 +336,4 @@ declare class Index extends Index$1 {
|
|
|
334
336
|
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
export { type FetchResult, Index, type IndexConfig, type
|
|
339
|
+
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
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(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
|
-
|
|
5
|
-
exports.Index = b;
|
|
1
|
+
"use strict";var b=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var U=(r,e)=>{for(var t in e)b(r,t,{get:e[t],enumerable:!0})},_=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!S.call(r,s)&&s!==t&&b(r,s,{get:()=>e[s],enumerable:!(o=w(e,s))||o.enumerable});return r};var P=r=>_(b({},"__esModule",{value:!0}),r);var A={};U(A,{Index:()=>C});module.exports=P(A);var a=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},o=null,s=null;for(let R=0;R<=this.retry.attempts;R++)try{o=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"};o=new Response(T,g);break}s=x,await new Promise(T=>setTimeout(T,this.retry.backoff(R)))}if(!o)throw s??new Error("Exhausted all retries");let y=await o.json();if(!o.ok)throw new a(`${y.error}, command was: ${JSON.stringify(e.body)}`);return{result:y.result,error:y.error}}};var n=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 a(o);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends n{constructor(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e),super(t,"delete")}};var c=class extends n{constructor(e){super(e,"query")}};var u=class extends n{constructor(e){super(e,"upsert")}};var m=class extends n{constructor([e,t]){super({ids:e,...t},"fetch")}};var l=class extends n{constructor(e){super(e,"range")}};var d=class extends n{constructor(){super([],"reset")}};var h=class extends n{constructor(){super([],"info")}};var f=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);info=()=>new h().exec(this.client)};var C=class r extends f{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,o=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(!o)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(o.startsWith(" ")||o.endsWith(" ")||/\r|\n/.test(o))&&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 i({baseUrl:o,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache: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 o=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!o)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new r({...e,url:t,token:o})}};0&&(module.exports={Index});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
export { b as Index };
|
|
1
|
+
var s=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(C){if(this.options.signal?.aborted){let T=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),x={status:200,statusText:this.options.signal.reason??"Aborted"};r=new Response(T,x);break}a=C,await new Promise(T=>setTimeout(T,this.retry.backoff(R)))}if(!r)throw a??new Error("Exhausted all retries");let y=await r.json();if(!r.ok)throw new s(`${y.error}, command was: ${JSON.stringify(e.body)}`);return{result:y.result,error:y.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 s(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([],"info")}};var f=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);info=()=>new h().exec(this.client)};var b=class n extends f{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 n({...e,url:t,token:r})}};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": "v1.0.
|
|
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": "v1.0.1", "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" } }
|