@hakodb/client 0.6.3 → 0.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "repository": {
6
6
  "type": "git",
package/src/client.ts CHANGED
@@ -1112,9 +1112,9 @@ export class CollectionReference {
1112
1112
  ensureOk(this.client.nativeBindings().dropTraverseIndex(this.client.engineHandle(), this.name), this.client.nativeBindings(), 'dropTraverseIndex');
1113
1113
  }
1114
1114
 
1115
- /** HNSW-tuned vector index (m = edges per node, efConstruction = build beam, efSearch = query beam; 0 = engine default). */
1116
- async createVectorIndexV2(field: string, dim: number, metric: VectorMetric = 'cosine', m = 0, efConstruction = 0, efSearch = 0): Promise<void> {
1117
- ensureOk(this.client.nativeBindings().createVectorIndexV2(this.client.engineHandle(), this.name, field, dim, metric === 'l2' ? 1 : 0, m, efConstruction, efSearch), this.client.nativeBindings(), 'createVectorIndexV2');
1115
+ /** HNSW-tuned vector index (m = edges per node, efConstruction = build beam, efSearch = query beam; 0 = engine default). binaryStage1 enables the popcount stage-1 filter (0 = int8 default). */
1116
+ async createVectorIndexV2(field: string, dim: number, metric: VectorMetric = 'cosine', m = 0, efConstruction = 0, efSearch = 0, binaryStage1 = 0): Promise<void> {
1117
+ ensureOk(this.client.nativeBindings().createVectorIndexV2(this.client.engineHandle(), this.name, field, dim, metric === 'l2' ? 1 : 0, m, efConstruction, efSearch, binaryStage1), this.client.nativeBindings(), 'createVectorIndexV2');
1118
1118
  }
1119
1119
 
1120
1120
  /** Graph BFS with the v0.19 extensions: via-edge hops, node/edge predicates, opt-in path/via projections. */
@@ -1144,14 +1144,40 @@ export class CollectionReference {
1144
1144
  return JSON.parse(json);
1145
1145
  }
1146
1146
 
1147
- /** Whole-graph analysis: "components" | "cycle" | "topo". */
1148
- async graphAnalysis(op: 'components' | 'cycle' | 'topo', opts: PathOptions = {}): Promise<unknown> {
1147
+ /** Whole-graph analysis: "components" | "cycle" | "topo" | "degrees". */
1148
+ async graphAnalysis(op: 'components' | 'cycle' | 'topo' | 'degrees', opts: PathOptions = {}): Promise<unknown> {
1149
1149
  const native = this.client.nativeBindings();
1150
1150
  const o = resolvePathOptions(opts);
1151
1151
  const json = native.graphAnalysis(this.client.engineHandle(), this.name, op, o.direction, o.edge, o.via, o.nodeField, o.nodeJSON);
1152
1152
  if (json === null) throw new Error(`graphAnalysis failed: ${native.lastError()}`);
1153
1153
  return JSON.parse(json);
1154
1154
  }
1155
+
1156
+ /** Personalized PageRank: seeds = ["col/id"] or null for classic; damping 0 = 0.85; top 0 = all nodes. */
1157
+ async graphPagerank(seeds: string[] | null, opts: PathOptions & { damping?: number; top?: number } = {}): Promise<unknown> {
1158
+ const native = this.client.nativeBindings();
1159
+ const o = resolvePathOptions(opts);
1160
+ const json = native.graphPagerank(this.client.engineHandle(), this.name, seeds === null ? null : JSON.stringify(seeds), o.direction, o.edge, o.via, o.nodeField, o.nodeJSON, opts.damping ?? 0, opts.top ?? 0);
1161
+ if (json === null) throw new Error(`graphPagerank failed: ${native.lastError()}`);
1162
+ return JSON.parse(json);
1163
+ }
1164
+
1165
+ /** Seed-scoped N-hop subgraph: same node/edge shape as exportGraph, scoped to one seed. nodeCap 0 = unlimited. */
1166
+ async subgraph(seedId: string, opts: PathOptions & { nodeCap?: number } = {}): Promise<unknown> {
1167
+ const native = this.client.nativeBindings();
1168
+ const o = resolvePathOptions(opts);
1169
+ const json = native.subgraph(this.client.engineHandle(), this.name, seedId, o.maxDepth, o.direction, o.edge, o.via, o.nodeField, o.nodeJSON, opts.nodeCap ?? 0);
1170
+ if (json === null) throw new Error(`subgraph failed: ${native.lastError()}`);
1171
+ return JSON.parse(json);
1172
+ }
1173
+
1174
+ /** Hybrid retrieval: FTS (sparse) + KNN (dense) fused with RRF. rrfK 0 = default 60. */
1175
+ async hybridSearch(textField: string, textQuery: string, vecField: string, vec: Float32Array, k = 10, rrfK = 0): Promise<unknown> {
1176
+ const native = this.client.nativeBindings();
1177
+ const json = native.hybridSearch(this.client.engineHandle(), this.name, textField, textQuery, vecField, vec, k, rrfK);
1178
+ if (json === null) throw new Error(`hybridSearch failed: ${native.lastError()}`);
1179
+ return JSON.parse(json);
1180
+ }
1155
1181
  }
1156
1182
 
1157
1183
  export class DocumentReference {
package/src/native.ts CHANGED
@@ -211,11 +211,14 @@ export interface NativeBindings {
211
211
  dropEdgeIndex(engine: Handle, collection: string): number;
212
212
  dropFtsIndex(engine: Handle, collection: string, field: string): number;
213
213
  dropTraverseIndex(engine: Handle, collection: string): number;
214
- createVectorIndexV2(engine: Handle, collection: string, field: string, dim: number, metric: number, m: number, efConstruction: number, efSearch: number): number;
214
+ createVectorIndexV2(engine: Handle, collection: string, field: string, dim: number, metric: number, m: number, efConstruction: number, efSearch: number, binaryStage1: number): number;
215
215
  findPathsFull(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, maxDepth: number, k: number, includePath: boolean, includeVia: boolean, nodeField: string | null, nodeJSON: string | null, typeField: string | null, typeJSON: string | null, matchField: string | null, matchJSON: string | null): string | null;
216
216
  simplePathsFull(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, weight: string | null, maxDepth: number, k: number, includePath: boolean, includeVia: boolean, nodeField: string | null, nodeJSON: string | null, typeField: string | null, typeJSON: string | null, matchField: string | null, matchJSON: string | null): string | null;
217
217
  exportGraph(engine: Handle, collection: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
218
218
  graphAnalysis(engine: Handle, collection: string, op: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
219
+ graphPagerank(engine: Handle, collection: string, seeds: string | null, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, damping: number, top: number): string | null;
220
+ subgraph(engine: Handle, collection: string, seedId: string, maxDepth: number, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, nodeCap: number): string | null;
221
+ hybridSearch(engine: Handle, collection: string, textField: string, textQuery: string, vecField: string, vec: Float32Array, k: number, rrfK: number): string | null;
219
222
  insertJSON(engine: Handle, collection: string, id: string, json: string): number;
220
223
  batchSetJSON(batch: Handle, collection: string, id: string, json: string): number;
221
224
 
@@ -427,7 +430,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
427
430
  hk_engine_drop_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
428
431
  hk_engine_drop_fts_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
429
432
  hk_engine_drop_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
430
- hk_engine_create_vector_index_v2: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.i32 },
433
+ hk_engine_create_vector_index_v2: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.usize, FFIType.usize, FFIType.usize, FFIType.u32], returns: FFIType.i32 },
434
+ hk_engine_graph_pagerank: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.f64, FFIType.usize], returns: FFIType.ptr },
435
+ hk_engine_subgraph: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize], returns: FFIType.ptr },
436
+ hk_engine_hybrid_search: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
431
437
  hk_engine_find_paths_v4: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
432
438
  hk_engine_find_simple_paths_v3: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
433
439
  hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
@@ -811,11 +817,14 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
811
817
  dropEdgeIndex: (engine, collection) => symbols.hk_engine_drop_edge_index(engine, toC(collection)),
812
818
  dropFtsIndex: (engine, collection, field) => symbols.hk_engine_drop_fts_index(engine, toC(collection), toC(field)),
813
819
  dropTraverseIndex: (engine, collection) => symbols.hk_engine_drop_traverse_index(engine, toC(collection)),
814
- createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch) => symbols.hk_engine_create_vector_index_v2(engine, toC(collection), toC(field), dim, metric, m, efConstruction, efSearch),
820
+ createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => symbols.hk_engine_create_vector_index_v2(engine, toC(collection), toC(field), dim, metric, m, efConstruction, efSearch, binaryStage1),
815
821
  findPathsFull: (engine, collection, id, direction, edge, via, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => ptrToStringAndFree(symbols.hk_engine_find_paths_v4(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), typeField === null ? null : toC(typeField), typeJSON === null ? null : toC(typeJSON), matchField === null ? null : toC(matchField), matchJSON === null ? null : toC(matchJSON))),
816
822
  simplePathsFull: (engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => ptrToStringAndFree(symbols.hk_engine_find_simple_paths_v3(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), weight === null ? null : toC(weight), maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), typeField === null ? null : toC(typeField), typeJSON === null ? null : toC(typeJSON), matchField === null ? null : toC(matchField), matchJSON === null ? null : toC(matchJSON))),
817
823
  exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => ptrToStringAndFree(symbols.hk_engine_export_graph(engine, toC(collection), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON))),
818
824
  graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => ptrToStringAndFree(symbols.hk_engine_graph_analysis(engine, toC(collection), toC(op), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON))),
825
+ graphPagerank: (engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top) => ptrToStringAndFree(symbols.hk_engine_graph_pagerank(engine, toC(collection), seeds === null ? null : toC(seeds), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), damping, top)),
826
+ subgraph: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap) => ptrToStringAndFree(symbols.hk_engine_subgraph(engine, toC(collection), toC(seedId), maxDepth, direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), nodeCap)),
827
+ hybridSearch: (engine, collection, textField, textQuery, vecField, vec, k, rrfK) => ptrToStringAndFree(symbols.hk_engine_hybrid_search(engine, toC(collection), toC(textField), toC(textQuery), toC(vecField), vec, vec.length, k, rrfK)),
819
828
  insertJSON: (engine, collection, id, json) => symbols.hk_engine_insert_json(engine, toC(collection), toC(id), toC(json)),
820
829
  batchSetJSON: (batch, collection, id, json) => symbols.hk_batch_set_json(batch, toC(collection), toC(id), toC(json)),
821
830
 
@@ -1065,7 +1074,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1065
1074
  hk_engine_drop_edge_index: lib.func('int hk_engine_drop_edge_index(HK_Engine* engine, const char* collection)'),
1066
1075
  hk_engine_drop_fts_index: lib.func('int hk_engine_drop_fts_index(HK_Engine* engine, const char* collection, const char* field)'),
1067
1076
  hk_engine_drop_traverse_index: lib.func('int hk_engine_drop_traverse_index(HK_Engine* engine, const char* collection)'),
1068
- hk_engine_create_vector_index_v2: lib.func('int hk_engine_create_vector_index_v2(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric, size_t m, size_t ef_construction, size_t ef_search)'),
1077
+ hk_engine_create_vector_index_v2: lib.func('int hk_engine_create_vector_index_v2(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric, size_t m, size_t ef_construction, size_t ef_search, uint32_t binary_stage1)'),
1078
+ hk_engine_graph_pagerank: lib.func('HeapStr hk_engine_graph_pagerank(HK_Engine* engine, const char* collection, const char* seeds_json, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, double damping, size_t top)'),
1079
+ hk_engine_subgraph: lib.func('HeapStr hk_engine_subgraph(HK_Engine* engine, const char* collection, const char* seed_id, uint32_t max_depth, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, size_t node_cap)'),
1080
+ hk_engine_hybrid_search: lib.func('HeapStr hk_engine_hybrid_search(HK_Engine* engine, const char* collection, const char* text_field, const char* text_query, const char* vec_field, const float* vec, size_t vec_len, size_t k, size_t rrf_k)'),
1069
1081
  hk_engine_find_paths_v4: lib.func('HeapStr hk_engine_find_paths_v4(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, const char* via, size_t max_depth, size_t k, uint32_t include_path, uint32_t include_via, const char* filter_field, const char* filter_json, const char* type_field, const char* type_json, const char* match_field, const char* match_json)'),
1070
1082
  hk_engine_find_simple_paths_v3: lib.func('HeapStr hk_engine_find_simple_paths_v3(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, const char* via, const char* weight, size_t max_depth, size_t k, uint32_t include_path, uint32_t include_via, const char* filter_field, const char* filter_json, const char* type_field, const char* type_json, const char* match_field, const char* match_json)'),
1071
1083
  hk_engine_export_graph: lib.func('HeapStr hk_engine_export_graph(HK_Engine* engine, const char* collection, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json)'),
@@ -1442,11 +1454,14 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1442
1454
  dropEdgeIndex: (engine, collection) => fn.hk_engine_drop_edge_index(engine, collection),
1443
1455
  dropFtsIndex: (engine, collection, field) => fn.hk_engine_drop_fts_index(engine, collection, field),
1444
1456
  dropTraverseIndex: (engine, collection) => fn.hk_engine_drop_traverse_index(engine, collection),
1445
- createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch),
1457
+ createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1),
1446
1458
  findPathsFull: (engine, collection, id, direction, edge, via, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => fn.hk_engine_find_paths_v4(engine, collection, id, direction, edge, via, maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON),
1447
1459
  simplePathsFull: (engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => fn.hk_engine_find_simple_paths_v3(engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON),
1448
1460
  exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_export_graph(engine, collection, direction, edge, via, nodeField, nodeJSON),
1449
1461
  graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_graph_analysis(engine, collection, op, direction, edge, via, nodeField, nodeJSON),
1462
+ graphPagerank: (engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top) => fn.hk_engine_graph_pagerank(engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top),
1463
+ subgraph: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap) => fn.hk_engine_subgraph(engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap),
1464
+ hybridSearch: (engine, collection, textField, textQuery, vecField, vec, k, rrfK) => fn.hk_engine_hybrid_search(engine, collection, textField, textQuery, vecField, vec, k, rrfK),
1450
1465
  insertJSON: (engine, collection, id, json) => fn.hk_engine_insert_json(engine, collection, id, json),
1451
1466
  batchSetJSON: (batch, collection, id, json) => fn.hk_batch_set_json(batch, collection, id, json),
1452
1467