@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.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
Tx: () => Tx,
|
|
63
63
|
VERSION: () => VERSION,
|
|
64
64
|
ValidationError: () => ValidationError,
|
|
65
|
+
VectorCollection: () => VectorCollection,
|
|
65
66
|
VectorError: () => VectorError,
|
|
66
67
|
z: () => import_zod.z
|
|
67
68
|
});
|
|
@@ -394,6 +395,125 @@ var Collection = class {
|
|
|
394
395
|
}
|
|
395
396
|
};
|
|
396
397
|
|
|
398
|
+
// src/vector_collection.ts
|
|
399
|
+
var VectorCollection = class {
|
|
400
|
+
constructor(client, name) {
|
|
401
|
+
this.client = client;
|
|
402
|
+
this.name = name;
|
|
403
|
+
}
|
|
404
|
+
get basePath() {
|
|
405
|
+
return `/vectors/collections/${encodeURIComponent(this.name)}`;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Insert one or more vectors.
|
|
409
|
+
*
|
|
410
|
+
* Wire: `POST /v1/vectors/collections/{name}/vectors` with
|
|
411
|
+
* `{ vectors: [{ id, values, metadata }] }`.
|
|
412
|
+
*
|
|
413
|
+
* Accepts either a single record or an array — the SDK always sends
|
|
414
|
+
* the wrapped `{ vectors: [...] }` envelope the gateway expects.
|
|
415
|
+
*/
|
|
416
|
+
async insert(records) {
|
|
417
|
+
const vectors = Array.isArray(records) ? records : [records];
|
|
418
|
+
const { data } = await this.client._getHttpClient().post(
|
|
419
|
+
`${this.basePath}/vectors`,
|
|
420
|
+
{ vectors }
|
|
421
|
+
);
|
|
422
|
+
return data?.data ?? data;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* k-NN search over the vector collection.
|
|
426
|
+
*
|
|
427
|
+
* Wire: `POST /v1/vectors/collections/{name}/search` with
|
|
428
|
+
* `{ vector, k, include_metadata, filter? }`.
|
|
429
|
+
*
|
|
430
|
+
* Returns the bare array of hits — gateway envelope (`{data: [...]}`) is
|
|
431
|
+
* unwrapped automatically for parity with `Collection.vectorSearch`.
|
|
432
|
+
*/
|
|
433
|
+
async search(options) {
|
|
434
|
+
const k = options.k ?? options.topK ?? 10;
|
|
435
|
+
const body = {
|
|
436
|
+
vector: options.vector,
|
|
437
|
+
k,
|
|
438
|
+
include_metadata: options.includeMetadata !== false
|
|
439
|
+
};
|
|
440
|
+
if (options.filter !== void 0) body.filter = options.filter;
|
|
441
|
+
const { data } = await this.client._getHttpClient().post(
|
|
442
|
+
`${this.basePath}/search`,
|
|
443
|
+
body
|
|
444
|
+
);
|
|
445
|
+
const inner = data?.data ?? data;
|
|
446
|
+
if (Array.isArray(inner)) return inner;
|
|
447
|
+
return inner?.matches ?? inner?.results ?? inner?.hits ?? [];
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Fetch a single vector by id.
|
|
451
|
+
*
|
|
452
|
+
* Wire: `GET /v1/vectors/collections/{name}/vectors/{id}`. Returns the
|
|
453
|
+
* gateway payload `{ id, values, metadata }` (envelope unwrapped) or
|
|
454
|
+
* `null` on 404.
|
|
455
|
+
*/
|
|
456
|
+
async get(id) {
|
|
457
|
+
try {
|
|
458
|
+
const { data } = await this.client._getHttpClient().get(
|
|
459
|
+
`${this.basePath}/vectors/${encodeURIComponent(id)}`
|
|
460
|
+
);
|
|
461
|
+
return data?.data ?? data;
|
|
462
|
+
} catch (err) {
|
|
463
|
+
if (err?.code === "NOT_FOUND" || err?.status === 404) return null;
|
|
464
|
+
throw err;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Delete one or more vectors by id.
|
|
469
|
+
*
|
|
470
|
+
* Single-id wire: `DELETE /v1/vectors/collections/{name}/vectors/{id}`.
|
|
471
|
+
* Bulk wire: `DELETE /v1/vectors/collections/{name}/vectors` with
|
|
472
|
+
* `{ ids: [...] }` body.
|
|
473
|
+
*/
|
|
474
|
+
async delete(ids) {
|
|
475
|
+
if (typeof ids === "string") {
|
|
476
|
+
const { data: data2 } = await this.client._getHttpClient().delete(
|
|
477
|
+
`${this.basePath}/vectors/${encodeURIComponent(ids)}`
|
|
478
|
+
);
|
|
479
|
+
return data2?.data ?? data2;
|
|
480
|
+
}
|
|
481
|
+
const { data } = await this.client._getHttpClient().request({
|
|
482
|
+
method: "DELETE",
|
|
483
|
+
url: `${this.basePath}/vectors`,
|
|
484
|
+
data: { ids }
|
|
485
|
+
});
|
|
486
|
+
return data?.data ?? data;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Vector count.
|
|
490
|
+
*
|
|
491
|
+
* Wire: `GET /v1/vectors/collections/{name}/count` if the gateway
|
|
492
|
+
* exposes it, otherwise falls back to `info().vector_count`.
|
|
493
|
+
*/
|
|
494
|
+
async count() {
|
|
495
|
+
try {
|
|
496
|
+
const { data } = await this.client._getHttpClient().get(`${this.basePath}/count`);
|
|
497
|
+
const inner = data?.data ?? data;
|
|
498
|
+
const n = typeof inner === "number" ? inner : inner?.count ?? inner?.vector_count;
|
|
499
|
+
if (typeof n === "number") return n;
|
|
500
|
+
} catch {
|
|
501
|
+
}
|
|
502
|
+
const info = await this.info();
|
|
503
|
+
return typeof info?.vector_count === "number" ? info.vector_count : 0;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Collection metadata.
|
|
507
|
+
*
|
|
508
|
+
* Wire: `GET /v1/vectors/collections/{name}` returning
|
|
509
|
+
* `{ name, dimensions, vector_count, distance_metric, index_type }`.
|
|
510
|
+
*/
|
|
511
|
+
async info() {
|
|
512
|
+
const { data } = await this.client._getHttpClient().get(this.basePath);
|
|
513
|
+
return data?.data ?? data;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
397
517
|
// src/automl.ts
|
|
398
518
|
var AutoMLModel = class {
|
|
399
519
|
constructor(client, info) {
|
|
@@ -2835,6 +2955,20 @@ var SynapCores = class {
|
|
|
2835
2955
|
this.collectionsCache = /* @__PURE__ */ new Map();
|
|
2836
2956
|
this.currentTransaction = null;
|
|
2837
2957
|
this.preparedStatements = /* @__PURE__ */ new Map();
|
|
2958
|
+
// =================================================================
|
|
2959
|
+
// VECTOR COLLECTIONS — /v1/vectors/collections/{name}
|
|
2960
|
+
//
|
|
2961
|
+
// The gateway exposes two parallel "collection" worlds:
|
|
2962
|
+
// (a) document-store collections under /v1/collections (above), and
|
|
2963
|
+
// (b) vector collections under /v1/vectors/collections (below).
|
|
2964
|
+
//
|
|
2965
|
+
// v0.3.0 only wrapped (a) so vector-first users had to drop down to
|
|
2966
|
+
// `_getHttpClient()` to call (b) directly. v0.4.0 adds first-class
|
|
2967
|
+
// helpers — `createVectorCollection`, `vectorCollection(name)`,
|
|
2968
|
+
// `listVectorCollections`, `deleteVectorCollection` — that target (b)
|
|
2969
|
+
// and return a typed `VectorCollection` handle.
|
|
2970
|
+
// =================================================================
|
|
2971
|
+
this.vectorCollectionsCache = /* @__PURE__ */ new Map();
|
|
2838
2972
|
this.config = {
|
|
2839
2973
|
host: config.host || "localhost",
|
|
2840
2974
|
port: config.port || 8080,
|
|
@@ -2857,14 +2991,14 @@ var SynapCores = class {
|
|
|
2857
2991
|
if (this.config.jwtToken) {
|
|
2858
2992
|
authHeader["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
2859
2993
|
} else if (this.config.apiKey) {
|
|
2860
|
-
authHeader["
|
|
2994
|
+
authHeader["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2861
2995
|
}
|
|
2862
2996
|
this.httpClient = import_axios.default.create({
|
|
2863
2997
|
baseURL,
|
|
2864
2998
|
timeout: this.config.timeout,
|
|
2865
2999
|
headers: {
|
|
2866
3000
|
"Content-Type": "application/json",
|
|
2867
|
-
"User-Agent": "synapcores-nodejs/0.
|
|
3001
|
+
"User-Agent": "synapcores-nodejs/0.4.0",
|
|
2868
3002
|
...authHeader
|
|
2869
3003
|
},
|
|
2870
3004
|
...httpsAgent && { httpsAgent }
|
|
@@ -3089,6 +3223,67 @@ var SynapCores = class {
|
|
|
3089
3223
|
await this.httpClient.delete(`/collections/${name}`);
|
|
3090
3224
|
this.collectionsCache.delete(name);
|
|
3091
3225
|
}
|
|
3226
|
+
/**
|
|
3227
|
+
* Create a vector collection.
|
|
3228
|
+
*
|
|
3229
|
+
* Wire: `POST /v1/vectors/collections` with
|
|
3230
|
+
* `{ name, dimensions, distance_metric }`. Distinct from
|
|
3231
|
+
* `createCollection`, which targets the document-store subsystem.
|
|
3232
|
+
*
|
|
3233
|
+
* @example
|
|
3234
|
+
* const coll = await client.createVectorCollection({
|
|
3235
|
+
* name: 'memory_v1', dimensions: 1536, distance_metric: 'cosine',
|
|
3236
|
+
* });
|
|
3237
|
+
* await coll.insert({ id: 'v1', values: [...], metadata: { ... } });
|
|
3238
|
+
*/
|
|
3239
|
+
async createVectorCollection(options) {
|
|
3240
|
+
await this.httpClient.post("/vectors/collections", {
|
|
3241
|
+
name: options.name,
|
|
3242
|
+
dimensions: options.dimensions,
|
|
3243
|
+
distance_metric: options.distance_metric ?? "cosine"
|
|
3244
|
+
});
|
|
3245
|
+
const coll = new VectorCollection(this, options.name);
|
|
3246
|
+
this.vectorCollectionsCache.set(options.name, coll);
|
|
3247
|
+
return coll;
|
|
3248
|
+
}
|
|
3249
|
+
/**
|
|
3250
|
+
* Synchronous accessor for an existing vector collection. Does not
|
|
3251
|
+
* round-trip to the gateway — use `createVectorCollection` if you
|
|
3252
|
+
* need to provision the collection first, or `listVectorCollections`
|
|
3253
|
+
* to confirm existence.
|
|
3254
|
+
*
|
|
3255
|
+
* v0.4.0 split: this targets the **vector subsystem**
|
|
3256
|
+
* (`/v1/vectors/collections/{name}`). `client.collection(name)` still
|
|
3257
|
+
* returns a document-store `Collection` for the legacy subsystem.
|
|
3258
|
+
*/
|
|
3259
|
+
vectorCollection(name) {
|
|
3260
|
+
const cached = this.vectorCollectionsCache.get(name);
|
|
3261
|
+
if (cached) return cached;
|
|
3262
|
+
const coll = new VectorCollection(this, name);
|
|
3263
|
+
this.vectorCollectionsCache.set(name, coll);
|
|
3264
|
+
return coll;
|
|
3265
|
+
}
|
|
3266
|
+
/**
|
|
3267
|
+
* List vector collections.
|
|
3268
|
+
*
|
|
3269
|
+
* Wire: `GET /v1/vectors/collections`. Returns the bare array of
|
|
3270
|
+
* collection-info objects (envelope unwrapped).
|
|
3271
|
+
*/
|
|
3272
|
+
async listVectorCollections() {
|
|
3273
|
+
const { data } = await this.httpClient.get("/vectors/collections");
|
|
3274
|
+
const inner = data?.data ?? data;
|
|
3275
|
+
if (Array.isArray(inner)) return inner;
|
|
3276
|
+
return inner?.items ?? inner?.collections ?? [];
|
|
3277
|
+
}
|
|
3278
|
+
/**
|
|
3279
|
+
* Delete a vector collection.
|
|
3280
|
+
*
|
|
3281
|
+
* Wire: `DELETE /v1/vectors/collections/{name}`.
|
|
3282
|
+
*/
|
|
3283
|
+
async deleteVectorCollection(name) {
|
|
3284
|
+
await this.httpClient.delete(`/vectors/collections/${encodeURIComponent(name)}`);
|
|
3285
|
+
this.vectorCollectionsCache.delete(name);
|
|
3286
|
+
}
|
|
3092
3287
|
/**
|
|
3093
3288
|
* Execute SQL query (legacy method for backward compatibility)
|
|
3094
3289
|
* @deprecated Use executeQuery for new code
|
|
@@ -4003,7 +4198,7 @@ var SynapCores = class {
|
|
|
4003
4198
|
|
|
4004
4199
|
// src/index.ts
|
|
4005
4200
|
var import_zod = require("zod");
|
|
4006
|
-
var VERSION = "0.
|
|
4201
|
+
var VERSION = "0.4.0";
|
|
4007
4202
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4008
4203
|
0 && (module.exports = {
|
|
4009
4204
|
AuthenticationError,
|
|
@@ -4038,6 +4233,7 @@ var VERSION = "0.3.0";
|
|
|
4038
4233
|
Tx,
|
|
4039
4234
|
VERSION,
|
|
4040
4235
|
ValidationError,
|
|
4236
|
+
VectorCollection,
|
|
4041
4237
|
VectorError,
|
|
4042
4238
|
z
|
|
4043
4239
|
});
|