@upstash/vector 1.1.5 → 1.1.6

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
@@ -3,7 +3,7 @@
3
3
  > [!NOTE]
4
4
  > **This project is in GA Stage.**
5
5
  >
6
- > The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
6
+ > The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
7
7
  > The Upstash team is committed to maintaining and improving its functionality.
8
8
 
9
9
  `@upstash/vector` is an HTTP/REST based client for Typescript, built on top of [Upstash REST API](https://upstash.com/docs/vector/api/endpoints/).
@@ -83,7 +83,7 @@ const results = await index.query<Metadata>(
83
83
  ... // query embedding
84
84
  ],
85
85
  includeVectors: true,
86
- includeMetadata: true
86
+ includeMetadata: true,
87
87
  topK: 1,
88
88
  filter: "genre = 'fantasy' and title = 'Lord of the Rings'"
89
89
  },
@@ -210,7 +210,7 @@ const results = await namespace.query<Metadata>(
210
210
  ... // query embedding
211
211
  ],
212
212
  includeVectors: true,
213
- includeMetadata: true
213
+ includeMetadata: true,
214
214
  topK: 1,
215
215
  filter: "genre = 'fantasy' and title = 'Lord of the Rings'"
216
216
  },
@@ -233,7 +233,7 @@ We have a [Discord](upstash.com/discord) for common problems. If you can't find
233
233
 
234
234
  ## Docs
235
235
 
236
- See [the documentation](https://upstash.com/docs/oss/sdks/ts/vector/overview) for details.
236
+ See [the documentation](https://upstash.com/docs/vector/sdks/ts/getting-started) for details.
237
237
 
238
238
  ## Contributing
239
239
 
@@ -0,0 +1 @@
1
+ var m=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var A=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},this.retry=typeof e?.retry=="boolean"&&e?.retry===!1?{attempts:1,backoff:()=>0}:{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 f=0;f<=this.retry.attempts;f++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(D){if(this.options.signal?.aborted){let P=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),q={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(P,q);break}s=D,await new Promise(P=>setTimeout(P,this.retry.backoff(f)))}if(!a)throw s??new Error("Exhausted all retries");let o=await a.json();if(!a.ok)throw new m(`${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 m(a);if(t===void 0)throw new TypeError("Request did not return a result");return t}};var i=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 x=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 p=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 d=class extends r{constructor(e,t){let a="upsert";Array.isArray(e)?a=e.some(o=>w(o))?"upsert":"upsert-data":a=w(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},w=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 u=class extends r{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var l=class extends r{constructor(e){let t="reset";e?.namespace?t=`${t}/${e.namespace}`:e?.all&&(t=`${t}?all`),super([],t)}};var h=class extends r{constructor(){super([],"info")}};var C=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(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 p(e,{namespace:this.namespace}).exec(this.client);delete=e=>new i(e,{namespace:this.namespace}).exec(this.client);range=e=>new u(e,{namespace:this.namespace}).exec(this.client);reset=()=>new l({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 T=class extends r{constructor(e){super(e,"resumable-query-next")}};var M=class extends r{constructor(e,t){let a="resumable-query";"data"in e&&(a="resumable-query-data"),t&&(a=`${a}/${t}`),super(e,a)}};var b=class extends r{constructor(e){super(e,"resumable-query-end")}};var R=class{uuid;start;fetchNext;stop;constructor(e,t,a){this.start=async()=>{let s=await new M(e,a).exec(t);return this.uuid=s.uuid,s},this.fetchNext=s=>{if(!this.uuid)throw new Error("The resumable query has already been stopped. Please start another resumable query.");return new T({uuid:this.uuid,additionalK:s}).exec(t)},this.stop=async()=>{if(!this.uuid)throw new Error("Resumable query has not been started. Call start() first.");let s=await new b({uuid:this.uuid}).exec(t);return this.uuid="",s}}};var g=class extends r{constructor(){super([],"list-namespaces")}};var E=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var Q=class{client;constructor(e){this.client=e}namespace=e=>new C(this.client,e);delete=(e,t)=>new i(e,t).exec(this.client);query=(e,t)=>new p(e,t).exec(this.client);queryMany=(e,t)=>new x(e,t).exec(this.client);resumableQuery=async(e,t)=>{let a=new R(e,this.client,t?.namespace),s=await a.start(),{fetchNext:o,stop:f}=a;return{fetchNext:o,stop:f,result:s.scores}};upsert=(e,t)=>new d(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 l(e).exec(this.client);range=(e,t)=>new u(e,t).exec(this.client);info=()=>new h().exec(this.client);listNamespaces=()=>new g().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};export{A as a,Q as b};
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-wT6XsV3D.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-wT6XsV3D.mjs';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-Kaq7eMt8.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-Kaq7eMt8.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-wT6XsV3D.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-wT6XsV3D.js';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-Kaq7eMt8.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-Kaq7eMt8.js';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)b(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&&b(n,s,{get:()=>e[s],enumerable:!(a=w(e,s))||a.enumerable});return n};var _=n=>O(b({},"__esModule",{value:!0}),n);var q={};D(q,{Index:()=>A});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=>U(o))?"upsert":"upsert-data":a=U(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},U=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 h=class extends r{constructor(){super([],"info")}};var C=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new d(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var y=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var 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 C(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 h().exec(this.client);listNamespaces=()=>new x().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var A=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,cache:e?.cache===!1?void 0:e?.cache});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
+ "use strict";var U=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var Q=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _(e))!O.call(r,s)&&s!==t&&U(r,s,{get:()=>e[s],enumerable:!(a=D(e,s))||a.enumerable});return r};var $=r=>I(U({},"__esModule",{value:!0}),r);var k={};Q(k,{Index:()=>w});module.exports=$(k);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},this.retry=typeof e?.retry=="boolean"&&e?.retry===!1?{attempts:1,backoff:()=>0}:{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 T=0;T<=this.retry.attempts;T++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(N){if(this.options.signal?.aborted){let A=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),q={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(A,q);break}s=N,await new Promise(A=>setTimeout(A,this.retry.backoff(T)))}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(t===void 0)throw new TypeError("Request did not return a result");return t}};var m=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 h=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 p=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 d=class extends n{constructor(e,t){let a="upsert";Array.isArray(e)?a=e.some(o=>V(o))?"upsert":"upsert-data":a=V(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},V=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 u=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var l=class extends n{constructor(e){let t="reset";e?.namespace?t=`${t}/${e.namespace}`:e?.all&&(t=`${t}?all`),super([],t)}};var C=class extends n{constructor(){super([],"info")}};var R=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(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 p(e,{namespace:this.namespace}).exec(this.client);delete=e=>new m(e,{namespace:this.namespace}).exec(this.client);range=e=>new u(e,{namespace:this.namespace}).exec(this.client);reset=()=>new l({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(e){super(e,"resumable-query-next")}};var E=class extends n{constructor(e,t){let a="resumable-query";"data"in e&&(a="resumable-query-data"),t&&(a=`${a}/${t}`),super(e,a)}};var M=class extends n{constructor(e){super(e,"resumable-query-end")}};var g=class{uuid;start;fetchNext;stop;constructor(e,t,a){this.start=async()=>{let s=await new E(e,a).exec(t);return this.uuid=s.uuid,s},this.fetchNext=s=>{if(!this.uuid)throw new Error("The resumable query has already been stopped. Please start another resumable query.");return new x({uuid:this.uuid,additionalK:s}).exec(t)},this.stop=async()=>{if(!this.uuid)throw new Error("Resumable query has not been started. Call start() first.");let s=await new M({uuid:this.uuid}).exec(t);return this.uuid="",s}}};var b=class extends n{constructor(){super([],"list-namespaces")}};var P=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var S=class{client;constructor(e){this.client=e}namespace=e=>new R(this.client,e);delete=(e,t)=>new m(e,t).exec(this.client);query=(e,t)=>new p(e,t).exec(this.client);queryMany=(e,t)=>new h(e,t).exec(this.client);resumableQuery=async(e,t)=>{let a=new g(e,this.client,t?.namespace),s=await a.start(),{fetchNext:o,stop:T}=a;return{fetchNext:o,stop:T,result:s.scores}};upsert=(e,t)=>new d(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 l(e).exec(this.client);range=(e,t)=>new u(e,t).exec(this.client);info=()=>new C().exec(this.client);listNamespaces=()=>new b().exec(this.client);deleteNamespace=e=>new P(e).exec(this.client)};var w=class r extends S{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,cache:e?.cache===!1?void 0:e?.cache});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 r({...t,url:a,token:s})}};0&&(module.exports={Index});
@@ -1 +1 @@
1
- import{a as s,b as i}from"./chunk-J6ZA44LH.mjs";var o=class T extends i{constructor(e){let r=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(!r)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!"),(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:t,retry:e?.retry,headers:{authorization:`Bearer ${r}`},signal:e?.signal,cache:e?.cache===!1?void 0:e?.cache});super(n)}static fromEnv(e,r){let t,n;if(e){if(t=e.UPSTASH_VECTOR_REST_URL,!t)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=e.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:t,token:n})}};export{o as Index};
1
+ import{a as s,b as i}from"./chunk-AGHQGIQX.mjs";var o=class T extends i{constructor(e){let r=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(!r)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!"),(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:t,retry:e?.retry,headers:{authorization:`Bearer ${r}`},signal:e?.signal,cache:e?.cache===!1?void 0:e?.cache});super(n)}static fromEnv(e,r){let t,n;if(e){if(t=e.UPSTASH_VECTOR_REST_URL,!t)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=e.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:t,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-wT6XsV3D.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-wT6XsV3D.mjs';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-Kaq7eMt8.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-Kaq7eMt8.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-wT6XsV3D.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-wT6XsV3D.js';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-Kaq7eMt8.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-Kaq7eMt8.js';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
package/dist/nodejs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)b(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&&b(n,s,{get:()=>e[s],enumerable:!(a=w(e,s))||a.enumerable});return n};var O=n=>_(b({},"__esModule",{value:!0}),n);var q={};D(q,{Index:()=>A});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=>U(o))?"upsert":"upsert-data":a=U(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},U=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 A=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});
1
+ "use strict";var U=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var O=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Q(e))!q.call(r,s)&&s!==t&&U(r,s,{get:()=>e[s],enumerable:!(a=_(e,s))||a.enumerable});return r};var $=r=>I(U({},"__esModule",{value:!0}),r);var k={};O(k,{Index:()=>w});module.exports=$(k);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},this.retry=typeof e?.retry=="boolean"&&e?.retry===!1?{attempts:1,backoff:()=>0}:{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 T=0;T<=this.retry.attempts;T++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(N){if(this.options.signal?.aborted){let A=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),D={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(A,D);break}s=N,await new Promise(A=>setTimeout(A,this.retry.backoff(T)))}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(t===void 0)throw new TypeError("Request did not return a result");return t}};var m=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 h=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 p=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 d=class extends n{constructor(e,t){let a="upsert";Array.isArray(e)?a=e.some(o=>V(o))?"upsert":"upsert-data":a=V(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},V=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 u=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var l=class extends n{constructor(e){let t="reset";e?.namespace?t=`${t}/${e.namespace}`:e?.all&&(t=`${t}?all`),super([],t)}};var C=class extends n{constructor(){super([],"info")}};var x=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(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 p(e,{namespace:this.namespace}).exec(this.client);delete=e=>new m(e,{namespace:this.namespace}).exec(this.client);range=e=>new u(e,{namespace:this.namespace}).exec(this.client);reset=()=>new l({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 R=class extends n{constructor(e){super(e,"resumable-query-next")}};var E=class extends n{constructor(e,t){let a="resumable-query";"data"in e&&(a="resumable-query-data"),t&&(a=`${a}/${t}`),super(e,a)}};var M=class extends n{constructor(e){super(e,"resumable-query-end")}};var b=class{uuid;start;fetchNext;stop;constructor(e,t,a){this.start=async()=>{let s=await new E(e,a).exec(t);return this.uuid=s.uuid,s},this.fetchNext=s=>{if(!this.uuid)throw new Error("The resumable query has already been stopped. Please start another resumable query.");return new R({uuid:this.uuid,additionalK:s}).exec(t)},this.stop=async()=>{if(!this.uuid)throw new Error("Resumable query has not been started. Call start() first.");let s=await new M({uuid:this.uuid}).exec(t);return this.uuid="",s}}};var g=class extends n{constructor(){super([],"list-namespaces")}};var P=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var S=class{client;constructor(e){this.client=e}namespace=e=>new x(this.client,e);delete=(e,t)=>new m(e,t).exec(this.client);query=(e,t)=>new p(e,t).exec(this.client);queryMany=(e,t)=>new h(e,t).exec(this.client);resumableQuery=async(e,t)=>{let a=new b(e,this.client,t?.namespace),s=await a.start(),{fetchNext:o,stop:T}=a;return{fetchNext:o,stop:T,result:s.scores}};upsert=(e,t)=>new d(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 l(e).exec(this.client);range=(e,t)=>new u(e,t).exec(this.client);info=()=>new C().exec(this.client);listNamespaces=()=>new g().exec(this.client);deleteNamespace=e=>new P(e).exec(this.client)};var w=class r extends S{constructor(e){if(e!==void 0&&"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=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 r({...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-J6ZA44LH.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};
1
+ import{a as s,b as o}from"./chunk-AGHQGIQX.mjs";var T=class i extends o{constructor(e){if(e!==void 0&&"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};
@@ -10,9 +10,9 @@ type UpstashResponse<TResult> = {
10
10
  result?: TResult;
11
11
  error?: string;
12
12
  };
13
- interface Requester {
13
+ type Requester = {
14
14
  request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
15
- }
15
+ };
16
16
  type RetryConfig = false | {
17
17
  /**
18
18
  * The number of retries to attempt before giving up.
@@ -51,8 +51,8 @@ type Vector<TMetadata = Dict> = {
51
51
  type NAMESPACE = string;
52
52
  type Dict = Record<string, unknown>;
53
53
 
54
- declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
55
- type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
54
+ declare const _ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "resumable-query", "resumable-query-data", "resumable-query-next", "resumable-query-end", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
55
+ type EndpointVariants = (typeof _ENDPOINTS)[number] | `${(typeof _ENDPOINTS)[number]}/${NAMESPACE}` | `reset?all`;
56
56
  /**
57
57
  * TResult is the raw data returned from upstash, which may need to be transformed or parsed.
58
58
  */
@@ -126,6 +126,14 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
126
126
  constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
127
127
  }
128
128
 
129
+ type ResetCommandOptions = {
130
+ namespace?: string;
131
+ all?: never;
132
+ } | {
133
+ namespace?: never;
134
+ all?: true;
135
+ };
136
+
129
137
  type NamespaceTitle = string;
130
138
  type NamespaceInfo = {
131
139
  vectorCount: number;
@@ -312,6 +320,10 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
312
320
  reset: () => Promise<string>;
313
321
  }
314
322
 
323
+ type ResumableQueryPayload = {
324
+ maxIdle: number;
325
+ } & QueryCommandPayload;
326
+
315
327
  type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
316
328
  /**
317
329
  * Serverless vector client for upstash vector db.
@@ -410,6 +422,40 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
410
422
  queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
411
423
  namespace?: string;
412
424
  }) => Promise<QueryResult<TMetadata>[][]>;
425
+ /**
426
+ * Initializes a resumable query operation on the vector database.
427
+ * This method allows for querying large result sets in multiple chunks or implementing pagination.
428
+ *
429
+ * @template TMetadata
430
+ * @param {ResumableQueryPayload} args - The arguments for the resumable query.
431
+ * @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
432
+ * @param {number} args.topK - The number of top results to return in each fetch operation.
433
+ * @param {number[]} args.vector - The query vector used for similarity search.
434
+ * @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
435
+ * @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
436
+ * @param {Object} [options] - Additional options for the query.
437
+ * @param {string} [options.namespace] - The namespace to query within.
438
+ * @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
439
+ * @example
440
+ * const { result, fetchNext, stop } = await index.resumableQuery({
441
+ * maxIdle: 3600,
442
+ * topK: 50,
443
+ * vector: [0.1, 0.2, 0.3, ...],
444
+ * includeMetadata: true,
445
+ * includeVectors: true
446
+ * }, { namespace: 'my-namespace' });
447
+ *
448
+ * const firstBatch = await fetchNext(10);
449
+ * const secondBatch = await fetchNext(10);
450
+ * await stop(); // End the query session
451
+ */
452
+ resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload, options?: {
453
+ namespace?: string;
454
+ }) => Promise<{
455
+ fetchNext: (additionalK: number) => Promise<QueryResult[]>;
456
+ stop: () => Promise<string>;
457
+ result: QueryResult<TMetadata>[];
458
+ }>;
413
459
  /**
414
460
  * Upserts (Updates and Inserts) specific items into the index.
415
461
  * It's used for adding new items to the index or updating existing ones.
@@ -494,19 +540,35 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
494
540
  namespace?: string | undefined;
495
541
  } | undefined) => Promise<FetchResult<TMetadata>[]>;
496
542
  /**
497
- * It's used for wiping an entire index.
543
+ * It's used for wiping the index.
544
+ *
545
+ * By default, resets the default namespace:
498
546
  *
499
547
  * @example
500
548
  * ```js
501
549
  * await index.reset();
502
- * console.log('Index has been reset');
550
+ * console.log('Default namespace has been reset');
551
+ * ```
552
+ *
553
+ * To reset a namespace, call reset like:
554
+ *
555
+ * @example
556
+ * ```js
557
+ * await index.reset({ namespace: "ns" });
558
+ * console.log('Namespace ns has been reset');
559
+ * ```
560
+ *
561
+ * If you want to reset all namespaces, call reset like:
562
+ *
563
+ * @example
564
+ * ```js
565
+ * await index.reset({ all: true });
566
+ * console.log('All namespaces have been reset');
503
567
  * ```
504
568
  *
505
569
  * @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
506
570
  */
507
- reset: (options?: {
508
- namespace?: string;
509
- }) => Promise<string>;
571
+ reset: (options?: ResetCommandOptions) => Promise<string>;
510
572
  /**
511
573
  * Retrieves a range of items from the index.
512
574
  *
@@ -522,6 +584,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
522
584
  * console.log(rangeResults); // Outputs the result of the range operation
523
585
  * ```
524
586
  *
587
+ * You can also pass a namespace like:
588
+ *
589
+ * ```js
590
+ * const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
591
+ * ```
592
+ *
525
593
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
526
594
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
527
595
  * @param {number} args.limit - The maximum number of items to return in this range.
@@ -10,9 +10,9 @@ type UpstashResponse<TResult> = {
10
10
  result?: TResult;
11
11
  error?: string;
12
12
  };
13
- interface Requester {
13
+ type Requester = {
14
14
  request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
15
- }
15
+ };
16
16
  type RetryConfig = false | {
17
17
  /**
18
18
  * The number of retries to attempt before giving up.
@@ -51,8 +51,8 @@ type Vector<TMetadata = Dict> = {
51
51
  type NAMESPACE = string;
52
52
  type Dict = Record<string, unknown>;
53
53
 
54
- declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
55
- type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
54
+ declare const _ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "resumable-query", "resumable-query-data", "resumable-query-next", "resumable-query-end", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
55
+ type EndpointVariants = (typeof _ENDPOINTS)[number] | `${(typeof _ENDPOINTS)[number]}/${NAMESPACE}` | `reset?all`;
56
56
  /**
57
57
  * TResult is the raw data returned from upstash, which may need to be transformed or parsed.
58
58
  */
@@ -126,6 +126,14 @@ declare class RangeCommand<TMetadata> extends Command<RangeResult<TMetadata>> {
126
126
  constructor(payload: RangeCommandPayload, options?: RangeCommandOptions);
127
127
  }
128
128
 
129
+ type ResetCommandOptions = {
130
+ namespace?: string;
131
+ all?: never;
132
+ } | {
133
+ namespace?: never;
134
+ all?: true;
135
+ };
136
+
129
137
  type NamespaceTitle = string;
130
138
  type NamespaceInfo = {
131
139
  vectorCount: number;
@@ -312,6 +320,10 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
312
320
  reset: () => Promise<string>;
313
321
  }
314
322
 
323
+ type ResumableQueryPayload = {
324
+ maxIdle: number;
325
+ } & QueryCommandPayload;
326
+
315
327
  type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParameters<TCommand>[0];
316
328
  /**
317
329
  * Serverless vector client for upstash vector db.
@@ -410,6 +422,40 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
410
422
  queryMany: <TMetadata extends Dict = TIndexMetadata>(args: CommandArgs<typeof QueryManyCommand>, options?: {
411
423
  namespace?: string;
412
424
  }) => Promise<QueryResult<TMetadata>[][]>;
425
+ /**
426
+ * Initializes a resumable query operation on the vector database.
427
+ * This method allows for querying large result sets in multiple chunks or implementing pagination.
428
+ *
429
+ * @template TMetadata
430
+ * @param {ResumableQueryPayload} args - The arguments for the resumable query.
431
+ * @param {number} args.maxIdle - The maximum idle time in seconds before the query session expires.
432
+ * @param {number} args.topK - The number of top results to return in each fetch operation.
433
+ * @param {number[]} args.vector - The query vector used for similarity search.
434
+ * @param {boolean} [args.includeMetadata] - Whether to include metadata in the query results.
435
+ * @param {boolean} [args.includeVectors] - Whether to include vectors in the query results.
436
+ * @param {Object} [options] - Additional options for the query.
437
+ * @param {string} [options.namespace] - The namespace to query within.
438
+ * @returns {Promise<ResumableQuery<TMetadata>>} A promise that resolves to a ResumableQuery object.
439
+ * @example
440
+ * const { result, fetchNext, stop } = await index.resumableQuery({
441
+ * maxIdle: 3600,
442
+ * topK: 50,
443
+ * vector: [0.1, 0.2, 0.3, ...],
444
+ * includeMetadata: true,
445
+ * includeVectors: true
446
+ * }, { namespace: 'my-namespace' });
447
+ *
448
+ * const firstBatch = await fetchNext(10);
449
+ * const secondBatch = await fetchNext(10);
450
+ * await stop(); // End the query session
451
+ */
452
+ resumableQuery: <TMetadata extends Dict = TIndexMetadata>(args: ResumableQueryPayload, options?: {
453
+ namespace?: string;
454
+ }) => Promise<{
455
+ fetchNext: (additionalK: number) => Promise<QueryResult[]>;
456
+ stop: () => Promise<string>;
457
+ result: QueryResult<TMetadata>[];
458
+ }>;
413
459
  /**
414
460
  * Upserts (Updates and Inserts) specific items into the index.
415
461
  * It's used for adding new items to the index or updating existing ones.
@@ -494,19 +540,35 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
494
540
  namespace?: string | undefined;
495
541
  } | undefined) => Promise<FetchResult<TMetadata>[]>;
496
542
  /**
497
- * It's used for wiping an entire index.
543
+ * It's used for wiping the index.
544
+ *
545
+ * By default, resets the default namespace:
498
546
  *
499
547
  * @example
500
548
  * ```js
501
549
  * await index.reset();
502
- * console.log('Index has been reset');
550
+ * console.log('Default namespace has been reset');
551
+ * ```
552
+ *
553
+ * To reset a namespace, call reset like:
554
+ *
555
+ * @example
556
+ * ```js
557
+ * await index.reset({ namespace: "ns" });
558
+ * console.log('Namespace ns has been reset');
559
+ * ```
560
+ *
561
+ * If you want to reset all namespaces, call reset like:
562
+ *
563
+ * @example
564
+ * ```js
565
+ * await index.reset({ all: true });
566
+ * console.log('All namespaces have been reset');
503
567
  * ```
504
568
  *
505
569
  * @returns {Promise<string>} A promise that resolves with the result of the reset operation after the command is executed.
506
570
  */
507
- reset: (options?: {
508
- namespace?: string;
509
- }) => Promise<string>;
571
+ reset: (options?: ResetCommandOptions) => Promise<string>;
510
572
  /**
511
573
  * Retrieves a range of items from the index.
512
574
  *
@@ -522,6 +584,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
522
584
  * console.log(rangeResults); // Outputs the result of the range operation
523
585
  * ```
524
586
  *
587
+ * You can also pass a namespace like:
588
+ *
589
+ * ```js
590
+ * const rangeResults = await index.range(rangeArgs, { namespace: "ns" });
591
+ * ```
592
+ *
525
593
  * @param {CommandArgs<typeof RangeCommand>} args - The arguments for the range command.
526
594
  * @param {number|string} args.cursor - The starting point (cursor) for the range query.
527
595
  * @param {number} args.limit - The maximum number of items to return in this range.
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/vector", "version": "v1.1.5", "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" } }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "./nodejs": { "import": "./dist/nodejs.mjs", "types": "./dist/nodejs.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
+ { "name": "@upstash/vector", "version": "v1.1.6", "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" } }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "./nodejs": { "import": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts" } }, "main": "./dist/nodejs.js", "module": "./dist/nodejs.mjs", "browser": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts", "devDependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "@typescript-eslint/eslint-plugin": "^8.4.0", "bun-types": "latest", "eslint": "8.56", "eslint-plugin-unicorn": "^55.0.0", "husky": "^8.0.3", "prettier": "^3.3.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": "prettier --write .", "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix", "build": "tsup", "prepare": "husky install" } }
@@ -1 +0,0 @@
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=>b(o))?"upsert":"upsert-data":a=b(e)?"upsert":"upsert-data",t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}},b=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 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 T(e).exec(this.client)};export{E as a,R as b};