@upstash/vector 1.0.8-canary → 1.1.0
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 +100 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,43 +61,58 @@ await index.upsert([{
|
|
|
61
61
|
}])
|
|
62
62
|
|
|
63
63
|
//Query Data
|
|
64
|
-
const results = await index.query<Metadata>(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
const results = await index.query<Metadata>(
|
|
65
|
+
{
|
|
66
|
+
vector: [
|
|
67
|
+
... // query embedding
|
|
68
|
+
],
|
|
69
|
+
includeVectors: true,
|
|
70
|
+
includeMetadata: true
|
|
71
|
+
topK: 1,
|
|
72
|
+
filter: "genre = 'fantasy' and title = 'Lord of the Rings'"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
namespace: "example-namespace"
|
|
76
|
+
}
|
|
77
|
+
)
|
|
73
78
|
|
|
74
79
|
// If you wanna learn more about filtering check: [Metadata Filtering](https://upstash.com/docs/vector/features/filtering)
|
|
75
80
|
|
|
76
81
|
//Update Data
|
|
77
|
-
await index.upsert(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
await index.upsert(
|
|
83
|
+
{
|
|
84
|
+
id: "upstash-rocks",
|
|
85
|
+
metadata: {
|
|
86
|
+
title: 'Star Wars',
|
|
87
|
+
genre: 'sci-fi',
|
|
88
|
+
category: 'classic'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
namespace: "namespace"
|
|
83
93
|
}
|
|
84
|
-
|
|
94
|
+
);
|
|
85
95
|
|
|
86
96
|
//Delete record
|
|
87
|
-
await index.delete("upstash-rocks");
|
|
97
|
+
await index.delete("upstash-rocks", {namespace: "example-namespace"});
|
|
88
98
|
|
|
89
99
|
//Delete many by id
|
|
90
100
|
await index.delete(["id-1", "id-2", "id-3"]);
|
|
91
101
|
|
|
92
102
|
//Fetch records by their IDs
|
|
93
|
-
await index.fetch(["id-1", "id-2"]);
|
|
103
|
+
await index.fetch(["id-1", "id-2"], {namespace: "example-namespace"});
|
|
94
104
|
|
|
95
105
|
//Fetch records with range
|
|
96
|
-
await index.range(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
await index.range(
|
|
107
|
+
{
|
|
108
|
+
cursor: 0,
|
|
109
|
+
limit: 5,
|
|
110
|
+
includeVectors: true,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
namespace: "example-namespace"
|
|
114
|
+
}
|
|
115
|
+
);
|
|
101
116
|
|
|
102
117
|
//Reset index
|
|
103
118
|
await index.reset();
|
|
@@ -106,7 +121,68 @@ await index.reset();
|
|
|
106
121
|
await index.info();
|
|
107
122
|
|
|
108
123
|
//Random vector based on stored vectors
|
|
109
|
-
await index.random();
|
|
124
|
+
await index.random({namespace: "example-namespace"});
|
|
125
|
+
|
|
126
|
+
//List existing namesapces
|
|
127
|
+
await index.listNamespaces();
|
|
128
|
+
|
|
129
|
+
//Delete a namespace
|
|
130
|
+
await index.deleteNamespace("namespace-to-be-deleted");
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Namespaces
|
|
134
|
+
|
|
135
|
+
Upstash Vector allows you to partition a single index into multiple isolated namespaces. Each namespace functions as a self-contained subset of the index, in which read and write requests are only limited to one namespace. To learn more about it, see [Namespaces](https://upstash.com/docs/vector/features/namespaces)
|
|
136
|
+
|
|
137
|
+
# Example
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { Index } from "@upstash/vector";
|
|
141
|
+
|
|
142
|
+
type Metadata = {
|
|
143
|
+
title: string;
|
|
144
|
+
genre: "sci-fi" | "fantasy" | "horror" | "action";
|
|
145
|
+
category: "classic" | "modern";
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const index = new Index<Metadata>({
|
|
149
|
+
url: "<UPSTASH_VECTOR_REST_URL>",
|
|
150
|
+
token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const namespace = index.namespace("example-namespace");
|
|
154
|
+
|
|
155
|
+
//Upsert Data
|
|
156
|
+
await namespace.upsert([{
|
|
157
|
+
id: 'upstash-rocks',
|
|
158
|
+
vector: [
|
|
159
|
+
.... // embedding values
|
|
160
|
+
],
|
|
161
|
+
metadata: {
|
|
162
|
+
title: 'Lord of The Rings',
|
|
163
|
+
genre: 'fantasy',
|
|
164
|
+
category: 'classic'
|
|
165
|
+
}
|
|
166
|
+
}])
|
|
167
|
+
|
|
168
|
+
//Query Vector
|
|
169
|
+
const results = await namespace.query<Metadata>(
|
|
170
|
+
{
|
|
171
|
+
vector: [
|
|
172
|
+
... // query embedding
|
|
173
|
+
],
|
|
174
|
+
includeVectors: true,
|
|
175
|
+
includeMetadata: true
|
|
176
|
+
topK: 1,
|
|
177
|
+
filter: "genre = 'fantasy' and title = 'Lord of the Rings'"
|
|
178
|
+
},
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
//Delete Record
|
|
182
|
+
await namespace.delete("upstash-rocks");
|
|
183
|
+
|
|
184
|
+
//Fetch records by their IDs
|
|
185
|
+
await namespace.fetch(["id-1", "id-2"]);
|
|
110
186
|
```
|
|
111
187
|
|
|
112
188
|
## Metadata Filtering
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.0
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.0", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "main": "./dist/index.js", "module": "./dist/index.mjs", "devDependencies": { "@biomejs/biome": "^1.4.1", "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "bun-types": "latest", "husky": "^8.0.3", "tsup": "latest", "typescript": "^5.0.0", "vitest": "^1.2.2" }, "bugs": { "url": "https://github.com/upstash/vector/issues" }, "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "files": [ "dist" ], "homepage": "https://upstash.com/vector", "keywords": [ "vector", "upstash", "db" ], "license": "MIT", "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000 && vitest run --typecheck", "fmt": "bunx biome check --apply ./src", "build": "tsup", "prepare": "husky install" }, "types": "./dist/index.d.ts" }
|