@upstash/vector 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-XN6MKCVR.mjs +761 -0
- package/dist/cloudflare.d.mts +2 -2
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +860 -1
- package/dist/cloudflare.mjs +81 -1
- package/dist/nodejs.d.mts +2 -2
- package/dist/nodejs.d.ts +2 -2
- package/dist/nodejs.js +839 -1
- package/dist/nodejs.mjs +60 -1
- package/dist/{vector-Kaq7eMt8.d.mts → vector-gR6tGrYi.d.mts} +5 -3
- package/dist/{vector-Kaq7eMt8.d.ts → vector-gR6tGrYi.d.ts} +5 -3
- package/package.json +1 -1
- package/dist/chunk-AGHQGIQX.mjs +0 -1
package/dist/nodejs.mjs
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
HttpClient,
|
|
3
|
+
Index
|
|
4
|
+
} from "./chunk-XN6MKCVR.mjs";
|
|
5
|
+
|
|
6
|
+
// src/platforms/nodejs.ts
|
|
7
|
+
var Index2 = class _Index extends Index {
|
|
8
|
+
constructor(configOrRequester) {
|
|
9
|
+
if (configOrRequester !== void 0 && "request" in configOrRequester) {
|
|
10
|
+
super(configOrRequester);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const token = configOrRequester?.token ?? process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN ?? process.env.UPSTASH_VECTOR_REST_TOKEN;
|
|
14
|
+
const url = configOrRequester?.url ?? process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL ?? process.env.UPSTASH_VECTOR_REST_URL;
|
|
15
|
+
if (!token) {
|
|
16
|
+
throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");
|
|
17
|
+
}
|
|
18
|
+
if (!url) {
|
|
19
|
+
throw new Error("UPSTASH_VECTOR_REST_URL is missing!");
|
|
20
|
+
}
|
|
21
|
+
if (url.startsWith(" ") || url.endsWith(" ") || /\r|\n/.test(url)) {
|
|
22
|
+
console.warn("The vector url contains whitespace or newline, which can cause errors!");
|
|
23
|
+
}
|
|
24
|
+
if (token.startsWith(" ") || token.endsWith(" ") || /\r|\n/.test(token)) {
|
|
25
|
+
console.warn("The vector token contains whitespace or newline, which can cause errors!");
|
|
26
|
+
}
|
|
27
|
+
const client = new HttpClient({
|
|
28
|
+
baseUrl: url,
|
|
29
|
+
retry: configOrRequester?.retry,
|
|
30
|
+
headers: { authorization: `Bearer ${token}` },
|
|
31
|
+
cache: configOrRequester?.cache === false ? void 0 : configOrRequester?.cache || "no-store",
|
|
32
|
+
signal: configOrRequester?.signal
|
|
33
|
+
});
|
|
34
|
+
super(client);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
38
|
+
*
|
|
39
|
+
* Use this to automatically load connection secrets from your environment
|
|
40
|
+
* variables. For instance when using the Vercel integration.
|
|
41
|
+
*
|
|
42
|
+
* When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
|
|
43
|
+
* Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
44
|
+
* your environment using `process.env`.
|
|
45
|
+
*/
|
|
46
|
+
static fromEnv(env, config) {
|
|
47
|
+
const url = env?.UPSTASH_VECTOR_REST_URL || process?.env.UPSTASH_VECTOR_REST_URL;
|
|
48
|
+
const token = env?.UPSTASH_VECTOR_REST_TOKEN || process?.env.UPSTASH_VECTOR_REST_TOKEN;
|
|
49
|
+
if (!url) {
|
|
50
|
+
throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");
|
|
51
|
+
}
|
|
52
|
+
if (!token) {
|
|
53
|
+
throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");
|
|
54
|
+
}
|
|
55
|
+
return new _Index({ ...config, url, token });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
Index2 as Index
|
|
60
|
+
};
|
|
@@ -274,10 +274,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
274
274
|
* @example
|
|
275
275
|
* ```js
|
|
276
276
|
* await index.namespace("ns").delete('test-id')
|
|
277
|
+
* // { deleted: 1 }
|
|
277
278
|
* ```
|
|
278
279
|
*
|
|
279
280
|
* @param id - List of ids or single id
|
|
280
|
-
* @returns
|
|
281
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
281
282
|
*/
|
|
282
283
|
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
283
284
|
deleted: number;
|
|
@@ -348,11 +349,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
348
349
|
*
|
|
349
350
|
* @example
|
|
350
351
|
* ```js
|
|
351
|
-
* await index.delete('test-id')
|
|
352
|
+
* const result = await index.delete('test-id');
|
|
353
|
+
* // { deleted: 1 }
|
|
352
354
|
* ```
|
|
353
355
|
*
|
|
354
356
|
* @param id - List of ids or single id
|
|
355
|
-
* @returns
|
|
357
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
356
358
|
*/
|
|
357
359
|
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
358
360
|
namespace?: string;
|
|
@@ -274,10 +274,11 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
274
274
|
* @example
|
|
275
275
|
* ```js
|
|
276
276
|
* await index.namespace("ns").delete('test-id')
|
|
277
|
+
* // { deleted: 1 }
|
|
277
278
|
* ```
|
|
278
279
|
*
|
|
279
280
|
* @param id - List of ids or single id
|
|
280
|
-
* @returns
|
|
281
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
281
282
|
*/
|
|
282
283
|
delete: (args: CommandArgs<typeof DeleteCommand>) => Promise<{
|
|
283
284
|
deleted: number;
|
|
@@ -348,11 +349,12 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
|
348
349
|
*
|
|
349
350
|
* @example
|
|
350
351
|
* ```js
|
|
351
|
-
* await index.delete('test-id')
|
|
352
|
+
* const result = await index.delete('test-id');
|
|
353
|
+
* // { deleted: 1 }
|
|
352
354
|
* ```
|
|
353
355
|
*
|
|
354
356
|
* @param id - List of ids or single id
|
|
355
|
-
* @returns
|
|
357
|
+
* @returns Number of deleted vectors like `{ deleted: number }`. The number will be 0 if no vectors are deleted.
|
|
356
358
|
*/
|
|
357
359
|
delete: (args: CommandArgs<typeof DeleteCommand>, options?: {
|
|
358
360
|
namespace?: string;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.1.
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.7", "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" }, "./cloudflare": { "import": "./dist/cloudflare.mjs", "require": "./dist/cloudflare.js" }, "./nodejs": { "import": "./dist/nodejs.mjs", "require": "./dist/nodejs.js" } }, "main": "./dist/nodejs.js", "module": "./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": "9.10.0", "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" } }
|
package/dist/chunk-AGHQGIQX.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|