@upstash/vector 1.1.3-canary.3 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ const index = new Index<Metadata>({
47
47
  token: "<UPSTASH_VECTOR_REST_TOKEN>",
48
48
  });
49
49
 
50
- //Upsert Data
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
- //Query Data
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 Data
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 2
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};
@@ -1,5 +1,5 @@
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';
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
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -1,5 +1,5 @@
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';
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
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var _=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},N=(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 V=n=>N(M({},"__esModule",{value:!0}),n);var D={};_(D,{Index:()=>S});module.exports=V(D);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(b){if(this.options.signal?.aborted){let x=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),A={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(x,A);break}s=b,await new Promise(x=>setTimeout(x,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 y=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 T(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 T=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var E=class extends r{constructor(){super([],"list-namespaces")}};var h=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 T(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 E().exec(this.client);deleteNamespace=e=>new h(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 f({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`")}else{if(a=process?.env.UPSTASH_VECTOR_REST_URL,!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(s=process?.env.UPSTASH_VECTOR_REST_TOKEN,!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});
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});
@@ -1 +1 @@
1
- import{a as s,b as o}from"./chunk-HLW45HVB.mjs";var i=class T 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,n;if(r){if(e=r.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=r.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`")}else{if(e=process?.env.UPSTASH_VECTOR_REST_URL,!e)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(n=process?.env.UPSTASH_VECTOR_REST_TOKEN,!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`")}return new T({...t,url:e,token:n})}};export{i as Index};
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};
package/dist/nodejs.d.mts CHANGED
@@ -1,5 +1,5 @@
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';
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
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
package/dist/nodejs.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
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
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
package/dist/nodejs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var _=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},N=(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 V=n=>N(M({},"__esModule",{value:!0}),n);var O={};_(O,{Index:()=>S});module.exports=V(O);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 R=0;R<=this.retry.attempts;R++)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(R)))}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 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);update=e=>new T(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 T=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 E=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var x=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 T(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 C().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var S=class n extends x{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,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`")}else{if(a=process?.env.UPSTASH_VECTOR_REST_URL,!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(s=process?.env.UPSTASH_VECTOR_REST_TOKEN,!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});
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 CHANGED
@@ -1 +1 @@
1
- import{a as s,b as o}from"./chunk-HLW45HVB.mjs";var i=class T extends o{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 r=new s({baseUrl:n,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(r)}static fromEnv(e,t){let n,r;if(e){if(n=e.UPSTASH_VECTOR_REST_URL,!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");if(r=e.UPSTASH_VECTOR_REST_TOKEN,!r)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`")}else{if(n=process?.env.UPSTASH_VECTOR_REST_URL,!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");if(r=process?.env.UPSTASH_VECTOR_REST_TOKEN,!r)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`")}return new T({...t,url:n,token:r})}};export{i as Index};
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: number[];
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: number[];
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
  /**
@@ -356,12 +366,49 @@ declare class Index<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
- * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
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<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<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[0] - An array of IDs of the items to be fetched.
434
- * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
435
- * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
436
- * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
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
  /**
@@ -44,8 +44,9 @@ type RequesterConfig = {
44
44
 
45
45
  type Vector<TMetadata = Dict> = {
46
46
  id: string;
47
- vector: number[];
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: number[];
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
  /**
@@ -356,12 +366,49 @@ declare class Index<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
- * @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
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<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<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[0] - An array of IDs of the items to be fetched.
434
- * @param {FetchCommandOptions} args[1] - Options for the fetch operation.
435
- * @param {boolean} [args[1].includeMetadata=false] - Optionally include metadata of the fetched items.
436
- * @param {boolean} [args[1].includeVectors=false] - Optionally include feature vectors of the fetched items.
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
  /**
package/package.json CHANGED
@@ -1,66 +1 @@
1
- {
2
- "name": "@upstash/vector",
3
- "version": "1.1.3-canary.3",
4
- "author": "Oguzhan Olguncu <oguzhan@upstash.com>",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/upstash/vector-js"
8
- },
9
- "exports": {
10
- ".": {
11
- "import": "./dist/nodejs.mjs",
12
- "require": "./dist/nodejs.js",
13
- "types": "./dist/nodejs.d.ts",
14
- "browser": "./dist/nodejs.mjs",
15
- "bun": "./dist/nodejs.mjs",
16
- "deno": "./dist/nodejs.mjs",
17
- "edge-light": "./dist/nodejs.mjs",
18
- "edge-routine": "./dist/nodejs.mjs",
19
- "netlify": "./dist/nodejs.mjs",
20
- "react-native": "./dist/nodejs.mjs",
21
- "wintercg": "./dist/nodejs.mjs",
22
- "worker": {
23
- "import": "./dist/cloudflare.mjs",
24
- "types": "./dist/cloudflare.d.ts"
25
- },
26
- "workerd": {
27
- "import": "./dist/cloudflare.mjs",
28
- "types": "./dist/cloudflare.d.ts"
29
- }
30
- }
31
- },
32
- "main": "./dist/nodejs.js",
33
- "module": "./dist/nodejs.mjs",
34
- "browser": "./dist/nodejs.mjs",
35
- "types": "./dist/nodejs.d.ts",
36
- "devDependencies": {
37
- "@biomejs/biome": "^1.4.1",
38
- "@commitlint/cli": "^18.6.0",
39
- "@commitlint/config-conventional": "^18.6.0",
40
- "bun-types": "latest",
41
- "husky": "^8.0.3",
42
- "tsup": "latest",
43
- "typescript": "^5.0.0",
44
- "vitest": "^1.2.2"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/upstash/vector/issues"
48
- },
49
- "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.",
50
- "files": [
51
- "dist"
52
- ],
53
- "homepage": "https://upstash.com/vector",
54
- "keywords": [
55
- "vector",
56
- "upstash",
57
- "db"
58
- ],
59
- "license": "MIT",
60
- "scripts": {
61
- "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000 && vitest run --typecheck",
62
- "fmt": "bunx biome check --apply ./src",
63
- "build": "tsup",
64
- "prepare": "husky install"
65
- }
66
- }
1
+ { "name": "@upstash/vector", "version": "v1.1.3", "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" } }
@@ -1 +0,0 @@
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};