sutradb-core 5.6.0 → 5.6.1
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 +1 -1
- package/client.js +40 -19
- package/package.json +6 -6
package/README.md
CHANGED
package/client.js
CHANGED
|
@@ -31,13 +31,32 @@ function normalizeDocument(doc) {
|
|
|
31
31
|
return out;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function requirePathSegment(value, label) {
|
|
35
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
36
|
+
throw new SutraClientError(`${label} must be a non-empty string`);
|
|
37
|
+
}
|
|
38
|
+
return encodeURIComponent(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
class SutraClient {
|
|
35
42
|
constructor(optionsOrUrl = "http://localhost:8765") {
|
|
36
43
|
const opts =
|
|
37
44
|
typeof optionsOrUrl === "string"
|
|
38
45
|
? { baseUrl: optionsOrUrl }
|
|
39
46
|
: optionsOrUrl || {};
|
|
40
|
-
|
|
47
|
+
const rawBaseUrl = (opts.baseUrl || "http://localhost:8765").replace(/\/+$/, "");
|
|
48
|
+
let parsedUrl;
|
|
49
|
+
try {
|
|
50
|
+
parsedUrl = new URL(rawBaseUrl);
|
|
51
|
+
} catch {
|
|
52
|
+
throw new SutraClientError(`Invalid SutraDB baseUrl: ${rawBaseUrl}`);
|
|
53
|
+
}
|
|
54
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
55
|
+
throw new SutraClientError(
|
|
56
|
+
`Unsupported baseUrl protocol '${parsedUrl.protocol}'; expected http: or https:`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
this.baseUrl = rawBaseUrl;
|
|
41
60
|
this.apiKey = opts.apiKey;
|
|
42
61
|
this.timeoutMs = typeof opts.timeoutMs === "number" ? opts.timeoutMs : 30000;
|
|
43
62
|
this.defaultHeaders = Object.assign({}, opts.headers || {});
|
|
@@ -129,20 +148,20 @@ class SutraClient {
|
|
|
129
148
|
}
|
|
130
149
|
|
|
131
150
|
async dropCollection(name) {
|
|
132
|
-
return this._request("DELETE", `/collections/${
|
|
151
|
+
return this._request("DELETE", `/collections/${requirePathSegment(name, "collection")}`);
|
|
133
152
|
}
|
|
134
153
|
|
|
135
154
|
async stats(collection) {
|
|
136
155
|
return this._request(
|
|
137
156
|
"GET",
|
|
138
|
-
`/collections/${
|
|
157
|
+
`/collections/${requirePathSegment(collection, "collection")}/stats`
|
|
139
158
|
);
|
|
140
159
|
}
|
|
141
160
|
|
|
142
161
|
async insert(collection, documents) {
|
|
143
162
|
return this._request(
|
|
144
163
|
"POST",
|
|
145
|
-
`/collections/${
|
|
164
|
+
`/collections/${requirePathSegment(collection, "collection")}/insert`,
|
|
146
165
|
{ documents: documents.map(normalizeDocument) }
|
|
147
166
|
);
|
|
148
167
|
}
|
|
@@ -150,7 +169,7 @@ class SutraClient {
|
|
|
150
169
|
async upsert(collection, documents) {
|
|
151
170
|
return this._request(
|
|
152
171
|
"POST",
|
|
153
|
-
`/collections/${
|
|
172
|
+
`/collections/${requirePathSegment(collection, "collection")}/upsert`,
|
|
154
173
|
{ documents: documents.map(normalizeDocument) }
|
|
155
174
|
);
|
|
156
175
|
}
|
|
@@ -159,8 +178,9 @@ class SutraClient {
|
|
|
159
178
|
try {
|
|
160
179
|
return await this._request(
|
|
161
180
|
"GET",
|
|
162
|
-
`/collections/${
|
|
163
|
-
docId
|
|
181
|
+
`/collections/${requirePathSegment(collection, "collection")}/documents/${requirePathSegment(
|
|
182
|
+
docId,
|
|
183
|
+
"docId"
|
|
164
184
|
)}`
|
|
165
185
|
);
|
|
166
186
|
} catch (err) {
|
|
@@ -181,15 +201,16 @@ class SutraClient {
|
|
|
181
201
|
const suffix = qs ? `?${qs}` : "";
|
|
182
202
|
return this._request(
|
|
183
203
|
"GET",
|
|
184
|
-
`/collections/${
|
|
204
|
+
`/collections/${requirePathSegment(collection, "collection")}/documents${suffix}`
|
|
185
205
|
);
|
|
186
206
|
}
|
|
187
207
|
|
|
188
208
|
async updateMetadata(collection, docId, metadata) {
|
|
189
209
|
return this._request(
|
|
190
210
|
"PATCH",
|
|
191
|
-
`/collections/${
|
|
192
|
-
docId
|
|
211
|
+
`/collections/${requirePathSegment(collection, "collection")}/documents/${requirePathSegment(
|
|
212
|
+
docId,
|
|
213
|
+
"docId"
|
|
193
214
|
)}/metadata`,
|
|
194
215
|
{ metadata }
|
|
195
216
|
);
|
|
@@ -199,7 +220,7 @@ class SutraClient {
|
|
|
199
220
|
const idList = Array.isArray(ids) ? ids : [ids];
|
|
200
221
|
return this._request(
|
|
201
222
|
"DELETE",
|
|
202
|
-
`/collections/${
|
|
223
|
+
`/collections/${requirePathSegment(collection, "collection")}/documents`,
|
|
203
224
|
{ ids: idList }
|
|
204
225
|
);
|
|
205
226
|
}
|
|
@@ -241,7 +262,7 @@ class SutraClient {
|
|
|
241
262
|
|
|
242
263
|
const data = await this._request(
|
|
243
264
|
"POST",
|
|
244
|
-
`/collections/${
|
|
265
|
+
`/collections/${requirePathSegment(collection, "collection")}/query`,
|
|
245
266
|
payload
|
|
246
267
|
);
|
|
247
268
|
const raw = (data && data.results) || [];
|
|
@@ -261,7 +282,7 @@ class SutraClient {
|
|
|
261
282
|
async buildHnsw(collection, options = {}) {
|
|
262
283
|
return this._request(
|
|
263
284
|
"POST",
|
|
264
|
-
`/collections/${
|
|
285
|
+
`/collections/${requirePathSegment(collection, "collection")}/hnsw`,
|
|
265
286
|
{
|
|
266
287
|
m: options.m ?? 16,
|
|
267
288
|
ef_construction: options.efConstruction ?? 200,
|
|
@@ -273,7 +294,7 @@ class SutraClient {
|
|
|
273
294
|
async enableBq(collection) {
|
|
274
295
|
return this._request(
|
|
275
296
|
"POST",
|
|
276
|
-
`/collections/${
|
|
297
|
+
`/collections/${requirePathSegment(collection, "collection")}/bq`,
|
|
277
298
|
{}
|
|
278
299
|
);
|
|
279
300
|
}
|
|
@@ -281,7 +302,7 @@ class SutraClient {
|
|
|
281
302
|
async enableSq8(collection) {
|
|
282
303
|
return this._request(
|
|
283
304
|
"POST",
|
|
284
|
-
`/collections/${
|
|
305
|
+
`/collections/${requirePathSegment(collection, "collection")}/sq8`,
|
|
285
306
|
{}
|
|
286
307
|
);
|
|
287
308
|
}
|
|
@@ -289,7 +310,7 @@ class SutraClient {
|
|
|
289
310
|
async trainPq(collection, options = {}) {
|
|
290
311
|
return this._request(
|
|
291
312
|
"POST",
|
|
292
|
-
`/collections/${
|
|
313
|
+
`/collections/${requirePathSegment(collection, "collection")}/pq/train`,
|
|
293
314
|
{
|
|
294
315
|
m: options.m ?? null,
|
|
295
316
|
max_samples: options.maxSamples ?? null,
|
|
@@ -300,7 +321,7 @@ class SutraClient {
|
|
|
300
321
|
async enablePq(collection) {
|
|
301
322
|
return this._request(
|
|
302
323
|
"POST",
|
|
303
|
-
`/collections/${
|
|
324
|
+
`/collections/${requirePathSegment(collection, "collection")}/pq`,
|
|
304
325
|
{}
|
|
305
326
|
);
|
|
306
327
|
}
|
|
@@ -308,7 +329,7 @@ class SutraClient {
|
|
|
308
329
|
async compact(collection) {
|
|
309
330
|
return this._request(
|
|
310
331
|
"POST",
|
|
311
|
-
`/collections/${
|
|
332
|
+
`/collections/${requirePathSegment(collection, "collection")}/compact`,
|
|
312
333
|
{}
|
|
313
334
|
);
|
|
314
335
|
}
|
|
@@ -316,7 +337,7 @@ class SutraClient {
|
|
|
316
337
|
async save(collection) {
|
|
317
338
|
return this._request(
|
|
318
339
|
"POST",
|
|
319
|
-
`/collections/${
|
|
340
|
+
`/collections/${requirePathSegment(collection, "collection")}/save`,
|
|
320
341
|
{}
|
|
321
342
|
);
|
|
322
343
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sutradb-core",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.1",
|
|
4
4
|
"description": "Embedded Rust + Node.js hybrid vector database (HNSW, BM25, WAND sparse, ColBERT) with zero-copy Float32Array SIMD, 32x BQ, and sub-ms Roaring filtering, plus zero-dependency SutraClient.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -81,10 +81,10 @@
|
|
|
81
81
|
"@napi-rs/cli": "^2.18.4"
|
|
82
82
|
},
|
|
83
83
|
"optionalDependencies": {
|
|
84
|
-
"sutradb-core-darwin-arm64": "5.6.
|
|
85
|
-
"sutradb-core-darwin-x64": "5.6.
|
|
86
|
-
"sutradb-core-linux-arm64-gnu": "5.6.
|
|
87
|
-
"sutradb-core-linux-x64-gnu": "5.6.
|
|
88
|
-
"sutradb-core-win32-x64-msvc": "5.6.
|
|
84
|
+
"sutradb-core-darwin-arm64": "5.6.1",
|
|
85
|
+
"sutradb-core-darwin-x64": "5.6.1",
|
|
86
|
+
"sutradb-core-linux-arm64-gnu": "5.6.1",
|
|
87
|
+
"sutradb-core-linux-x64-gnu": "5.6.1",
|
|
88
|
+
"sutradb-core-win32-x64-msvc": "5.6.1"
|
|
89
89
|
}
|
|
90
90
|
}
|