@synapcores/sdk 0.3.0 → 0.4.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/CHANGELOG.md +47 -0
- package/README.md +10 -0
- package/dist/index.d.mts +159 -2
- package/dist/index.d.ts +159 -2
- package/dist/index.js +199 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -332,6 +332,125 @@ var Collection = class {
|
|
|
332
332
|
}
|
|
333
333
|
};
|
|
334
334
|
|
|
335
|
+
// src/vector_collection.ts
|
|
336
|
+
var VectorCollection = class {
|
|
337
|
+
constructor(client, name) {
|
|
338
|
+
this.client = client;
|
|
339
|
+
this.name = name;
|
|
340
|
+
}
|
|
341
|
+
get basePath() {
|
|
342
|
+
return `/vectors/collections/${encodeURIComponent(this.name)}`;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Insert one or more vectors.
|
|
346
|
+
*
|
|
347
|
+
* Wire: `POST /v1/vectors/collections/{name}/vectors` with
|
|
348
|
+
* `{ vectors: [{ id, values, metadata }] }`.
|
|
349
|
+
*
|
|
350
|
+
* Accepts either a single record or an array — the SDK always sends
|
|
351
|
+
* the wrapped `{ vectors: [...] }` envelope the gateway expects.
|
|
352
|
+
*/
|
|
353
|
+
async insert(records) {
|
|
354
|
+
const vectors = Array.isArray(records) ? records : [records];
|
|
355
|
+
const { data } = await this.client._getHttpClient().post(
|
|
356
|
+
`${this.basePath}/vectors`,
|
|
357
|
+
{ vectors }
|
|
358
|
+
);
|
|
359
|
+
return data?.data ?? data;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* k-NN search over the vector collection.
|
|
363
|
+
*
|
|
364
|
+
* Wire: `POST /v1/vectors/collections/{name}/search` with
|
|
365
|
+
* `{ vector, k, include_metadata, filter? }`.
|
|
366
|
+
*
|
|
367
|
+
* Returns the bare array of hits — gateway envelope (`{data: [...]}`) is
|
|
368
|
+
* unwrapped automatically for parity with `Collection.vectorSearch`.
|
|
369
|
+
*/
|
|
370
|
+
async search(options) {
|
|
371
|
+
const k = options.k ?? options.topK ?? 10;
|
|
372
|
+
const body = {
|
|
373
|
+
vector: options.vector,
|
|
374
|
+
k,
|
|
375
|
+
include_metadata: options.includeMetadata !== false
|
|
376
|
+
};
|
|
377
|
+
if (options.filter !== void 0) body.filter = options.filter;
|
|
378
|
+
const { data } = await this.client._getHttpClient().post(
|
|
379
|
+
`${this.basePath}/search`,
|
|
380
|
+
body
|
|
381
|
+
);
|
|
382
|
+
const inner = data?.data ?? data;
|
|
383
|
+
if (Array.isArray(inner)) return inner;
|
|
384
|
+
return inner?.matches ?? inner?.results ?? inner?.hits ?? [];
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Fetch a single vector by id.
|
|
388
|
+
*
|
|
389
|
+
* Wire: `GET /v1/vectors/collections/{name}/vectors/{id}`. Returns the
|
|
390
|
+
* gateway payload `{ id, values, metadata }` (envelope unwrapped) or
|
|
391
|
+
* `null` on 404.
|
|
392
|
+
*/
|
|
393
|
+
async get(id) {
|
|
394
|
+
try {
|
|
395
|
+
const { data } = await this.client._getHttpClient().get(
|
|
396
|
+
`${this.basePath}/vectors/${encodeURIComponent(id)}`
|
|
397
|
+
);
|
|
398
|
+
return data?.data ?? data;
|
|
399
|
+
} catch (err) {
|
|
400
|
+
if (err?.code === "NOT_FOUND" || err?.status === 404) return null;
|
|
401
|
+
throw err;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Delete one or more vectors by id.
|
|
406
|
+
*
|
|
407
|
+
* Single-id wire: `DELETE /v1/vectors/collections/{name}/vectors/{id}`.
|
|
408
|
+
* Bulk wire: `DELETE /v1/vectors/collections/{name}/vectors` with
|
|
409
|
+
* `{ ids: [...] }` body.
|
|
410
|
+
*/
|
|
411
|
+
async delete(ids) {
|
|
412
|
+
if (typeof ids === "string") {
|
|
413
|
+
const { data: data2 } = await this.client._getHttpClient().delete(
|
|
414
|
+
`${this.basePath}/vectors/${encodeURIComponent(ids)}`
|
|
415
|
+
);
|
|
416
|
+
return data2?.data ?? data2;
|
|
417
|
+
}
|
|
418
|
+
const { data } = await this.client._getHttpClient().request({
|
|
419
|
+
method: "DELETE",
|
|
420
|
+
url: `${this.basePath}/vectors`,
|
|
421
|
+
data: { ids }
|
|
422
|
+
});
|
|
423
|
+
return data?.data ?? data;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Vector count.
|
|
427
|
+
*
|
|
428
|
+
* Wire: `GET /v1/vectors/collections/{name}/count` if the gateway
|
|
429
|
+
* exposes it, otherwise falls back to `info().vector_count`.
|
|
430
|
+
*/
|
|
431
|
+
async count() {
|
|
432
|
+
try {
|
|
433
|
+
const { data } = await this.client._getHttpClient().get(`${this.basePath}/count`);
|
|
434
|
+
const inner = data?.data ?? data;
|
|
435
|
+
const n = typeof inner === "number" ? inner : inner?.count ?? inner?.vector_count;
|
|
436
|
+
if (typeof n === "number") return n;
|
|
437
|
+
} catch {
|
|
438
|
+
}
|
|
439
|
+
const info = await this.info();
|
|
440
|
+
return typeof info?.vector_count === "number" ? info.vector_count : 0;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Collection metadata.
|
|
444
|
+
*
|
|
445
|
+
* Wire: `GET /v1/vectors/collections/{name}` returning
|
|
446
|
+
* `{ name, dimensions, vector_count, distance_metric, index_type }`.
|
|
447
|
+
*/
|
|
448
|
+
async info() {
|
|
449
|
+
const { data } = await this.client._getHttpClient().get(this.basePath);
|
|
450
|
+
return data?.data ?? data;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
335
454
|
// src/automl.ts
|
|
336
455
|
var AutoMLModel = class {
|
|
337
456
|
constructor(client, info) {
|
|
@@ -2773,6 +2892,20 @@ var SynapCores = class {
|
|
|
2773
2892
|
this.collectionsCache = /* @__PURE__ */ new Map();
|
|
2774
2893
|
this.currentTransaction = null;
|
|
2775
2894
|
this.preparedStatements = /* @__PURE__ */ new Map();
|
|
2895
|
+
// =================================================================
|
|
2896
|
+
// VECTOR COLLECTIONS — /v1/vectors/collections/{name}
|
|
2897
|
+
//
|
|
2898
|
+
// The gateway exposes two parallel "collection" worlds:
|
|
2899
|
+
// (a) document-store collections under /v1/collections (above), and
|
|
2900
|
+
// (b) vector collections under /v1/vectors/collections (below).
|
|
2901
|
+
//
|
|
2902
|
+
// v0.3.0 only wrapped (a) so vector-first users had to drop down to
|
|
2903
|
+
// `_getHttpClient()` to call (b) directly. v0.4.0 adds first-class
|
|
2904
|
+
// helpers — `createVectorCollection`, `vectorCollection(name)`,
|
|
2905
|
+
// `listVectorCollections`, `deleteVectorCollection` — that target (b)
|
|
2906
|
+
// and return a typed `VectorCollection` handle.
|
|
2907
|
+
// =================================================================
|
|
2908
|
+
this.vectorCollectionsCache = /* @__PURE__ */ new Map();
|
|
2776
2909
|
this.config = {
|
|
2777
2910
|
host: config.host || "localhost",
|
|
2778
2911
|
port: config.port || 8080,
|
|
@@ -2795,14 +2928,14 @@ var SynapCores = class {
|
|
|
2795
2928
|
if (this.config.jwtToken) {
|
|
2796
2929
|
authHeader["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
2797
2930
|
} else if (this.config.apiKey) {
|
|
2798
|
-
authHeader["
|
|
2931
|
+
authHeader["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2799
2932
|
}
|
|
2800
2933
|
this.httpClient = axios.create({
|
|
2801
2934
|
baseURL,
|
|
2802
2935
|
timeout: this.config.timeout,
|
|
2803
2936
|
headers: {
|
|
2804
2937
|
"Content-Type": "application/json",
|
|
2805
|
-
"User-Agent": "synapcores-nodejs/0.
|
|
2938
|
+
"User-Agent": "synapcores-nodejs/0.4.0",
|
|
2806
2939
|
...authHeader
|
|
2807
2940
|
},
|
|
2808
2941
|
...httpsAgent && { httpsAgent }
|
|
@@ -3027,6 +3160,67 @@ var SynapCores = class {
|
|
|
3027
3160
|
await this.httpClient.delete(`/collections/${name}`);
|
|
3028
3161
|
this.collectionsCache.delete(name);
|
|
3029
3162
|
}
|
|
3163
|
+
/**
|
|
3164
|
+
* Create a vector collection.
|
|
3165
|
+
*
|
|
3166
|
+
* Wire: `POST /v1/vectors/collections` with
|
|
3167
|
+
* `{ name, dimensions, distance_metric }`. Distinct from
|
|
3168
|
+
* `createCollection`, which targets the document-store subsystem.
|
|
3169
|
+
*
|
|
3170
|
+
* @example
|
|
3171
|
+
* const coll = await client.createVectorCollection({
|
|
3172
|
+
* name: 'memory_v1', dimensions: 1536, distance_metric: 'cosine',
|
|
3173
|
+
* });
|
|
3174
|
+
* await coll.insert({ id: 'v1', values: [...], metadata: { ... } });
|
|
3175
|
+
*/
|
|
3176
|
+
async createVectorCollection(options) {
|
|
3177
|
+
await this.httpClient.post("/vectors/collections", {
|
|
3178
|
+
name: options.name,
|
|
3179
|
+
dimensions: options.dimensions,
|
|
3180
|
+
distance_metric: options.distance_metric ?? "cosine"
|
|
3181
|
+
});
|
|
3182
|
+
const coll = new VectorCollection(this, options.name);
|
|
3183
|
+
this.vectorCollectionsCache.set(options.name, coll);
|
|
3184
|
+
return coll;
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
* Synchronous accessor for an existing vector collection. Does not
|
|
3188
|
+
* round-trip to the gateway — use `createVectorCollection` if you
|
|
3189
|
+
* need to provision the collection first, or `listVectorCollections`
|
|
3190
|
+
* to confirm existence.
|
|
3191
|
+
*
|
|
3192
|
+
* v0.4.0 split: this targets the **vector subsystem**
|
|
3193
|
+
* (`/v1/vectors/collections/{name}`). `client.collection(name)` still
|
|
3194
|
+
* returns a document-store `Collection` for the legacy subsystem.
|
|
3195
|
+
*/
|
|
3196
|
+
vectorCollection(name) {
|
|
3197
|
+
const cached = this.vectorCollectionsCache.get(name);
|
|
3198
|
+
if (cached) return cached;
|
|
3199
|
+
const coll = new VectorCollection(this, name);
|
|
3200
|
+
this.vectorCollectionsCache.set(name, coll);
|
|
3201
|
+
return coll;
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* List vector collections.
|
|
3205
|
+
*
|
|
3206
|
+
* Wire: `GET /v1/vectors/collections`. Returns the bare array of
|
|
3207
|
+
* collection-info objects (envelope unwrapped).
|
|
3208
|
+
*/
|
|
3209
|
+
async listVectorCollections() {
|
|
3210
|
+
const { data } = await this.httpClient.get("/vectors/collections");
|
|
3211
|
+
const inner = data?.data ?? data;
|
|
3212
|
+
if (Array.isArray(inner)) return inner;
|
|
3213
|
+
return inner?.items ?? inner?.collections ?? [];
|
|
3214
|
+
}
|
|
3215
|
+
/**
|
|
3216
|
+
* Delete a vector collection.
|
|
3217
|
+
*
|
|
3218
|
+
* Wire: `DELETE /v1/vectors/collections/{name}`.
|
|
3219
|
+
*/
|
|
3220
|
+
async deleteVectorCollection(name) {
|
|
3221
|
+
await this.httpClient.delete(`/vectors/collections/${encodeURIComponent(name)}`);
|
|
3222
|
+
this.vectorCollectionsCache.delete(name);
|
|
3223
|
+
}
|
|
3030
3224
|
/**
|
|
3031
3225
|
* Execute SQL query (legacy method for backward compatibility)
|
|
3032
3226
|
* @deprecated Use executeQuery for new code
|
|
@@ -3941,7 +4135,7 @@ var SynapCores = class {
|
|
|
3941
4135
|
|
|
3942
4136
|
// src/index.ts
|
|
3943
4137
|
import { z } from "zod";
|
|
3944
|
-
var VERSION = "0.
|
|
4138
|
+
var VERSION = "0.4.0";
|
|
3945
4139
|
export {
|
|
3946
4140
|
AuthenticationError,
|
|
3947
4141
|
AutoMLClient,
|
|
@@ -3975,6 +4169,7 @@ export {
|
|
|
3975
4169
|
Tx,
|
|
3976
4170
|
VERSION,
|
|
3977
4171
|
ValidationError,
|
|
4172
|
+
VectorCollection,
|
|
3978
4173
|
VectorError,
|
|
3979
4174
|
z
|
|
3980
4175
|
};
|