@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.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) {
|
|
@@ -1920,6 +2039,10 @@ var GraphEdgeApi = class {
|
|
|
1920
2039
|
properties: data.properties ?? props
|
|
1921
2040
|
};
|
|
1922
2041
|
}
|
|
2042
|
+
/** Delete an edge by id. Mirrors `graph.nodes.delete`. */
|
|
2043
|
+
async delete(id) {
|
|
2044
|
+
await this.synapCores._getHttpClient().delete(`/graph/edges/${id}`);
|
|
2045
|
+
}
|
|
1923
2046
|
};
|
|
1924
2047
|
var GraphIndexesApi = class {
|
|
1925
2048
|
constructor(synapCores) {
|
|
@@ -2773,6 +2896,20 @@ var SynapCores = class {
|
|
|
2773
2896
|
this.collectionsCache = /* @__PURE__ */ new Map();
|
|
2774
2897
|
this.currentTransaction = null;
|
|
2775
2898
|
this.preparedStatements = /* @__PURE__ */ new Map();
|
|
2899
|
+
// =================================================================
|
|
2900
|
+
// VECTOR COLLECTIONS — /v1/vectors/collections/{name}
|
|
2901
|
+
//
|
|
2902
|
+
// The gateway exposes two parallel "collection" worlds:
|
|
2903
|
+
// (a) document-store collections under /v1/collections (above), and
|
|
2904
|
+
// (b) vector collections under /v1/vectors/collections (below).
|
|
2905
|
+
//
|
|
2906
|
+
// v0.3.0 only wrapped (a) so vector-first users had to drop down to
|
|
2907
|
+
// `_getHttpClient()` to call (b) directly. v0.4.0 adds first-class
|
|
2908
|
+
// helpers — `createVectorCollection`, `vectorCollection(name)`,
|
|
2909
|
+
// `listVectorCollections`, `deleteVectorCollection` — that target (b)
|
|
2910
|
+
// and return a typed `VectorCollection` handle.
|
|
2911
|
+
// =================================================================
|
|
2912
|
+
this.vectorCollectionsCache = /* @__PURE__ */ new Map();
|
|
2776
2913
|
this.config = {
|
|
2777
2914
|
host: config.host || "localhost",
|
|
2778
2915
|
port: config.port || 8080,
|
|
@@ -2795,14 +2932,14 @@ var SynapCores = class {
|
|
|
2795
2932
|
if (this.config.jwtToken) {
|
|
2796
2933
|
authHeader["Authorization"] = `Bearer ${this.config.jwtToken}`;
|
|
2797
2934
|
} else if (this.config.apiKey) {
|
|
2798
|
-
authHeader["
|
|
2935
|
+
authHeader["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2799
2936
|
}
|
|
2800
2937
|
this.httpClient = axios.create({
|
|
2801
2938
|
baseURL,
|
|
2802
2939
|
timeout: this.config.timeout,
|
|
2803
2940
|
headers: {
|
|
2804
2941
|
"Content-Type": "application/json",
|
|
2805
|
-
"User-Agent": "synapcores-nodejs/0.
|
|
2942
|
+
"User-Agent": "synapcores-nodejs/0.4.0",
|
|
2806
2943
|
...authHeader
|
|
2807
2944
|
},
|
|
2808
2945
|
...httpsAgent && { httpsAgent }
|
|
@@ -3027,6 +3164,67 @@ var SynapCores = class {
|
|
|
3027
3164
|
await this.httpClient.delete(`/collections/${name}`);
|
|
3028
3165
|
this.collectionsCache.delete(name);
|
|
3029
3166
|
}
|
|
3167
|
+
/**
|
|
3168
|
+
* Create a vector collection.
|
|
3169
|
+
*
|
|
3170
|
+
* Wire: `POST /v1/vectors/collections` with
|
|
3171
|
+
* `{ name, dimensions, distance_metric }`. Distinct from
|
|
3172
|
+
* `createCollection`, which targets the document-store subsystem.
|
|
3173
|
+
*
|
|
3174
|
+
* @example
|
|
3175
|
+
* const coll = await client.createVectorCollection({
|
|
3176
|
+
* name: 'memory_v1', dimensions: 1536, distance_metric: 'cosine',
|
|
3177
|
+
* });
|
|
3178
|
+
* await coll.insert({ id: 'v1', values: [...], metadata: { ... } });
|
|
3179
|
+
*/
|
|
3180
|
+
async createVectorCollection(options) {
|
|
3181
|
+
await this.httpClient.post("/vectors/collections", {
|
|
3182
|
+
name: options.name,
|
|
3183
|
+
dimensions: options.dimensions,
|
|
3184
|
+
distance_metric: options.distance_metric ?? "cosine"
|
|
3185
|
+
});
|
|
3186
|
+
const coll = new VectorCollection(this, options.name);
|
|
3187
|
+
this.vectorCollectionsCache.set(options.name, coll);
|
|
3188
|
+
return coll;
|
|
3189
|
+
}
|
|
3190
|
+
/**
|
|
3191
|
+
* Synchronous accessor for an existing vector collection. Does not
|
|
3192
|
+
* round-trip to the gateway — use `createVectorCollection` if you
|
|
3193
|
+
* need to provision the collection first, or `listVectorCollections`
|
|
3194
|
+
* to confirm existence.
|
|
3195
|
+
*
|
|
3196
|
+
* v0.4.0 split: this targets the **vector subsystem**
|
|
3197
|
+
* (`/v1/vectors/collections/{name}`). `client.collection(name)` still
|
|
3198
|
+
* returns a document-store `Collection` for the legacy subsystem.
|
|
3199
|
+
*/
|
|
3200
|
+
vectorCollection(name) {
|
|
3201
|
+
const cached = this.vectorCollectionsCache.get(name);
|
|
3202
|
+
if (cached) return cached;
|
|
3203
|
+
const coll = new VectorCollection(this, name);
|
|
3204
|
+
this.vectorCollectionsCache.set(name, coll);
|
|
3205
|
+
return coll;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* List vector collections.
|
|
3209
|
+
*
|
|
3210
|
+
* Wire: `GET /v1/vectors/collections`. Returns the bare array of
|
|
3211
|
+
* collection-info objects (envelope unwrapped).
|
|
3212
|
+
*/
|
|
3213
|
+
async listVectorCollections() {
|
|
3214
|
+
const { data } = await this.httpClient.get("/vectors/collections");
|
|
3215
|
+
const inner = data?.data ?? data;
|
|
3216
|
+
if (Array.isArray(inner)) return inner;
|
|
3217
|
+
return inner?.items ?? inner?.collections ?? [];
|
|
3218
|
+
}
|
|
3219
|
+
/**
|
|
3220
|
+
* Delete a vector collection.
|
|
3221
|
+
*
|
|
3222
|
+
* Wire: `DELETE /v1/vectors/collections/{name}`.
|
|
3223
|
+
*/
|
|
3224
|
+
async deleteVectorCollection(name) {
|
|
3225
|
+
await this.httpClient.delete(`/vectors/collections/${encodeURIComponent(name)}`);
|
|
3226
|
+
this.vectorCollectionsCache.delete(name);
|
|
3227
|
+
}
|
|
3030
3228
|
/**
|
|
3031
3229
|
* Execute SQL query (legacy method for backward compatibility)
|
|
3032
3230
|
* @deprecated Use executeQuery for new code
|
|
@@ -3941,7 +4139,7 @@ var SynapCores = class {
|
|
|
3941
4139
|
|
|
3942
4140
|
// src/index.ts
|
|
3943
4141
|
import { z } from "zod";
|
|
3944
|
-
var VERSION = "0.
|
|
4142
|
+
var VERSION = "0.4.0";
|
|
3945
4143
|
export {
|
|
3946
4144
|
AuthenticationError,
|
|
3947
4145
|
AutoMLClient,
|
|
@@ -3975,6 +4173,7 @@ export {
|
|
|
3975
4173
|
Tx,
|
|
3976
4174
|
VERSION,
|
|
3977
4175
|
ValidationError,
|
|
4176
|
+
VectorCollection,
|
|
3978
4177
|
VectorError,
|
|
3979
4178
|
z
|
|
3980
4179
|
};
|