@synapcores/sdk 0.3.0 → 0.4.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/CHANGELOG.md +47 -0
- package/README.md +10 -0
- package/dist/index.d.mts +161 -2
- package/dist/index.d.ts +161 -2
- package/dist/index.js +203 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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) {
|
|
@@ -1982,6 +2102,10 @@ var GraphEdgeApi = class {
|
|
|
1982
2102
|
properties: data.properties ?? props
|
|
1983
2103
|
};
|
|
1984
2104
|
}
|
|
2105
|
+
/** Delete an edge by id. Mirrors `graph.nodes.delete`. */
|
|
2106
|
+
async delete(id) {
|
|
2107
|
+
await this.synapCores._getHttpClient().delete(`/graph/edges/${id}`);
|
|
2108
|
+
}
|
|
1985
2109
|
};
|
|
1986
2110
|
var GraphIndexesApi = class {
|
|
1987
2111
|
constructor(synapCores) {
|
|
@@ -2835,6 +2959,20 @@ var SynapCores = class {
|
|
|
2835
2959
|
this.collectionsCache = /* @__PURE__ */ new Map();
|
|
2836
2960
|
this.currentTransaction = null;
|
|
2837
2961
|
this.preparedStatements = /* @__PURE__ */ new Map();
|
|
2962
|
+
// =================================================================
|
|
2963
|
+
// VECTOR COLLECTIONS — /v1/vectors/collections/{name}
|
|
2964
|
+
//
|
|
2965
|
+
// The gateway exposes two parallel "collection" worlds:
|
|
2966
|
+
// (a) document-store collections under /v1/collections (above), and
|
|
2967
|
+
// (b) vector collections under /v1/vectors/collections (below).
|
|
2968
|
+
//
|
|
2969
|
+
// v0.3.0 only wrapped (a) so vector-first users had to drop down to
|
|
2970
|
+
// `_getHttpClient()` to call (b) directly. v0.4.0 adds first-class
|
|
2971
|
+
// helpers — `createVectorCollection`, `vectorCollection(name)`,
|
|
2972
|
+
// `listVectorCollections`, `deleteVectorCollection` — that target (b)
|
|
2973
|
+
// and return a typed `VectorCollection` handle.
|
|
2974
|
+
// =================================================================
|
|
2975
|
+
this.vectorCollectionsCache = /* @__PURE__ */ new Map();
|
|
2838
2976
|
this.config = {
|
|
2839
2977
|
host: config.host || "localhost",
|
|
2840
2978
|
port: config.port || 8080,
|
|
@@ -2857,14 +2995,14 @@ var SynapCores = class {
|
|
|
2857
2995
|
if (this.config.jwtToken) {
|
|
2858
2996
|
authHeader["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
2859
2997
|
} else if (this.config.apiKey) {
|
|
2860
|
-
authHeader["
|
|
2998
|
+
authHeader["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2861
2999
|
}
|
|
2862
3000
|
this.httpClient = import_axios.default.create({
|
|
2863
3001
|
baseURL,
|
|
2864
3002
|
timeout: this.config.timeout,
|
|
2865
3003
|
headers: {
|
|
2866
3004
|
"Content-Type": "application/json",
|
|
2867
|
-
"User-Agent": "synapcores-nodejs/0.
|
|
3005
|
+
"User-Agent": "synapcores-nodejs/0.4.0",
|
|
2868
3006
|
...authHeader
|
|
2869
3007
|
},
|
|
2870
3008
|
...httpsAgent && { httpsAgent }
|
|
@@ -3089,6 +3227,67 @@ var SynapCores = class {
|
|
|
3089
3227
|
await this.httpClient.delete(`/collections/${name}`);
|
|
3090
3228
|
this.collectionsCache.delete(name);
|
|
3091
3229
|
}
|
|
3230
|
+
/**
|
|
3231
|
+
* Create a vector collection.
|
|
3232
|
+
*
|
|
3233
|
+
* Wire: `POST /v1/vectors/collections` with
|
|
3234
|
+
* `{ name, dimensions, distance_metric }`. Distinct from
|
|
3235
|
+
* `createCollection`, which targets the document-store subsystem.
|
|
3236
|
+
*
|
|
3237
|
+
* @example
|
|
3238
|
+
* const coll = await client.createVectorCollection({
|
|
3239
|
+
* name: 'memory_v1', dimensions: 1536, distance_metric: 'cosine',
|
|
3240
|
+
* });
|
|
3241
|
+
* await coll.insert({ id: 'v1', values: [...], metadata: { ... } });
|
|
3242
|
+
*/
|
|
3243
|
+
async createVectorCollection(options) {
|
|
3244
|
+
await this.httpClient.post("/vectors/collections", {
|
|
3245
|
+
name: options.name,
|
|
3246
|
+
dimensions: options.dimensions,
|
|
3247
|
+
distance_metric: options.distance_metric ?? "cosine"
|
|
3248
|
+
});
|
|
3249
|
+
const coll = new VectorCollection(this, options.name);
|
|
3250
|
+
this.vectorCollectionsCache.set(options.name, coll);
|
|
3251
|
+
return coll;
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Synchronous accessor for an existing vector collection. Does not
|
|
3255
|
+
* round-trip to the gateway — use `createVectorCollection` if you
|
|
3256
|
+
* need to provision the collection first, or `listVectorCollections`
|
|
3257
|
+
* to confirm existence.
|
|
3258
|
+
*
|
|
3259
|
+
* v0.4.0 split: this targets the **vector subsystem**
|
|
3260
|
+
* (`/v1/vectors/collections/{name}`). `client.collection(name)` still
|
|
3261
|
+
* returns a document-store `Collection` for the legacy subsystem.
|
|
3262
|
+
*/
|
|
3263
|
+
vectorCollection(name) {
|
|
3264
|
+
const cached = this.vectorCollectionsCache.get(name);
|
|
3265
|
+
if (cached) return cached;
|
|
3266
|
+
const coll = new VectorCollection(this, name);
|
|
3267
|
+
this.vectorCollectionsCache.set(name, coll);
|
|
3268
|
+
return coll;
|
|
3269
|
+
}
|
|
3270
|
+
/**
|
|
3271
|
+
* List vector collections.
|
|
3272
|
+
*
|
|
3273
|
+
* Wire: `GET /v1/vectors/collections`. Returns the bare array of
|
|
3274
|
+
* collection-info objects (envelope unwrapped).
|
|
3275
|
+
*/
|
|
3276
|
+
async listVectorCollections() {
|
|
3277
|
+
const { data } = await this.httpClient.get("/vectors/collections");
|
|
3278
|
+
const inner = data?.data ?? data;
|
|
3279
|
+
if (Array.isArray(inner)) return inner;
|
|
3280
|
+
return inner?.items ?? inner?.collections ?? [];
|
|
3281
|
+
}
|
|
3282
|
+
/**
|
|
3283
|
+
* Delete a vector collection.
|
|
3284
|
+
*
|
|
3285
|
+
* Wire: `DELETE /v1/vectors/collections/{name}`.
|
|
3286
|
+
*/
|
|
3287
|
+
async deleteVectorCollection(name) {
|
|
3288
|
+
await this.httpClient.delete(`/vectors/collections/${encodeURIComponent(name)}`);
|
|
3289
|
+
this.vectorCollectionsCache.delete(name);
|
|
3290
|
+
}
|
|
3092
3291
|
/**
|
|
3093
3292
|
* Execute SQL query (legacy method for backward compatibility)
|
|
3094
3293
|
* @deprecated Use executeQuery for new code
|
|
@@ -4003,7 +4202,7 @@ var SynapCores = class {
|
|
|
4003
4202
|
|
|
4004
4203
|
// src/index.ts
|
|
4005
4204
|
var import_zod = require("zod");
|
|
4006
|
-
var VERSION = "0.
|
|
4205
|
+
var VERSION = "0.4.0";
|
|
4007
4206
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4008
4207
|
0 && (module.exports = {
|
|
4009
4208
|
AuthenticationError,
|
|
@@ -4038,6 +4237,7 @@ var VERSION = "0.3.0";
|
|
|
4038
4237
|
Tx,
|
|
4039
4238
|
VERSION,
|
|
4040
4239
|
ValidationError,
|
|
4240
|
+
VectorCollection,
|
|
4041
4241
|
VectorError,
|
|
4042
4242
|
z
|
|
4043
4243
|
});
|