@wiscale/velesdb-sdk 1.5.1 → 1.6.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/dist/index.d.mts CHANGED
@@ -23,6 +23,13 @@ interface VelesDBConfig {
23
23
  }
24
24
  /** Collection type */
25
25
  type CollectionType = 'vector' | 'metadata_only';
26
+ /** HNSW index parameters for collection creation */
27
+ interface HnswParams {
28
+ /** Number of bi-directional links per node (M parameter) */
29
+ m?: number;
30
+ /** Size of dynamic candidate list during construction */
31
+ efConstruction?: number;
32
+ }
26
33
  /** Collection configuration */
27
34
  interface CollectionConfig {
28
35
  /** Vector dimension (e.g., 768 for BERT, 1536 for GPT). Required for vector collections. */
@@ -39,6 +46,8 @@ interface CollectionConfig {
39
46
  collectionType?: CollectionType;
40
47
  /** Optional collection description */
41
48
  description?: string;
49
+ /** Optional HNSW parameters for index tuning */
50
+ hnsw?: HnswParams;
42
51
  }
43
52
  /** Collection metadata */
44
53
  interface Collection {
@@ -208,6 +217,74 @@ interface DegreeResponse {
208
217
  /** Number of outgoing edges */
209
218
  outDegree: number;
210
219
  }
220
+ /** Schema mode for graph collections */
221
+ type GraphSchemaMode = 'schemaless' | 'strict';
222
+ /** Graph collection configuration */
223
+ interface GraphCollectionConfig {
224
+ /** Optional embedding dimension for node vectors */
225
+ dimension?: number;
226
+ /** Distance metric for embeddings (default: 'cosine') */
227
+ metric?: DistanceMetric;
228
+ /** Schema mode (default: 'schemaless') */
229
+ schemaMode?: GraphSchemaMode;
230
+ }
231
+ /** Semantic memory entry */
232
+ interface SemanticEntry {
233
+ /** Unique fact ID */
234
+ id: number;
235
+ /** Fact text content */
236
+ text: string;
237
+ /** Embedding vector */
238
+ embedding: number[];
239
+ /** Optional metadata */
240
+ metadata?: Record<string, unknown>;
241
+ }
242
+ /** Episodic memory event */
243
+ interface EpisodicEvent {
244
+ /** Event type identifier */
245
+ eventType: string;
246
+ /** Event data */
247
+ data: Record<string, unknown>;
248
+ /** Embedding vector */
249
+ embedding: number[];
250
+ /** Optional metadata */
251
+ metadata?: Record<string, unknown>;
252
+ }
253
+ /** Procedural memory pattern */
254
+ interface ProceduralPattern {
255
+ /** Procedure name */
256
+ name: string;
257
+ /** Ordered steps */
258
+ steps: string[];
259
+ /** Optional metadata */
260
+ metadata?: Record<string, unknown>;
261
+ }
262
+ /** Agent memory configuration */
263
+ interface AgentMemoryConfig {
264
+ /** Embedding dimension (default: 384) */
265
+ dimension?: number;
266
+ }
267
+ /** Collection statistics response */
268
+ interface CollectionStatsResponse {
269
+ totalPoints: number;
270
+ totalSizeBytes: number;
271
+ rowCount: number;
272
+ deletedCount: number;
273
+ avgRowSizeBytes: number;
274
+ payloadSizeBytes: number;
275
+ lastAnalyzedEpochMs: number;
276
+ }
277
+ /** Collection configuration response */
278
+ interface CollectionConfigResponse {
279
+ name: string;
280
+ dimension: number;
281
+ metric: string;
282
+ storageMode: string;
283
+ pointCount: number;
284
+ metadataOnly: boolean;
285
+ graphSchema?: Record<string, unknown>;
286
+ embeddingDimension?: number;
287
+ }
211
288
  /** VelesQL query options */
212
289
  interface QueryOptions {
213
290
  /** Timeout in milliseconds (default: 30000) */
@@ -215,21 +292,15 @@ interface QueryOptions {
215
292
  /** Enable streaming response */
216
293
  stream?: boolean;
217
294
  }
218
- /** Query result from multi-model VelesQL query */
219
- interface QueryResult {
220
- /** Node/point ID */
221
- nodeId: bigint | number;
222
- /** Vector similarity score (if applicable) */
223
- vectorScore: number | null;
224
- /** Graph relevance score (if applicable) */
225
- graphScore: number | null;
226
- /** Combined fused score */
227
- fusedScore: number;
228
- /** Variable bindings from MATCH clause */
229
- bindings: Record<string, unknown>;
230
- /** Column data from JOIN (if applicable) */
231
- columnData: Record<string, unknown> | null;
232
- }
295
+ /**
296
+ * Query result row from VelesQL query.
297
+ *
298
+ * Shape depends on the SELECT clause:
299
+ * - `SELECT *` → `{id, field1, field2, ...}` (no vector)
300
+ * - `SELECT col1, col2` → `{col1, col2}`
301
+ * - `SELECT similarity() AS score, title` → `{score, title}`
302
+ */
303
+ type QueryResult = Record<string, unknown>;
233
304
  /** Query execution statistics */
234
305
  interface QueryStats {
235
306
  /** Execution time in milliseconds */
@@ -407,6 +478,31 @@ interface IVelesDBBackend {
407
478
  trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
408
479
  /** Stream-insert documents with backpressure support */
409
480
  streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
481
+ /** Create a graph collection */
482
+ createGraphCollection(name: string, config?: GraphCollectionConfig): Promise<void>;
483
+ /** Get collection statistics */
484
+ getCollectionStats(collection: string): Promise<CollectionStatsResponse | null>;
485
+ /** Analyze a collection */
486
+ analyzeCollection(collection: string): Promise<CollectionStatsResponse>;
487
+ /** Get collection configuration */
488
+ getCollectionConfig(collection: string): Promise<CollectionConfigResponse>;
489
+ /** Search returning only IDs and scores */
490
+ searchIds(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<Array<{
491
+ id: number;
492
+ score: number;
493
+ }>>;
494
+ /** Store a semantic fact */
495
+ storeSemanticFact(collection: string, entry: SemanticEntry): Promise<void>;
496
+ /** Search semantic memory */
497
+ searchSemanticMemory(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
498
+ /** Record an episodic event */
499
+ recordEpisodicEvent(collection: string, event: EpisodicEvent): Promise<void>;
500
+ /** Recall episodic events */
501
+ recallEpisodicEvents(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
502
+ /** Store a procedural pattern */
503
+ storeProceduralPattern(collection: string, pattern: ProceduralPattern): Promise<void>;
504
+ /** Match procedural patterns */
505
+ matchProceduralPatterns(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
410
506
  }
411
507
  /** Error types */
412
508
  declare class VelesDBError extends Error {
@@ -428,6 +524,36 @@ declare class BackpressureError extends VelesDBError {
428
524
  constructor(message?: string);
429
525
  }
430
526
 
527
+ /**
528
+ * Agent Memory facade for VelesDB.
529
+ *
530
+ * Provides semantic, episodic, and procedural memory abstractions
531
+ * on top of the VelesDB backend interface.
532
+ */
533
+
534
+ /**
535
+ * Agent Memory client for semantic, episodic, and procedural memory
536
+ */
537
+ declare class AgentMemoryClient {
538
+ private readonly backend;
539
+ private readonly config?;
540
+ constructor(backend: IVelesDBBackend, config?: AgentMemoryConfig | undefined);
541
+ /** Configured embedding dimension (default: 384) */
542
+ get dimension(): number;
543
+ /** Store a semantic fact */
544
+ storeFact(collection: string, entry: SemanticEntry): Promise<void>;
545
+ /** Search semantic memory */
546
+ searchFacts(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
547
+ /** Record an episodic event */
548
+ recordEvent(collection: string, event: EpisodicEvent): Promise<void>;
549
+ /** Recall episodic events */
550
+ recallEvents(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
551
+ /** Store a procedural pattern */
552
+ learnProcedure(collection: string, pattern: ProceduralPattern): Promise<void>;
553
+ /** Match procedural patterns */
554
+ recallProcedures(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
555
+ }
556
+
431
557
  /**
432
558
  * VelesDB Client - Unified interface for all backends
433
559
  */
@@ -609,7 +735,7 @@ declare class VelesDB {
609
735
  * `, { q: queryVector });
610
736
  *
611
737
  * for (const r of response.results) {
612
- * console.log(`Node ${r.nodeId}: ${r.fusedScore}`);
738
+ * console.log(`ID ${r.id}, title: ${r.title}`);
613
739
  * }
614
740
  * ```
615
741
  */
@@ -794,6 +920,53 @@ declare class VelesDB {
794
920
  * ```
795
921
  */
796
922
  getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
923
+ /**
924
+ * Create a graph collection
925
+ *
926
+ * @param name - Collection name
927
+ * @param config - Optional graph collection configuration
928
+ */
929
+ createGraphCollection(name: string, config?: GraphCollectionConfig): Promise<void>;
930
+ /**
931
+ * Get collection statistics (requires prior analyze)
932
+ *
933
+ * @param collection - Collection name
934
+ * @returns Statistics or null if not yet analyzed
935
+ */
936
+ getCollectionStats(collection: string): Promise<CollectionStatsResponse | null>;
937
+ /**
938
+ * Analyze a collection to compute statistics
939
+ *
940
+ * @param collection - Collection name
941
+ * @returns Computed statistics
942
+ */
943
+ analyzeCollection(collection: string): Promise<CollectionStatsResponse>;
944
+ /**
945
+ * Get collection configuration
946
+ *
947
+ * @param collection - Collection name
948
+ * @returns Collection configuration details
949
+ */
950
+ getCollectionConfig(collection: string): Promise<CollectionConfigResponse>;
951
+ /**
952
+ * Search returning only IDs and scores (lightweight)
953
+ *
954
+ * @param collection - Collection name
955
+ * @param query - Query vector
956
+ * @param options - Search options
957
+ * @returns Array of id/score pairs
958
+ */
959
+ searchIds(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<Array<{
960
+ id: number;
961
+ score: number;
962
+ }>>;
963
+ /**
964
+ * Create an agent memory interface
965
+ *
966
+ * @param config - Optional agent memory configuration
967
+ * @returns AgentMemoryClient instance
968
+ */
969
+ agentMemory(config?: AgentMemoryConfig): AgentMemoryClient;
797
970
  }
798
971
 
799
972
  /**
@@ -860,12 +1033,27 @@ declare class WasmBackend implements IVelesDBBackend {
860
1033
  getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
861
1034
  trainPq(_collection: string, _options?: PqTrainOptions): Promise<string>;
862
1035
  streamInsert(_collection: string, _docs: VectorDocument[]): Promise<void>;
1036
+ createGraphCollection(_name: string, _config?: GraphCollectionConfig): Promise<void>;
1037
+ getCollectionStats(_collection: string): Promise<CollectionStatsResponse | null>;
1038
+ analyzeCollection(_collection: string): Promise<CollectionStatsResponse>;
1039
+ getCollectionConfig(_collection: string): Promise<CollectionConfigResponse>;
1040
+ searchIds(_collection: string, _query: number[] | Float32Array, _options?: SearchOptions): Promise<Array<{
1041
+ id: number;
1042
+ score: number;
1043
+ }>>;
1044
+ storeSemanticFact(_collection: string, _entry: SemanticEntry): Promise<void>;
1045
+ searchSemanticMemory(_collection: string, _embedding: number[], _k?: number): Promise<SearchResult[]>;
1046
+ recordEpisodicEvent(_collection: string, _event: EpisodicEvent): Promise<void>;
1047
+ recallEpisodicEvents(_collection: string, _embedding: number[], _k?: number): Promise<SearchResult[]>;
1048
+ storeProceduralPattern(_collection: string, _pattern: ProceduralPattern): Promise<void>;
1049
+ matchProceduralPatterns(_collection: string, _embedding: number[], _k?: number): Promise<SearchResult[]>;
863
1050
  }
864
1051
 
865
1052
  /**
866
1053
  * REST Backend for VelesDB
867
1054
  *
868
- * Connects to VelesDB server via REST API
1055
+ * Connects to VelesDB server via REST API.
1056
+ * This is the composition root that delegates to focused backend modules.
869
1057
  */
870
1058
 
871
1059
  /**
@@ -884,55 +1072,67 @@ declare class RestBackend implements IVelesDBBackend {
884
1072
  private ensureInitialized;
885
1073
  private mapStatusToErrorCode;
886
1074
  private extractErrorPayload;
887
- /**
888
- * Parse node ID safely to handle u64 values above Number.MAX_SAFE_INTEGER.
889
- * Returns bigint for large values, number for safe values.
890
- */
891
1075
  private parseNodeId;
892
- private parseRestPointId;
893
- private isLikelyAggregationQuery;
894
1076
  private request;
1077
+ private asCrudTransport;
1078
+ private asSearchTransport;
1079
+ private asAgentMemoryTransport;
1080
+ private asQueryTransport;
1081
+ private asStreamingTransport;
895
1082
  createCollection(name: string, config: CollectionConfig): Promise<void>;
896
1083
  deleteCollection(name: string): Promise<void>;
897
1084
  getCollection(name: string): Promise<Collection | null>;
898
1085
  listCollections(): Promise<Collection[]>;
899
1086
  insert(collection: string, doc: VectorDocument): Promise<void>;
900
1087
  insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
901
- private sparseVectorToRestFormat;
902
- search(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
1088
+ delete(collection: string, id: string | number): Promise<boolean>;
1089
+ get(collection: string, id: string | number): Promise<VectorDocument | null>;
1090
+ isEmpty(collection: string): Promise<boolean>;
1091
+ flush(collection: string): Promise<void>;
1092
+ close(): Promise<void>;
1093
+ search(c: string, q: number[] | Float32Array, o?: SearchOptions): Promise<SearchResult[]>;
903
1094
  searchBatch(collection: string, searches: Array<{
904
1095
  vector: number[] | Float32Array;
905
1096
  k?: number;
906
1097
  filter?: Record<string, unknown>;
907
1098
  }>): Promise<SearchResult[][]>;
908
- delete(collection: string, id: string | number): Promise<boolean>;
909
- get(collection: string, id: string | number): Promise<VectorDocument | null>;
910
- textSearch(collection: string, query: string, options?: {
1099
+ textSearch(c: string, q: string, o?: {
911
1100
  k?: number;
912
1101
  filter?: Record<string, unknown>;
913
1102
  }): Promise<SearchResult[]>;
914
- hybridSearch(collection: string, vector: number[] | Float32Array, textQuery: string, options?: {
1103
+ hybridSearch(c: string, v: number[] | Float32Array, t: string, o?: {
915
1104
  k?: number;
916
1105
  vectorWeight?: number;
917
1106
  filter?: Record<string, unknown>;
918
1107
  }): Promise<SearchResult[]>;
919
- query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
920
- queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
1108
+ multiQuerySearch(c: string, v: Array<number[] | Float32Array>, o?: MultiQuerySearchOptions): Promise<SearchResult[]>;
1109
+ searchIds(c: string, q: number[] | Float32Array, o?: SearchOptions): Promise<Array<{
1110
+ id: number;
1111
+ score: number;
1112
+ }>>;
1113
+ query(c: string, q: string, p?: Record<string, unknown>, o?: QueryOptions): Promise<QueryApiResponse>;
1114
+ queryExplain(q: string, p?: Record<string, unknown>): Promise<ExplainResponse>;
921
1115
  collectionSanity(collection: string): Promise<CollectionSanityResponse>;
922
- multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
923
- isEmpty(collection: string): Promise<boolean>;
924
- flush(collection: string): Promise<void>;
925
- trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
926
- streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
927
- close(): Promise<void>;
1116
+ addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
1117
+ getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
1118
+ traverseGraph(collection: string, req: TraverseRequest): Promise<TraverseResponse>;
1119
+ getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
1120
+ createGraphCollection(name: string, config?: GraphCollectionConfig): Promise<void>;
928
1121
  createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
929
1122
  listIndexes(collection: string): Promise<IndexInfo[]>;
930
1123
  hasIndex(collection: string, label: string, property: string): Promise<boolean>;
931
1124
  dropIndex(collection: string, label: string, property: string): Promise<boolean>;
932
- addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
933
- getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
934
- traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
935
- getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
1125
+ getCollectionStats(collection: string): Promise<CollectionStatsResponse | null>;
1126
+ analyzeCollection(collection: string): Promise<CollectionStatsResponse>;
1127
+ getCollectionConfig(collection: string): Promise<CollectionConfigResponse>;
1128
+ trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
1129
+ streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
1130
+ storeSemanticFact(collection: string, entry: SemanticEntry): Promise<void>;
1131
+ searchSemanticMemory(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
1132
+ recordEpisodicEvent(collection: string, event: EpisodicEvent): Promise<void>;
1133
+ recallEpisodicEvents(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
1134
+ storeProceduralPattern(collection: string, pattern: ProceduralPattern): Promise<void>;
1135
+ matchProceduralPatterns(collection: string, embedding: number[], k?: number): Promise<SearchResult[]>;
936
1136
  }
937
1137
 
938
1138
  /**
@@ -942,7 +1142,7 @@ declare class RestBackend implements IVelesDBBackend {
942
1142
  *
943
1143
  * @example
944
1144
  * ```typescript
945
- * import { velesql } from '@velesdb/sdk';
1145
+ * import { velesql } from '@wiscale/velesdb-sdk';
946
1146
  *
947
1147
  * const query = velesql()
948
1148
  * .match('d', 'Document')
@@ -1125,4 +1325,4 @@ declare class VelesQLBuilder {
1125
1325
  */
1126
1326
  declare function velesql(): VelesQLBuilder;
1127
1327
 
1128
- export { type AddEdgeRequest, type AggregationQueryResponse, type BackendType, BackpressureError, type Collection, type CollectionConfig, type CollectionSanityChecks, type CollectionSanityDiagnostics, type CollectionSanityResponse, type CollectionType, ConnectionError, type CreateIndexOptions, type DegreeResponse, type DistanceMetric, type EdgesResponse, type ExplainCost, type ExplainFeatures, type ExplainPlanStep, type ExplainResponse, type FusionOptions, type FusionStrategy$1 as FusionStrategy, type GetEdgesOptions, type GraphEdge, type IVelesDBBackend, type IndexInfo, type IndexType, type MultiQuerySearchOptions, type NearVectorOptions, NotFoundError, type PqTrainOptions, type QueryApiResponse, type QueryOptions, type QueryResponse, type QueryResult, type QueryStats, type RelDirection, type RelOptions, RestBackend, type RestPointId, type SearchOptions, type SearchResult, type SparseVector, type StorageMode, type TraversalResultItem, type TraversalStats, type TraverseRequest, type TraverseResponse, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, VelesQLBuilder, WasmBackend, velesql };
1328
+ export { type AddEdgeRequest, AgentMemoryClient, type AgentMemoryConfig, type AggregationQueryResponse, type BackendType, BackpressureError, type Collection, type CollectionConfig, type CollectionConfigResponse, type CollectionSanityChecks, type CollectionSanityDiagnostics, type CollectionSanityResponse, type CollectionStatsResponse, type CollectionType, ConnectionError, type CreateIndexOptions, type DegreeResponse, type DistanceMetric, type EdgesResponse, type EpisodicEvent, type ExplainCost, type ExplainFeatures, type ExplainPlanStep, type ExplainResponse, type FusionOptions, type FusionStrategy$1 as FusionStrategy, type GetEdgesOptions, type GraphCollectionConfig, type GraphEdge, type GraphSchemaMode, type HnswParams, type IVelesDBBackend, type IndexInfo, type IndexType, type MultiQuerySearchOptions, type NearVectorOptions, NotFoundError, type PqTrainOptions, type ProceduralPattern, type QueryApiResponse, type QueryOptions, type QueryResponse, type QueryResult, type QueryStats, type RelDirection, type RelOptions, RestBackend, type RestPointId, type SearchOptions, type SearchResult, type SemanticEntry, type SparseVector, type StorageMode, type TraversalResultItem, type TraversalStats, type TraverseRequest, type TraverseResponse, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, VelesQLBuilder, WasmBackend, velesql };