@upstash/vector 1.1.2 → 1.1.3-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/README.md +40 -8
- package/dist/chunk-EEOSY6EV.mjs +1 -0
- package/dist/cloudflare.d.mts +60 -0
- package/dist/cloudflare.d.ts +60 -0
- package/dist/cloudflare.js +1 -0
- package/dist/cloudflare.mjs +1 -0
- package/dist/nodejs.d.mts +78 -0
- package/dist/nodejs.d.ts +78 -0
- package/dist/nodejs.js +1 -0
- package/dist/nodejs.mjs +1 -0
- package/dist/{index.d.mts → vector-U-xfTq8V.d.mts} +59 -79
- package/dist/{index.d.ts → vector-U-xfTq8V.d.ts} +59 -79
- package/package.json +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ const index = new Index<Metadata>({
|
|
|
47
47
|
token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
//Upsert
|
|
50
|
+
//Upsert data
|
|
51
51
|
await index.upsert([{
|
|
52
52
|
id: 'upstash-rocks',
|
|
53
53
|
vector: [
|
|
@@ -60,7 +60,21 @@ await index.upsert([{
|
|
|
60
60
|
}
|
|
61
61
|
}])
|
|
62
62
|
|
|
63
|
-
//
|
|
63
|
+
// Upsert data as plain text.
|
|
64
|
+
await index.upsert([{
|
|
65
|
+
id: 'tokyo',
|
|
66
|
+
data: "Tokyo is the capital of Japan.",
|
|
67
|
+
}])
|
|
68
|
+
|
|
69
|
+
//Upsert data alongside with your embedding
|
|
70
|
+
await index.upsert([{
|
|
71
|
+
id: 'tokyo',
|
|
72
|
+
data: "Tokyo is the capital of Japan.",
|
|
73
|
+
vector: [......]
|
|
74
|
+
}])
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
//Query data
|
|
64
78
|
const results = await index.query<Metadata>(
|
|
65
79
|
{
|
|
66
80
|
vector: [
|
|
@@ -76,9 +90,28 @@ const results = await index.query<Metadata>(
|
|
|
76
90
|
}
|
|
77
91
|
)
|
|
78
92
|
|
|
93
|
+
//Query with your data
|
|
94
|
+
const results = await index.query(
|
|
95
|
+
{
|
|
96
|
+
data: "Where is the capital of Japan",
|
|
97
|
+
topK: 1,
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
//Query with your data
|
|
102
|
+
const results = await index.query(
|
|
103
|
+
{
|
|
104
|
+
vector: [
|
|
105
|
+
... // query embedding
|
|
106
|
+
],
|
|
107
|
+
includeData: true, // Returns data associated with your vector.
|
|
108
|
+
topK: 1,
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
|
|
79
112
|
// If you wanna learn more about filtering check: [Metadata Filtering](https://upstash.com/docs/vector/features/filtering)
|
|
80
113
|
|
|
81
|
-
//Update
|
|
114
|
+
//Update data
|
|
82
115
|
await index.upsert(
|
|
83
116
|
{
|
|
84
117
|
id: "upstash-rocks",
|
|
@@ -102,6 +135,9 @@ await index.delete(["id-1", "id-2", "id-3"]);
|
|
|
102
135
|
//Fetch records by their IDs
|
|
103
136
|
await index.fetch(["id-1", "id-2"], {namespace: "example-namespace"});
|
|
104
137
|
|
|
138
|
+
//Fetch records by their IDs
|
|
139
|
+
await index.fetch(["id-1", "id-2"], {namespace: "example-namespace", includeData:true});
|
|
140
|
+
|
|
105
141
|
//Fetch records with range
|
|
106
142
|
await index.range(
|
|
107
143
|
{
|
|
@@ -223,11 +259,7 @@ Make sure you have Bun.js installed and have those relevant keys with specific v
|
|
|
223
259
|
|
|
224
260
|
```bash
|
|
225
261
|
|
|
226
|
-
## Vector dimension should be
|
|
262
|
+
## Vector dimension should be 3842
|
|
227
263
|
UPSTASH_VECTOR_REST_URL="XXXXX"
|
|
228
264
|
UPSTASH_VECTOR_REST_TOKEN="XXXXX"
|
|
229
|
-
|
|
230
|
-
## Vector dimension should be 384
|
|
231
|
-
EMBEDDING_UPSTASH_VECTOR_REST_URL="XXXXX"
|
|
232
|
-
EMBEDDING_UPSTASH_VECTOR_REST_TOKEN="XXXXX"
|
|
233
265
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var E=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 M=0;M<=this.retry.attempts;M++)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"})]),P={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,P);break}s=A,await new Promise(g=>setTimeout(g,this.retry.backoff(M)))}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 f=class extends n{constructor(e,t){let a="query";a=e.some(o=>o.data)?"query-data":"query",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,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";Array.isArray(e)?a=e.some(o=>R(o))?"upsert":"upsert-data":a=R(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},R=r=>"vector"in r;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 C=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 x=class extends n{constructor(){super([],"list-namespaces")}};var T=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var b=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);queryMany=(e,t)=>new f(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 C().exec(this.client);listNamespaces=()=>new x().exec(this.client);deleteNamespace=e=>new T(e).exec(this.client)};export{E as a,b};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-U-xfTq8V.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-U-xfTq8V.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 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
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
51
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
52
|
+
* your environment using `process.env`.
|
|
53
|
+
*/
|
|
54
|
+
static fromEnv(env?: {
|
|
55
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
56
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
57
|
+
}, config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Index, type IndexConfig };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-U-xfTq8V.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-U-xfTq8V.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 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
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
51
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
52
|
+
* your environment using `process.env`.
|
|
53
|
+
*/
|
|
54
|
+
static fromEnv(env?: {
|
|
55
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
56
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
57
|
+
}, config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Index, type IndexConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var A=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)A(n,t,{get:e[t],enumerable:!0})},O=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of V(e))!N.call(n,s)&&s!==t&&A(n,s,{get:()=>e[s],enumerable:!(a=w(e,s))||a.enumerable});return n};var _=n=>O(A({},"__esModule",{value:!0}),n);var q={};D(q,{Index:()=>U});module.exports=_(q);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 g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(S){if(this.options.signal?.aborted){let M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),P={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,P);break}s=S,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 f=class extends r{constructor(e,t){let a="query";a=e.some(o=>o.data)?"query-data":"query",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,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";Array.isArray(e)?a=e.some(o=>b(o))?"upsert":"upsert-data":a=b(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},b=n=>"vector"in n;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 C=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 x=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 h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);queryMany=(e,t)=>new f(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 C().exec(this.client);listNamespaces=()=>new x().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var U=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,s;if(e){if(a=e.UPSTASH_VECTOR_REST_URL,!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");if(s=e.UPSTASH_VECTOR_REST_TOKEN,!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 i}from"./chunk-EEOSY6EV.mjs";var o=class T extends i{constructor(t){let r=t?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,e=t?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!r)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!"),(r.startsWith(" ")||r.endsWith(" ")||/\r|\n/.test(r))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let n=new s({baseUrl:e,retry:t?.retry,headers:{authorization:`Bearer ${r}`},signal:t?.signal});super(n)}static fromEnv(t,r){let e,n;if(t){if(e=t.UPSTASH_VECTOR_REST_URL,!e)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");if(n=t.UPSTASH_VECTOR_REST_TOKEN,!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 T({...r,url:e,token:n})}};export{o as Index};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-U-xfTq8V.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-U-xfTq8V.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
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
69
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
70
|
+
* your environment using `process.env`.
|
|
71
|
+
*/
|
|
72
|
+
static fromEnv(env?: {
|
|
73
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
74
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
75
|
+
}, config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-U-xfTq8V.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-U-xfTq8V.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
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
69
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
70
|
+
* your environment using `process.env`.
|
|
71
|
+
*/
|
|
72
|
+
static fromEnv(env?: {
|
|
73
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
74
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
75
|
+
}, config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var A=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)A(n,t,{get:e[t],enumerable:!0})},_=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of V(e))!N.call(n,s)&&s!==t&&A(n,s,{get:()=>e[s],enumerable:!(a=w(e,s))||a.enumerable});return n};var O=n=>_(A({},"__esModule",{value:!0}),n);var q={};D(q,{Index:()=>U});module.exports=O(q);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 g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(S){if(this.options.signal?.aborted){let M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),P={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,P);break}s=S,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 f=class extends r{constructor(e,t){let a="query";a=e.some(o=>o.data)?"query-data":"query",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,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";Array.isArray(e)?a=e.some(o=>b(o))?"upsert":"upsert-data":a=b(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},b=n=>"vector"in n;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 C=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 x=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 h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);queryMany=(e,t)=>new f(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 C().exec(this.client);listNamespaces=()=>new x().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var U=class n extends R{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 T({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,t){let a=e?.UPSTASH_VECTOR_REST_URL||process?.env.UPSTASH_VECTOR_REST_URL,s=e?.UPSTASH_VECTOR_REST_TOKEN||process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(!s)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new n({...t,url:a,token:s})}};0&&(module.exports={Index});
|
package/dist/nodejs.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s,b as o}from"./chunk-EEOSY6EV.mjs";var T=class i extends o{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let n=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,t=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!n)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!t)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(n.startsWith(" ")||n.endsWith(" ")||/\r|\n/.test(n))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let r=new s({baseUrl:t,retry:e?.retry,headers:{authorization:`Bearer ${n}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(r)}static fromEnv(e,n){let t=e?.UPSTASH_VECTOR_REST_URL||process?.env.UPSTASH_VECTOR_REST_URL,r=e?.UPSTASH_VECTOR_REST_TOKEN||process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(!r)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new i({...n,url:t,token:r})}};export{T as Index};
|
|
@@ -44,8 +44,9 @@ type RequesterConfig = {
|
|
|
44
44
|
|
|
45
45
|
type Vector<TMetadata = Dict> = {
|
|
46
46
|
id: string;
|
|
47
|
-
vector
|
|
47
|
+
vector?: number[];
|
|
48
48
|
metadata?: TMetadata;
|
|
49
|
+
data?: string;
|
|
49
50
|
};
|
|
50
51
|
type NAMESPACE = string;
|
|
51
52
|
type Dict = Record<string, unknown>;
|
|
@@ -78,6 +79,7 @@ type QueryCommandPayload = {
|
|
|
78
79
|
filter?: string;
|
|
79
80
|
includeVectors?: boolean;
|
|
80
81
|
includeMetadata?: boolean;
|
|
82
|
+
includeData?: boolean;
|
|
81
83
|
} & ({
|
|
82
84
|
vector: number[];
|
|
83
85
|
data?: never;
|
|
@@ -88,12 +90,18 @@ type QueryCommandPayload = {
|
|
|
88
90
|
type QueryResult<TMetadata = Dict> = {
|
|
89
91
|
id: number | string;
|
|
90
92
|
score: number;
|
|
91
|
-
vector
|
|
93
|
+
vector?: number[];
|
|
92
94
|
metadata?: TMetadata;
|
|
95
|
+
data?: string;
|
|
93
96
|
};
|
|
94
97
|
type QueryCommandOptions = {
|
|
95
98
|
namespace?: string;
|
|
96
99
|
};
|
|
100
|
+
|
|
101
|
+
declare class QueryManyCommand<TMetadata> extends Command<QueryResult<TMetadata>[][]> {
|
|
102
|
+
constructor(payload: QueryCommandPayload[], options?: QueryCommandOptions);
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
|
|
98
106
|
constructor(payload: QueryCommandPayload, options?: QueryCommandOptions);
|
|
99
107
|
}
|
|
@@ -196,6 +204,7 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
196
204
|
} | {
|
|
197
205
|
id: string | number;
|
|
198
206
|
metadata: TMetadata extends infer U ? U : never;
|
|
207
|
+
metadataUpdateMode?: "PATCH" | "OVERWRITE" | undefined;
|
|
199
208
|
}) => Promise<{
|
|
200
209
|
updated: number;
|
|
201
210
|
}>;
|
|
@@ -223,6 +232,7 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
223
232
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
224
233
|
includeMetadata?: boolean | undefined;
|
|
225
234
|
includeVectors?: boolean | undefined;
|
|
235
|
+
includeData?: boolean | undefined;
|
|
226
236
|
namespace?: string | undefined;
|
|
227
237
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
228
238
|
/**
|
|
@@ -305,7 +315,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
305
315
|
/**
|
|
306
316
|
* Serverless vector client for upstash vector db.
|
|
307
317
|
*/
|
|
308
|
-
declare class Index
|
|
318
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
309
319
|
protected client: Requester;
|
|
310
320
|
/**
|
|
311
321
|
* Create a new vector db client
|
|
@@ -356,12 +366,49 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
356
366
|
* @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.
|
|
357
367
|
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
358
368
|
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
369
|
+
* @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
|
|
359
370
|
*
|
|
360
|
-
*
|
|
371
|
+
* A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
361
372
|
*/
|
|
362
373
|
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>, options?: {
|
|
363
374
|
namespace?: string;
|
|
364
375
|
}) => Promise<QueryResult<TMetadata>[]>;
|
|
376
|
+
/**
|
|
377
|
+
* Queries an index with specified parameters.
|
|
378
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```js
|
|
382
|
+
* await index.queryMany([
|
|
383
|
+
* {
|
|
384
|
+
* topK: 3,
|
|
385
|
+
* vector: [0.22, 0.66],
|
|
386
|
+
* filter: "age >= 23 and (type = 'turtle' OR type = 'cat')",
|
|
387
|
+
* },
|
|
388
|
+
* {
|
|
389
|
+
* topK: 3,
|
|
390
|
+
* vector: [0.45, 0.52],
|
|
391
|
+
* filter: "age >= 27 and (type = 'rabbit' OR type = 'dog')",
|
|
392
|
+
* },
|
|
393
|
+
* ]);
|
|
394
|
+
*
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @param {Object} args - The arguments for the query command.
|
|
398
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
399
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
400
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
401
|
+
* @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.
|
|
402
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
403
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
404
|
+
* @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
|
|
405
|
+
*
|
|
406
|
+
* A promise that resolves with an array of arrays of query result objects,
|
|
407
|
+
* where each inner array represents a group of results matching a specific query condition.
|
|
408
|
+
*/
|
|
409
|
+
queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
|
|
410
|
+
namespace?: string;
|
|
411
|
+
}) => Promise<QueryResult<TMetadata>[][]>;
|
|
365
412
|
/**
|
|
366
413
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
367
414
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -412,6 +459,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
412
459
|
} | {
|
|
413
460
|
id: string | number;
|
|
414
461
|
metadata: TMetadata extends infer U ? U : never;
|
|
462
|
+
metadataUpdateMode?: "PATCH" | "OVERWRITE" | undefined;
|
|
415
463
|
}, options?: {
|
|
416
464
|
namespace?: string;
|
|
417
465
|
}) => Promise<{
|
|
@@ -430,16 +478,18 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
430
478
|
* ```
|
|
431
479
|
*
|
|
432
480
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
433
|
-
* @param {(number[]|string[])} args
|
|
434
|
-
* @param {FetchCommandOptions} args
|
|
435
|
-
* @param {boolean} [args
|
|
436
|
-
* @param {boolean} [args
|
|
481
|
+
* @param {(number[]|string[])} args - An array of IDs of the items to be fetched.
|
|
482
|
+
* @param {FetchCommandOptions} args - Options for the fetch operation.
|
|
483
|
+
* @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
484
|
+
* @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
485
|
+
* @param {boolean} [args.metadataUpdateMode="OVERWRITE"] - Specifies whether to overwrite or patch the metadata values.
|
|
437
486
|
*
|
|
438
487
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
439
488
|
*/
|
|
440
489
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
441
490
|
includeMetadata?: boolean | undefined;
|
|
442
491
|
includeVectors?: boolean | undefined;
|
|
492
|
+
includeData?: boolean | undefined;
|
|
443
493
|
namespace?: string | undefined;
|
|
444
494
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
445
495
|
/**
|
|
@@ -521,74 +571,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
521
571
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
522
572
|
}
|
|
523
573
|
|
|
524
|
-
|
|
525
|
-
* Connection credentials for upstash vector.
|
|
526
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
527
|
-
*/
|
|
528
|
-
type IndexConfig = {
|
|
529
|
-
/**
|
|
530
|
-
* UPSTASH_VECTOR_REST_URL
|
|
531
|
-
*/
|
|
532
|
-
url?: string;
|
|
533
|
-
/**
|
|
534
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
535
|
-
*/
|
|
536
|
-
token?: string;
|
|
537
|
-
/**
|
|
538
|
-
* The signal will allow aborting requests on the fly.
|
|
539
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
540
|
-
*/
|
|
541
|
-
signal?: AbortSignal;
|
|
542
|
-
} & RequesterConfig;
|
|
543
|
-
/**
|
|
544
|
-
* Serverless vector client for upstash.
|
|
545
|
-
*/
|
|
546
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
547
|
-
/**
|
|
548
|
-
* Create a new vector client by providing the url and token
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* const index = new Index({
|
|
553
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
554
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
555
|
-
* });
|
|
556
|
-
* ```
|
|
557
|
-
* OR
|
|
558
|
-
* This will automatically get environment variables from .env file
|
|
559
|
-
* ```typescript
|
|
560
|
-
* const index = new Index();
|
|
561
|
-
* ```
|
|
562
|
-
*/
|
|
563
|
-
constructor(config?: IndexConfig);
|
|
564
|
-
/**
|
|
565
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
*
|
|
570
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
571
|
-
*
|
|
572
|
-
* const requester: Requester = {
|
|
573
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
574
|
-
* // ...
|
|
575
|
-
* }
|
|
576
|
-
* }
|
|
577
|
-
*
|
|
578
|
-
* const vector = new vector(requester)
|
|
579
|
-
* ```
|
|
580
|
-
*/
|
|
581
|
-
constructor(requesters?: Requester);
|
|
582
|
-
/**
|
|
583
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
584
|
-
*
|
|
585
|
-
* Use this to automatically load connection secrets from your environment
|
|
586
|
-
* variables. For instance when using the Vercel integration.
|
|
587
|
-
*
|
|
588
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
589
|
-
* your environment using `process.env`.
|
|
590
|
-
*/
|
|
591
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
574
|
+
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 };
|
|
@@ -44,8 +44,9 @@ type RequesterConfig = {
|
|
|
44
44
|
|
|
45
45
|
type Vector<TMetadata = Dict> = {
|
|
46
46
|
id: string;
|
|
47
|
-
vector
|
|
47
|
+
vector?: number[];
|
|
48
48
|
metadata?: TMetadata;
|
|
49
|
+
data?: string;
|
|
49
50
|
};
|
|
50
51
|
type NAMESPACE = string;
|
|
51
52
|
type Dict = Record<string, unknown>;
|
|
@@ -78,6 +79,7 @@ type QueryCommandPayload = {
|
|
|
78
79
|
filter?: string;
|
|
79
80
|
includeVectors?: boolean;
|
|
80
81
|
includeMetadata?: boolean;
|
|
82
|
+
includeData?: boolean;
|
|
81
83
|
} & ({
|
|
82
84
|
vector: number[];
|
|
83
85
|
data?: never;
|
|
@@ -88,12 +90,18 @@ type QueryCommandPayload = {
|
|
|
88
90
|
type QueryResult<TMetadata = Dict> = {
|
|
89
91
|
id: number | string;
|
|
90
92
|
score: number;
|
|
91
|
-
vector
|
|
93
|
+
vector?: number[];
|
|
92
94
|
metadata?: TMetadata;
|
|
95
|
+
data?: string;
|
|
93
96
|
};
|
|
94
97
|
type QueryCommandOptions = {
|
|
95
98
|
namespace?: string;
|
|
96
99
|
};
|
|
100
|
+
|
|
101
|
+
declare class QueryManyCommand<TMetadata> extends Command<QueryResult<TMetadata>[][]> {
|
|
102
|
+
constructor(payload: QueryCommandPayload[], options?: QueryCommandOptions);
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
declare class QueryCommand<TMetadata> extends Command<QueryResult<TMetadata>[]> {
|
|
98
106
|
constructor(payload: QueryCommandPayload, options?: QueryCommandOptions);
|
|
99
107
|
}
|
|
@@ -196,6 +204,7 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
196
204
|
} | {
|
|
197
205
|
id: string | number;
|
|
198
206
|
metadata: TMetadata extends infer U ? U : never;
|
|
207
|
+
metadataUpdateMode?: "PATCH" | "OVERWRITE" | undefined;
|
|
199
208
|
}) => Promise<{
|
|
200
209
|
updated: number;
|
|
201
210
|
}>;
|
|
@@ -223,6 +232,7 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
223
232
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
224
233
|
includeMetadata?: boolean | undefined;
|
|
225
234
|
includeVectors?: boolean | undefined;
|
|
235
|
+
includeData?: boolean | undefined;
|
|
226
236
|
namespace?: string | undefined;
|
|
227
237
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
228
238
|
/**
|
|
@@ -305,7 +315,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
305
315
|
/**
|
|
306
316
|
* Serverless vector client for upstash vector db.
|
|
307
317
|
*/
|
|
308
|
-
declare class Index
|
|
318
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
309
319
|
protected client: Requester;
|
|
310
320
|
/**
|
|
311
321
|
* Create a new vector db client
|
|
@@ -356,12 +366,49 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
356
366
|
* @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.
|
|
357
367
|
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
358
368
|
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
369
|
+
* @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
|
|
359
370
|
*
|
|
360
|
-
*
|
|
371
|
+
* A promise that resolves with an array of query result objects when the request to query the index is completed.
|
|
361
372
|
*/
|
|
362
373
|
query: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryCommand>, options?: {
|
|
363
374
|
namespace?: string;
|
|
364
375
|
}) => Promise<QueryResult<TMetadata>[]>;
|
|
376
|
+
/**
|
|
377
|
+
* Queries an index with specified parameters.
|
|
378
|
+
* This method creates and executes a query command on an index based on the provided arguments.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```js
|
|
382
|
+
* await index.queryMany([
|
|
383
|
+
* {
|
|
384
|
+
* topK: 3,
|
|
385
|
+
* vector: [0.22, 0.66],
|
|
386
|
+
* filter: "age >= 23 and (type = 'turtle' OR type = 'cat')",
|
|
387
|
+
* },
|
|
388
|
+
* {
|
|
389
|
+
* topK: 3,
|
|
390
|
+
* vector: [0.45, 0.52],
|
|
391
|
+
* filter: "age >= 27 and (type = 'rabbit' OR type = 'dog')",
|
|
392
|
+
* },
|
|
393
|
+
* ]);
|
|
394
|
+
*
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @param {Object} args - The arguments for the query command.
|
|
398
|
+
* @param {number[]} args.vector - An array of numbers representing the feature vector for the query.
|
|
399
|
+
* This vector is utilized to find the most relevant items in the index.
|
|
400
|
+
* @param {number} args.topK - The desired number of top results to be returned, based on relevance or similarity to the query vector.
|
|
401
|
+
* @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.
|
|
402
|
+
* @param {boolean} [args.includeVectors=false] - When set to true, includes the feature vectors of the returned items in the response.
|
|
403
|
+
* @param {boolean} [args.includeMetadata=false] - When set to true, includes additional metadata of the returned items in the response.
|
|
404
|
+
* @param {boolean} [args.includeData=false] - When set to true, includes data - string - of the returned items in the response.
|
|
405
|
+
*
|
|
406
|
+
* A promise that resolves with an array of arrays of query result objects,
|
|
407
|
+
* where each inner array represents a group of results matching a specific query condition.
|
|
408
|
+
*/
|
|
409
|
+
queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
|
|
410
|
+
namespace?: string;
|
|
411
|
+
}) => Promise<QueryResult<TMetadata>[][]>;
|
|
365
412
|
/**
|
|
366
413
|
* Upserts (Updates and Inserts) specific items into the index.
|
|
367
414
|
* It's used for adding new items to the index or updating existing ones.
|
|
@@ -412,6 +459,7 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
412
459
|
} | {
|
|
413
460
|
id: string | number;
|
|
414
461
|
metadata: TMetadata extends infer U ? U : never;
|
|
462
|
+
metadataUpdateMode?: "PATCH" | "OVERWRITE" | undefined;
|
|
415
463
|
}, options?: {
|
|
416
464
|
namespace?: string;
|
|
417
465
|
}) => Promise<{
|
|
@@ -430,16 +478,18 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
430
478
|
* ```
|
|
431
479
|
*
|
|
432
480
|
* @param {...CommandArgs<typeof FetchCommand>} args - The arguments for the fetch command.
|
|
433
|
-
* @param {(number[]|string[])} args
|
|
434
|
-
* @param {FetchCommandOptions} args
|
|
435
|
-
* @param {boolean} [args
|
|
436
|
-
* @param {boolean} [args
|
|
481
|
+
* @param {(number[]|string[])} args - An array of IDs of the items to be fetched.
|
|
482
|
+
* @param {FetchCommandOptions} args - Options for the fetch operation.
|
|
483
|
+
* @param {boolean} [args.includeMetadata=false] - Optionally include metadata of the fetched items.
|
|
484
|
+
* @param {boolean} [args.includeVectors=false] - Optionally include feature vectors of the fetched items.
|
|
485
|
+
* @param {boolean} [args.metadataUpdateMode="OVERWRITE"] - Specifies whether to overwrite or patch the metadata values.
|
|
437
486
|
*
|
|
438
487
|
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
|
|
439
488
|
*/
|
|
440
489
|
fetch: <TMetadata extends Dict = TIndexMetadata>(ids: number[] | string[], opts?: {
|
|
441
490
|
includeMetadata?: boolean | undefined;
|
|
442
491
|
includeVectors?: boolean | undefined;
|
|
492
|
+
includeData?: boolean | undefined;
|
|
443
493
|
namespace?: string | undefined;
|
|
444
494
|
} | undefined) => Promise<FetchResult<TMetadata>[]>;
|
|
445
495
|
/**
|
|
@@ -521,74 +571,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
521
571
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
522
572
|
}
|
|
523
573
|
|
|
524
|
-
|
|
525
|
-
* Connection credentials for upstash vector.
|
|
526
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
527
|
-
*/
|
|
528
|
-
type IndexConfig = {
|
|
529
|
-
/**
|
|
530
|
-
* UPSTASH_VECTOR_REST_URL
|
|
531
|
-
*/
|
|
532
|
-
url?: string;
|
|
533
|
-
/**
|
|
534
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
535
|
-
*/
|
|
536
|
-
token?: string;
|
|
537
|
-
/**
|
|
538
|
-
* The signal will allow aborting requests on the fly.
|
|
539
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
540
|
-
*/
|
|
541
|
-
signal?: AbortSignal;
|
|
542
|
-
} & RequesterConfig;
|
|
543
|
-
/**
|
|
544
|
-
* Serverless vector client for upstash.
|
|
545
|
-
*/
|
|
546
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
547
|
-
/**
|
|
548
|
-
* Create a new vector client by providing the url and token
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* const index = new Index({
|
|
553
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
554
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
555
|
-
* });
|
|
556
|
-
* ```
|
|
557
|
-
* OR
|
|
558
|
-
* This will automatically get environment variables from .env file
|
|
559
|
-
* ```typescript
|
|
560
|
-
* const index = new Index();
|
|
561
|
-
* ```
|
|
562
|
-
*/
|
|
563
|
-
constructor(config?: IndexConfig);
|
|
564
|
-
/**
|
|
565
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
*
|
|
570
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
571
|
-
*
|
|
572
|
-
* const requester: Requester = {
|
|
573
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
574
|
-
* // ...
|
|
575
|
-
* }
|
|
576
|
-
* }
|
|
577
|
-
*
|
|
578
|
-
* const vector = new vector(requester)
|
|
579
|
-
* ```
|
|
580
|
-
*/
|
|
581
|
-
constructor(requesters?: Requester);
|
|
582
|
-
/**
|
|
583
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
584
|
-
*
|
|
585
|
-
* Use this to automatically load connection secrets from your environment
|
|
586
|
-
* variables. For instance when using the Vercel integration.
|
|
587
|
-
*
|
|
588
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
589
|
-
* your environment using `process.env`.
|
|
590
|
-
*/
|
|
591
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
574
|
+
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.3-canary", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "exports": { ".": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js", "types": "./dist/nodejs.d.ts", "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" } } }, "main": "./dist/nodejs.js", "module": "./dist/nodejs.mjs", "browser": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts", "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" } }
|
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})},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/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,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 M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),A={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,A);break}o=b,await new Promise(M=>setTimeout(M,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 T=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 T().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(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 o=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(o)}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};
|