@upstash/vector 1.1.0 → 1.1.1-cf-canary
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/chunk-HLW45HVB.mjs +1 -0
- package/dist/cloudflare.d.mts +59 -0
- package/dist/cloudflare.d.ts +59 -0
- package/dist/cloudflare.js +1 -0
- package/dist/cloudflare.mjs +1 -0
- package/dist/nodejs.d.mts +74 -0
- package/dist/nodejs.d.ts +74 -0
- package/dist/nodejs.js +1 -0
- package/dist/nodejs.mjs +1 -0
- package/dist/{index.d.mts → vector-fCHAzBG_.d.mts} +82 -171
- package/dist/{index.d.ts → vector-fCHAzBG_.d.ts} +82 -171
- package/package.json +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var M=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 g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(b){if(this.options.signal?.aborted){let T=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),R={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(T,R);break}o=b,await new Promise(T=>setTimeout(T,this.retry.backoff(g)))}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 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(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 f=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);update=e=>new y(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 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 y=class extends n{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var C=class extends n{constructor(){super([],"list-namespaces")}};var x=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);update=(e,t)=>new y(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 f().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(e).exec(this.client)};export{M as a,E as b};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-fCHAzBG_.mjs';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, a as Requester, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfigCloudflare = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfigCloudflare);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
46
|
+
*
|
|
47
|
+
* Use this to automatically load connection secrets from your environment
|
|
48
|
+
* variables. For instance when using the Vercel integration.
|
|
49
|
+
*
|
|
50
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
51
|
+
* your environment using `process.env`.
|
|
52
|
+
*/
|
|
53
|
+
static fromEnv(env?: {
|
|
54
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
55
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
56
|
+
}, config?: Omit<IndexConfigCloudflare, "url" | "token">): Index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Index, type IndexConfigCloudflare };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-fCHAzBG_.js';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, a as Requester, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfigCloudflare = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfigCloudflare);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
46
|
+
*
|
|
47
|
+
* Use this to automatically load connection secrets from your environment
|
|
48
|
+
* variables. For instance when using the Vercel integration.
|
|
49
|
+
*
|
|
50
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
51
|
+
* your environment using `process.env`.
|
|
52
|
+
*/
|
|
53
|
+
static fromEnv(env?: {
|
|
54
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
55
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
56
|
+
}, config?: Omit<IndexConfigCloudflare, "url" | "token">): Index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Index, type IndexConfigCloudflare };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var M=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},V=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!w.call(n,s)&&s!==t&&M(n,s,{get:()=>e[s],enumerable:!(a=U(e,s))||a.enumerable});return n};var _=n=>V(M({},"__esModule",{value:!0}),n);var O={};N(O,{Index:()=>S});module.exports=_(O);var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var T=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(A){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=A,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]){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 f=class extends r{constructor(){super([],"info")}};var C=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(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 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 y=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var h=class extends r{constructor(){super([],"list-namespaces")}};var E=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var R=class{client;constructor(e){this.client=e}namespace=e=>new C(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);update=(e,t)=>new y(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 f().exec(this.client);listNamespaces=()=>new h().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var S=class n extends R{constructor(e){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 T({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},signal:e?.signal});super(s)}static fromEnv(e,t){let a=e?.UPSTASH_VECTOR_REST_URL??UPSTASH_VECTOR_REST_URL;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");let s=e?.UPSTASH_VECTOR_REST_TOKEN??UPSTASH_VECTOR_REST_TOKEN;if(!s)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`");return new n({...t,url:a,token:s})}};0&&(module.exports={Index});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s,b as o}from"./chunk-HLW45HVB.mjs";var T=class i extends o{constructor(r){let t=r?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,e=r?.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(!e)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(e.startsWith(" ")||e.endsWith(" ")||/\r|\n/.test(e))&&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 n=new s({baseUrl:e,retry:r?.retry,headers:{authorization:`Bearer ${t}`},signal:r?.signal});super(n)}static fromEnv(r,t){let e=r?.UPSTASH_VECTOR_REST_URL??UPSTASH_VECTOR_REST_URL;if(!e)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");let n=r?.UPSTASH_VECTOR_REST_TOKEN??UPSTASH_VECTOR_REST_TOKEN;if(!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`");return new i({...t,url:e,token:n})}};export{T as Index};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-fCHAzBG_.mjs';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new vector client by providing a custom `Requester` implementation
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
*
|
|
50
|
+
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
51
|
+
*
|
|
52
|
+
* const requester: Requester = {
|
|
53
|
+
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* const vector = new vector(requester)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(requesters?: Requester);
|
|
62
|
+
/**
|
|
63
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
64
|
+
*
|
|
65
|
+
* Use this to automatically load connection secrets from your environment
|
|
66
|
+
* variables. For instance when using the Vercel integration.
|
|
67
|
+
*
|
|
68
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
69
|
+
* your environment using `process.env`.
|
|
70
|
+
*/
|
|
71
|
+
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-fCHAzBG_.js';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new vector client by providing a custom `Requester` implementation
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
*
|
|
50
|
+
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
51
|
+
*
|
|
52
|
+
* const requester: Requester = {
|
|
53
|
+
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* const vector = new vector(requester)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(requesters?: Requester);
|
|
62
|
+
/**
|
|
63
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
64
|
+
*
|
|
65
|
+
* Use this to automatically load connection secrets from your environment
|
|
66
|
+
* variables. For instance when using the Vercel integration.
|
|
67
|
+
*
|
|
68
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
69
|
+
* your environment using `process.env`.
|
|
70
|
+
*/
|
|
71
|
+
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.js
ADDED
|
@@ -0,0 +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})},D=(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 V=n=>D(R({},"__esModule",{value:!0}),n);var _={};N(_,{Index:()=>b});module.exports=V(_);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 g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(A){if(this.options.signal?.aborted){let M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),U={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,U);break}s=A,await new Promise(M=>setTimeout(M,this.retry.backoff(g)))}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]){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 T=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);update=e=>new y(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 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 y=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var C=class extends r{constructor(){super([],"list-namespaces")}};var x=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);update=(e,t)=>new y(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 T().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(e).exec(this.client)};var b=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/nodejs.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r,b as s}from"./chunk-HLW45HVB.mjs";var o=class i extends s{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,n=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(!n)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(n.startsWith(" ")||n.endsWith(" ")||/\r|\n/.test(n))&&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 r({baseUrl:n,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0: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 n=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new i({...e,url:t,token:n})}};export{o as Index};
|
|
@@ -50,7 +50,7 @@ type Vector<TMetadata = Dict> = {
|
|
|
50
50
|
type NAMESPACE = string;
|
|
51
51
|
type Dict = Record<string, unknown>;
|
|
52
52
|
|
|
53
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
54
|
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
55
55
|
/**
|
|
56
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -148,70 +148,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
constructor(client: Requester, namespace: string);
|
|
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.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
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
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
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.
|
|
171
|
-
*
|
|
172
|
-
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
173
|
-
*/
|
|
174
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
175
|
-
id: string | number;
|
|
176
|
-
} & ({
|
|
177
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
178
|
-
data: string;
|
|
179
|
-
vector?: undefined;
|
|
180
|
-
} | {
|
|
181
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
182
|
-
data: string;
|
|
183
|
-
vector?: undefined;
|
|
184
|
-
})) | ({
|
|
185
|
-
id: string | number;
|
|
186
|
-
} & ({
|
|
187
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
188
|
-
vector?: number[] | undefined;
|
|
189
|
-
data?: undefined;
|
|
190
|
-
} | {
|
|
191
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
192
|
-
vector: number[];
|
|
193
|
-
data?: undefined;
|
|
194
|
-
})) | ({
|
|
195
|
-
id: string | number;
|
|
196
|
-
} & ({
|
|
197
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
198
|
-
data: string;
|
|
199
|
-
vector?: undefined;
|
|
200
|
-
} | {
|
|
201
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
202
|
-
data: string;
|
|
203
|
-
vector?: undefined;
|
|
204
|
-
}))[] | ({
|
|
205
|
-
id: string | number;
|
|
206
|
-
} & ({
|
|
207
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
208
|
-
vector?: number[] | undefined;
|
|
209
|
-
data?: undefined;
|
|
210
|
-
} | {
|
|
211
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
-
vector: number[];
|
|
213
|
-
data?: undefined;
|
|
214
|
-
}))[]) => Promise<string>;
|
|
215
151
|
/**
|
|
216
152
|
* Upserts (Updates and Inserts) specific items into the index namespace.
|
|
217
153
|
* It's used for adding new items to the index namespace or updating existing ones.
|
|
@@ -234,10 +170,35 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
234
170
|
*
|
|
235
171
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
236
172
|
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
173
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
174
|
+
id: string | number;
|
|
175
|
+
vector: number[];
|
|
176
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
177
|
+
} | {
|
|
178
|
+
id: string | number;
|
|
179
|
+
data: string;
|
|
180
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
181
|
+
} | {
|
|
182
|
+
id: string | number;
|
|
183
|
+
vector: number[];
|
|
184
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
185
|
+
}[] | {
|
|
186
|
+
id: string | number;
|
|
187
|
+
data: string;
|
|
188
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
189
|
+
}[]) => Promise<string>;
|
|
190
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
191
|
+
id: string | number;
|
|
192
|
+
vector: number[];
|
|
193
|
+
} | {
|
|
194
|
+
id: string | number;
|
|
195
|
+
data: string;
|
|
196
|
+
} | {
|
|
197
|
+
id: string | number;
|
|
198
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
199
|
+
}) => Promise<{
|
|
200
|
+
updated: number;
|
|
201
|
+
}>;
|
|
241
202
|
/**
|
|
242
203
|
* It's used for retrieving specific items from the index namespace, optionally including
|
|
243
204
|
* their metadata and feature vectors.
|
|
@@ -255,9 +216,38 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
255
216
|
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
256
217
|
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
257
218
|
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
219
|
+
* @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
|
|
258
220
|
*
|
|
259
221
|
* @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
222
|
*/
|
|
223
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
224
|
+
includeMetadata?: boolean | undefined;
|
|
225
|
+
includeVectors?: boolean | undefined;
|
|
226
|
+
namespace?: string | undefined;
|
|
227
|
+
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
228
|
+
/**
|
|
229
|
+
* Queries an index namespace with specified parameters.
|
|
230
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```js
|
|
234
|
+
* await index.namespace("ns").query({
|
|
235
|
+
* topK: 3,
|
|
236
|
+
* vector: [ 0.22, 0.66 ],
|
|
237
|
+
* filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @param {Object} args - The arguments for the query command.
|
|
242
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
243
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
244
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
245
|
+
* @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.
|
|
246
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
247
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
248
|
+
*
|
|
249
|
+
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
250
|
+
*/
|
|
261
251
|
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
262
252
|
/**
|
|
263
253
|
* Deletes a specific item or items from the index namespace by their ID(s). *
|
|
@@ -315,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
315
305
|
/**
|
|
316
306
|
* Serverless vector client for upstash vector db.
|
|
317
307
|
*/
|
|
318
|
-
declare class Index
|
|
308
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
319
309
|
protected client: Requester;
|
|
320
310
|
/**
|
|
321
311
|
* Create a new vector db client
|
|
@@ -394,49 +384,39 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
394
384
|
*
|
|
395
385
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
396
386
|
*/
|
|
397
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
387
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
388
|
+
id: string | number;
|
|
389
|
+
vector: number[];
|
|
390
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
391
|
+
} | {
|
|
398
392
|
id: string | number;
|
|
399
|
-
} & ({
|
|
400
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
401
393
|
data: string;
|
|
402
|
-
|
|
394
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
395
|
} | {
|
|
396
|
+
id: string | number;
|
|
397
|
+
vector: number[];
|
|
404
398
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
405
|
-
|
|
406
|
-
vector?: undefined;
|
|
407
|
-
})) | ({
|
|
399
|
+
}[] | {
|
|
408
400
|
id: string | number;
|
|
409
|
-
|
|
410
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
411
|
-
vector?: number[] | undefined;
|
|
412
|
-
data?: undefined;
|
|
413
|
-
} | {
|
|
401
|
+
data: string;
|
|
414
402
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
|
+
}[], options?: {
|
|
404
|
+
namespace?: string;
|
|
405
|
+
}) => Promise<string>;
|
|
406
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
407
|
+
id: string | number;
|
|
415
408
|
vector: number[];
|
|
416
|
-
|
|
417
|
-
})) | ({
|
|
409
|
+
} | {
|
|
418
410
|
id: string | number;
|
|
419
|
-
} & ({
|
|
420
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
421
411
|
data: string;
|
|
422
|
-
vector?: undefined;
|
|
423
412
|
} | {
|
|
424
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
425
|
-
data: string;
|
|
426
|
-
vector?: undefined;
|
|
427
|
-
}))[] | ({
|
|
428
413
|
id: string | number;
|
|
429
|
-
} & ({
|
|
430
414
|
metadata: TMetadata extends infer U ? U : never;
|
|
431
|
-
|
|
432
|
-
data?: undefined;
|
|
433
|
-
} | {
|
|
434
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
435
|
-
vector: number[];
|
|
436
|
-
data?: undefined;
|
|
437
|
-
}))[], options?: {
|
|
415
|
+
}, options?: {
|
|
438
416
|
namespace?: string;
|
|
439
|
-
}) => Promise<
|
|
417
|
+
}) => Promise<{
|
|
418
|
+
updated: number;
|
|
419
|
+
}>;
|
|
440
420
|
/**
|
|
441
421
|
* It's used for retrieving specific items from the index, optionally including
|
|
442
422
|
* their metadata and feature vectors.
|
|
@@ -460,6 +440,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
460
440
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
461
441
|
includeMetadata?: boolean | undefined;
|
|
462
442
|
includeVectors?: boolean | undefined;
|
|
443
|
+
namespace?: string | undefined;
|
|
463
444
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
464
445
|
/**
|
|
465
446
|
* It's used for wiping an entire index.
|
|
@@ -540,74 +521,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
540
521
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
541
522
|
}
|
|
542
523
|
|
|
543
|
-
|
|
544
|
-
* Connection credentials for upstash vector.
|
|
545
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
546
|
-
*/
|
|
547
|
-
type IndexConfig = {
|
|
548
|
-
/**
|
|
549
|
-
* UPSTASH_VECTOR_REST_URL
|
|
550
|
-
*/
|
|
551
|
-
url?: string;
|
|
552
|
-
/**
|
|
553
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
554
|
-
*/
|
|
555
|
-
token?: string;
|
|
556
|
-
/**
|
|
557
|
-
* The signal will allow aborting requests on the fly.
|
|
558
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
559
|
-
*/
|
|
560
|
-
signal?: AbortSignal;
|
|
561
|
-
} & RequesterConfig;
|
|
562
|
-
/**
|
|
563
|
-
* Serverless vector client for upstash.
|
|
564
|
-
*/
|
|
565
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
566
|
-
/**
|
|
567
|
-
* Create a new vector client by providing the url and token
|
|
568
|
-
*
|
|
569
|
-
* @example
|
|
570
|
-
* ```typescript
|
|
571
|
-
* const index = new Index({
|
|
572
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
573
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
574
|
-
* });
|
|
575
|
-
* ```
|
|
576
|
-
* OR
|
|
577
|
-
* This will automatically get environment variables from .env file
|
|
578
|
-
* ```typescript
|
|
579
|
-
* const index = new Index();
|
|
580
|
-
* ```
|
|
581
|
-
*/
|
|
582
|
-
constructor(config?: IndexConfig);
|
|
583
|
-
/**
|
|
584
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* ```ts
|
|
588
|
-
*
|
|
589
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
590
|
-
*
|
|
591
|
-
* const requester: Requester = {
|
|
592
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
593
|
-
* // ...
|
|
594
|
-
* }
|
|
595
|
-
* }
|
|
596
|
-
*
|
|
597
|
-
* const vector = new vector(requester)
|
|
598
|
-
* ```
|
|
599
|
-
*/
|
|
600
|
-
constructor(requesters?: Requester);
|
|
601
|
-
/**
|
|
602
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
603
|
-
*
|
|
604
|
-
* Use this to automatically load connection secrets from your environment
|
|
605
|
-
* variables. For instance when using the Vercel integration.
|
|
606
|
-
*
|
|
607
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
608
|
-
* your environment using `process.env`.
|
|
609
|
-
*/
|
|
610
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
524
|
+
export { type Dict as D, type FetchResult as F, Index as I, type QueryResult as Q, type RequesterConfig as R, type UpstashRequest as U, type Vector as V, type Requester as a, type UpstashResponse as b, type RangeResult as c, type InfoResult as d };
|
|
@@ -50,7 +50,7 @@ type Vector<TMetadata = Dict> = {
|
|
|
50
50
|
type NAMESPACE = string;
|
|
51
51
|
type Dict = Record<string, unknown>;
|
|
52
52
|
|
|
53
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
54
|
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
55
55
|
/**
|
|
56
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -148,70 +148,6 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
constructor(client: Requester, namespace: string);
|
|
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.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
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
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
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.
|
|
171
|
-
*
|
|
172
|
-
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
173
|
-
*/
|
|
174
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args: ({
|
|
175
|
-
id: string | number;
|
|
176
|
-
} & ({
|
|
177
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
178
|
-
data: string;
|
|
179
|
-
vector?: undefined;
|
|
180
|
-
} | {
|
|
181
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
182
|
-
data: string;
|
|
183
|
-
vector?: undefined;
|
|
184
|
-
})) | ({
|
|
185
|
-
id: string | number;
|
|
186
|
-
} & ({
|
|
187
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
188
|
-
vector?: number[] | undefined;
|
|
189
|
-
data?: undefined;
|
|
190
|
-
} | {
|
|
191
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
192
|
-
vector: number[];
|
|
193
|
-
data?: undefined;
|
|
194
|
-
})) | ({
|
|
195
|
-
id: string | number;
|
|
196
|
-
} & ({
|
|
197
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
198
|
-
data: string;
|
|
199
|
-
vector?: undefined;
|
|
200
|
-
} | {
|
|
201
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
202
|
-
data: string;
|
|
203
|
-
vector?: undefined;
|
|
204
|
-
}))[] | ({
|
|
205
|
-
id: string | number;
|
|
206
|
-
} & ({
|
|
207
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
208
|
-
vector?: number[] | undefined;
|
|
209
|
-
data?: undefined;
|
|
210
|
-
} | {
|
|
211
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
212
|
-
vector: number[];
|
|
213
|
-
data?: undefined;
|
|
214
|
-
}))[]) => Promise<string>;
|
|
215
151
|
/**
|
|
216
152
|
* Upserts (Updates and Inserts) specific items into the index namespace.
|
|
217
153
|
* It's used for adding new items to the index namespace or updating existing ones.
|
|
@@ -234,10 +170,35 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
234
170
|
*
|
|
235
171
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
236
172
|
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
173
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
174
|
+
id: string | number;
|
|
175
|
+
vector: number[];
|
|
176
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
177
|
+
} | {
|
|
178
|
+
id: string | number;
|
|
179
|
+
data: string;
|
|
180
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
181
|
+
} | {
|
|
182
|
+
id: string | number;
|
|
183
|
+
vector: number[];
|
|
184
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
185
|
+
}[] | {
|
|
186
|
+
id: string | number;
|
|
187
|
+
data: string;
|
|
188
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
189
|
+
}[]) => Promise<string>;
|
|
190
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
191
|
+
id: string | number;
|
|
192
|
+
vector: number[];
|
|
193
|
+
} | {
|
|
194
|
+
id: string | number;
|
|
195
|
+
data: string;
|
|
196
|
+
} | {
|
|
197
|
+
id: string | number;
|
|
198
|
+
metadata: TMetadata extends infer U ? U : never;
|
|
199
|
+
}) => Promise<{
|
|
200
|
+
updated: number;
|
|
201
|
+
}>;
|
|
241
202
|
/**
|
|
242
203
|
* It's used for retrieving specific items from the index namespace, optionally including
|
|
243
204
|
* their metadata and feature vectors.
|
|
@@ -255,9 +216,38 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
255
216
|
* @param {FetchCommandOptions} args[1] - Options for the fetch operation.
|
|
256
217
|
* @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
257
218
|
* @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
219
|
+
* @param {string} [args[1].namespace = ""] - The namespace of the index to fetch items from.
|
|
258
220
|
*
|
|
259
221
|
* @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
222
|
*/
|
|
223
|
+
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
224
|
+
includeMetadata?: boolean | undefined;
|
|
225
|
+
includeVectors?: boolean | undefined;
|
|
226
|
+
namespace?: string | undefined;
|
|
227
|
+
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
228
|
+
/**
|
|
229
|
+
* Queries an index namespace with specified parameters.
|
|
230
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```js
|
|
234
|
+
* await index.namespace("ns").query({
|
|
235
|
+
* topK: 3,
|
|
236
|
+
* vector: [ 0.22, 0.66 ],
|
|
237
|
+
* filter: "age >= 23 and (type = \'turtle\' OR type = \'cat\')"
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @param {Object} args - The arguments for the query command.
|
|
242
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
243
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
244
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
245
|
+
* @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.
|
|
246
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
247
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
248
|
+
*
|
|
249
|
+
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
250
|
+
*/
|
|
261
251
|
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>) => Promise<QueryResult<TMetadata>[]>;
|
|
262
252
|
/**
|
|
263
253
|
* Deletes a specific item or items from the index namespace by their ID(s). *
|
|
@@ -315,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
315
305
|
/**
|
|
316
306
|
* Serverless vector client for upstash vector db.
|
|
317
307
|
*/
|
|
318
|
-
declare class Index
|
|
308
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
319
309
|
protected client: Requester;
|
|
320
310
|
/**
|
|
321
311
|
* Create a new vector db client
|
|
@@ -394,49 +384,39 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
394
384
|
*
|
|
395
385
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
396
386
|
*/
|
|
397
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
387
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
388
|
+
id: string | number;
|
|
389
|
+
vector: number[];
|
|
390
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
391
|
+
} | {
|
|
398
392
|
id: string | number;
|
|
399
|
-
} & ({
|
|
400
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
401
393
|
data: string;
|
|
402
|
-
|
|
394
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
395
|
} | {
|
|
396
|
+
id: string | number;
|
|
397
|
+
vector: number[];
|
|
404
398
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
405
|
-
|
|
406
|
-
vector?: undefined;
|
|
407
|
-
})) | ({
|
|
399
|
+
}[] | {
|
|
408
400
|
id: string | number;
|
|
409
|
-
|
|
410
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
411
|
-
vector?: number[] | undefined;
|
|
412
|
-
data?: undefined;
|
|
413
|
-
} | {
|
|
401
|
+
data: string;
|
|
414
402
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
|
+
}[], options?: {
|
|
404
|
+
namespace?: string;
|
|
405
|
+
}) => Promise<string>;
|
|
406
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
407
|
+
id: string | number;
|
|
415
408
|
vector: number[];
|
|
416
|
-
|
|
417
|
-
})) | ({
|
|
409
|
+
} | {
|
|
418
410
|
id: string | number;
|
|
419
|
-
} & ({
|
|
420
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
421
411
|
data: string;
|
|
422
|
-
vector?: undefined;
|
|
423
412
|
} | {
|
|
424
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
425
|
-
data: string;
|
|
426
|
-
vector?: undefined;
|
|
427
|
-
}))[] | ({
|
|
428
413
|
id: string | number;
|
|
429
|
-
} & ({
|
|
430
414
|
metadata: TMetadata extends infer U ? U : never;
|
|
431
|
-
|
|
432
|
-
data?: undefined;
|
|
433
|
-
} | {
|
|
434
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
435
|
-
vector: number[];
|
|
436
|
-
data?: undefined;
|
|
437
|
-
}))[], options?: {
|
|
415
|
+
}, options?: {
|
|
438
416
|
namespace?: string;
|
|
439
|
-
}) => Promise<
|
|
417
|
+
}) => Promise<{
|
|
418
|
+
updated: number;
|
|
419
|
+
}>;
|
|
440
420
|
/**
|
|
441
421
|
* It's used for retrieving specific items from the index, optionally including
|
|
442
422
|
* their metadata and feature vectors.
|
|
@@ -460,6 +440,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
460
440
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
461
441
|
includeMetadata?: boolean | undefined;
|
|
462
442
|
includeVectors?: boolean | undefined;
|
|
443
|
+
namespace?: string | undefined;
|
|
463
444
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
464
445
|
/**
|
|
465
446
|
* It's used for wiping an entire index.
|
|
@@ -540,74 +521,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
540
521
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
541
522
|
}
|
|
542
523
|
|
|
543
|
-
|
|
544
|
-
* Connection credentials for upstash vector.
|
|
545
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
546
|
-
*/
|
|
547
|
-
type IndexConfig = {
|
|
548
|
-
/**
|
|
549
|
-
* UPSTASH_VECTOR_REST_URL
|
|
550
|
-
*/
|
|
551
|
-
url?: string;
|
|
552
|
-
/**
|
|
553
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
554
|
-
*/
|
|
555
|
-
token?: string;
|
|
556
|
-
/**
|
|
557
|
-
* The signal will allow aborting requests on the fly.
|
|
558
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
559
|
-
*/
|
|
560
|
-
signal?: AbortSignal;
|
|
561
|
-
} & RequesterConfig;
|
|
562
|
-
/**
|
|
563
|
-
* Serverless vector client for upstash.
|
|
564
|
-
*/
|
|
565
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
566
|
-
/**
|
|
567
|
-
* Create a new vector client by providing the url and token
|
|
568
|
-
*
|
|
569
|
-
* @example
|
|
570
|
-
* ```typescript
|
|
571
|
-
* const index = new Index({
|
|
572
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
573
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
574
|
-
* });
|
|
575
|
-
* ```
|
|
576
|
-
* OR
|
|
577
|
-
* This will automatically get environment variables from .env file
|
|
578
|
-
* ```typescript
|
|
579
|
-
* const index = new Index();
|
|
580
|
-
* ```
|
|
581
|
-
*/
|
|
582
|
-
constructor(config?: IndexConfig);
|
|
583
|
-
/**
|
|
584
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* ```ts
|
|
588
|
-
*
|
|
589
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
590
|
-
*
|
|
591
|
-
* const requester: Requester = {
|
|
592
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
593
|
-
* // ...
|
|
594
|
-
* }
|
|
595
|
-
* }
|
|
596
|
-
*
|
|
597
|
-
* const vector = new vector(requester)
|
|
598
|
-
* ```
|
|
599
|
-
*/
|
|
600
|
-
constructor(requesters?: Requester);
|
|
601
|
-
/**
|
|
602
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
603
|
-
*
|
|
604
|
-
* Use this to automatically load connection secrets from your environment
|
|
605
|
-
* variables. For instance when using the Vercel integration.
|
|
606
|
-
*
|
|
607
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
608
|
-
* your environment using `process.env`.
|
|
609
|
-
*/
|
|
610
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
524
|
+
export { type Dict as D, type FetchResult as F, Index as I, type QueryResult as Q, type RequesterConfig as R, type UpstashRequest as U, type Vector as V, type Requester as a, type UpstashResponse as b, type RangeResult as c, type InfoResult as d };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.1.
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.1-cf-canary", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "exports": { ".": { "browser": "./dist/nodejs.mjs", "bun": "./dist/nodejs.mjs", "deno": "./dist/nodejs.mjs", "edge-light": "./dist/nodejs.mjs", "edge-routine": "./dist/nodejs.mjs", "netlify": "./dist/nodejs.mjs", "react-native": "./dist/nodejs.mjs", "wintercg": "./dist/nodejs.mjs", "worker": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "workerd": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "node": "./dist/nodejs.mjs", "require": "./dist/nodejs.mjs", "import": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts" } }, "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/nodejs.d.ts" }
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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});
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|