@wiscale/velesdb-sdk 1.2.0 → 1.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/README.md +145 -1
- package/dist/index.d.mts +515 -11
- package/dist/index.d.ts +515 -11
- package/dist/index.js +800 -24
- package/dist/index.mjs +797 -23
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -72,13 +72,13 @@ interface SearchOptions {
|
|
|
72
72
|
includeVectors?: boolean;
|
|
73
73
|
}
|
|
74
74
|
/** Fusion strategy for multi-query search */
|
|
75
|
-
type FusionStrategy = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
75
|
+
type FusionStrategy$1 = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
76
76
|
/** Multi-query search options */
|
|
77
77
|
interface MultiQuerySearchOptions {
|
|
78
78
|
/** Number of results to return (default: 10) */
|
|
79
79
|
k?: number;
|
|
80
80
|
/** Fusion strategy (default: 'rrf') */
|
|
81
|
-
fusion?: FusionStrategy;
|
|
81
|
+
fusion?: FusionStrategy$1;
|
|
82
82
|
/** Fusion parameters */
|
|
83
83
|
fusionParams?: {
|
|
84
84
|
/** RRF k parameter (default: 60) */
|
|
@@ -104,6 +104,155 @@ interface SearchResult {
|
|
|
104
104
|
/** Vector data (if includeVectors is true) */
|
|
105
105
|
vector?: number[];
|
|
106
106
|
}
|
|
107
|
+
/** Graph edge representing a relationship between nodes */
|
|
108
|
+
interface GraphEdge {
|
|
109
|
+
/** Unique edge ID */
|
|
110
|
+
id: number;
|
|
111
|
+
/** Source node ID */
|
|
112
|
+
source: number;
|
|
113
|
+
/** Target node ID */
|
|
114
|
+
target: number;
|
|
115
|
+
/** Edge label (relationship type, e.g., "KNOWS", "FOLLOWS") */
|
|
116
|
+
label: string;
|
|
117
|
+
/** Edge properties */
|
|
118
|
+
properties?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
/** Request to add an edge to the graph */
|
|
121
|
+
interface AddEdgeRequest {
|
|
122
|
+
/** Unique edge ID */
|
|
123
|
+
id: number;
|
|
124
|
+
/** Source node ID */
|
|
125
|
+
source: number;
|
|
126
|
+
/** Target node ID */
|
|
127
|
+
target: number;
|
|
128
|
+
/** Edge label (relationship type) */
|
|
129
|
+
label: string;
|
|
130
|
+
/** Edge properties (optional) */
|
|
131
|
+
properties?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** Response containing edges */
|
|
134
|
+
interface EdgesResponse {
|
|
135
|
+
/** List of edges */
|
|
136
|
+
edges: GraphEdge[];
|
|
137
|
+
/** Total count of edges returned */
|
|
138
|
+
count: number;
|
|
139
|
+
}
|
|
140
|
+
/** Options for querying edges */
|
|
141
|
+
interface GetEdgesOptions {
|
|
142
|
+
/** Filter by edge label */
|
|
143
|
+
label?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Request for graph traversal (EPIC-016 US-050) */
|
|
146
|
+
interface TraverseRequest {
|
|
147
|
+
/** Source node ID to start traversal from */
|
|
148
|
+
source: number;
|
|
149
|
+
/** Traversal strategy: 'bfs' or 'dfs' */
|
|
150
|
+
strategy?: 'bfs' | 'dfs';
|
|
151
|
+
/** Maximum traversal depth */
|
|
152
|
+
maxDepth?: number;
|
|
153
|
+
/** Maximum number of results to return */
|
|
154
|
+
limit?: number;
|
|
155
|
+
/** Optional cursor for pagination */
|
|
156
|
+
cursor?: string;
|
|
157
|
+
/** Filter by relationship types (empty = all types) */
|
|
158
|
+
relTypes?: string[];
|
|
159
|
+
}
|
|
160
|
+
/** A single traversal result item */
|
|
161
|
+
interface TraversalResultItem {
|
|
162
|
+
/** Target node ID reached */
|
|
163
|
+
targetId: number;
|
|
164
|
+
/** Depth of traversal (number of hops from source) */
|
|
165
|
+
depth: number;
|
|
166
|
+
/** Path taken (list of edge IDs) */
|
|
167
|
+
path: number[];
|
|
168
|
+
}
|
|
169
|
+
/** Statistics from traversal operation */
|
|
170
|
+
interface TraversalStats {
|
|
171
|
+
/** Number of nodes visited */
|
|
172
|
+
visited: number;
|
|
173
|
+
/** Maximum depth reached */
|
|
174
|
+
depthReached: number;
|
|
175
|
+
}
|
|
176
|
+
/** Response from graph traversal */
|
|
177
|
+
interface TraverseResponse {
|
|
178
|
+
/** List of traversal results */
|
|
179
|
+
results: TraversalResultItem[];
|
|
180
|
+
/** Cursor for next page (if applicable) */
|
|
181
|
+
nextCursor?: string;
|
|
182
|
+
/** Whether more results are available */
|
|
183
|
+
hasMore: boolean;
|
|
184
|
+
/** Traversal statistics */
|
|
185
|
+
stats: TraversalStats;
|
|
186
|
+
}
|
|
187
|
+
/** Response for node degree query */
|
|
188
|
+
interface DegreeResponse {
|
|
189
|
+
/** Number of incoming edges */
|
|
190
|
+
inDegree: number;
|
|
191
|
+
/** Number of outgoing edges */
|
|
192
|
+
outDegree: number;
|
|
193
|
+
}
|
|
194
|
+
/** VelesQL query options */
|
|
195
|
+
interface QueryOptions {
|
|
196
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
197
|
+
timeoutMs?: number;
|
|
198
|
+
/** Enable streaming response */
|
|
199
|
+
stream?: boolean;
|
|
200
|
+
}
|
|
201
|
+
/** Query result from multi-model VelesQL query */
|
|
202
|
+
interface QueryResult {
|
|
203
|
+
/** Node/point ID */
|
|
204
|
+
nodeId: bigint | number;
|
|
205
|
+
/** Vector similarity score (if applicable) */
|
|
206
|
+
vectorScore: number | null;
|
|
207
|
+
/** Graph relevance score (if applicable) */
|
|
208
|
+
graphScore: number | null;
|
|
209
|
+
/** Combined fused score */
|
|
210
|
+
fusedScore: number;
|
|
211
|
+
/** Variable bindings from MATCH clause */
|
|
212
|
+
bindings: Record<string, unknown>;
|
|
213
|
+
/** Column data from JOIN (if applicable) */
|
|
214
|
+
columnData: Record<string, unknown> | null;
|
|
215
|
+
}
|
|
216
|
+
/** Query execution statistics */
|
|
217
|
+
interface QueryStats {
|
|
218
|
+
/** Execution time in milliseconds */
|
|
219
|
+
executionTimeMs: number;
|
|
220
|
+
/** Execution strategy used */
|
|
221
|
+
strategy: string;
|
|
222
|
+
/** Number of nodes scanned */
|
|
223
|
+
scannedNodes: number;
|
|
224
|
+
}
|
|
225
|
+
/** Full query response with results and stats */
|
|
226
|
+
interface QueryResponse {
|
|
227
|
+
/** Query results */
|
|
228
|
+
results: QueryResult[];
|
|
229
|
+
/** Execution statistics */
|
|
230
|
+
stats: QueryStats;
|
|
231
|
+
}
|
|
232
|
+
/** Index type for property indexes */
|
|
233
|
+
type IndexType = 'hash' | 'range';
|
|
234
|
+
/** Index information */
|
|
235
|
+
interface IndexInfo {
|
|
236
|
+
/** Node label (e.g., "Person") */
|
|
237
|
+
label: string;
|
|
238
|
+
/** Property name (e.g., "email") */
|
|
239
|
+
property: string;
|
|
240
|
+
/** Index type: 'hash' for O(1) equality, 'range' for O(log n) range queries */
|
|
241
|
+
indexType: IndexType;
|
|
242
|
+
/** Number of unique values indexed (for hash indexes) */
|
|
243
|
+
cardinality: number;
|
|
244
|
+
/** Memory usage in bytes */
|
|
245
|
+
memoryBytes: number;
|
|
246
|
+
}
|
|
247
|
+
/** Options for creating an index */
|
|
248
|
+
interface CreateIndexOptions {
|
|
249
|
+
/** Node label to index */
|
|
250
|
+
label: string;
|
|
251
|
+
/** Property name to index */
|
|
252
|
+
property: string;
|
|
253
|
+
/** Index type: 'hash' (default) or 'range' */
|
|
254
|
+
indexType?: IndexType;
|
|
255
|
+
}
|
|
107
256
|
/** Backend interface that all backends must implement */
|
|
108
257
|
interface IVelesDBBackend {
|
|
109
258
|
/** Initialize the backend */
|
|
@@ -145,8 +294,8 @@ interface IVelesDBBackend {
|
|
|
145
294
|
vectorWeight?: number;
|
|
146
295
|
filter?: Record<string, unknown>;
|
|
147
296
|
}): Promise<SearchResult[]>;
|
|
148
|
-
/** Execute VelesQL query */
|
|
149
|
-
query(queryString: string, params?: Record<string, unknown
|
|
297
|
+
/** Execute VelesQL multi-model query (EPIC-031 US-011) */
|
|
298
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
|
|
150
299
|
/** Multi-query fusion search */
|
|
151
300
|
multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
152
301
|
/** Check if collection is empty */
|
|
@@ -155,6 +304,22 @@ interface IVelesDBBackend {
|
|
|
155
304
|
flush(collection: string): Promise<void>;
|
|
156
305
|
/** Close/cleanup the backend */
|
|
157
306
|
close(): Promise<void>;
|
|
307
|
+
/** Create a property index for O(1) equality lookups */
|
|
308
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
309
|
+
/** List all indexes on a collection */
|
|
310
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
311
|
+
/** Check if an index exists */
|
|
312
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
313
|
+
/** Drop an index */
|
|
314
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
315
|
+
/** Add an edge to the collection's knowledge graph */
|
|
316
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
317
|
+
/** Get edges from the collection's knowledge graph */
|
|
318
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
319
|
+
/** Traverse the graph using BFS or DFS from a source node */
|
|
320
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
321
|
+
/** Get the in-degree and out-degree of a node */
|
|
322
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
158
323
|
}
|
|
159
324
|
/** Error types */
|
|
160
325
|
declare class VelesDBError extends Error {
|
|
@@ -335,13 +500,28 @@ declare class VelesDB {
|
|
|
335
500
|
filter?: Record<string, unknown>;
|
|
336
501
|
}): Promise<SearchResult[]>;
|
|
337
502
|
/**
|
|
338
|
-
* Execute a VelesQL query
|
|
503
|
+
* Execute a VelesQL multi-model query (EPIC-031 US-011)
|
|
504
|
+
*
|
|
505
|
+
* Supports hybrid vector + graph queries with VelesQL syntax.
|
|
339
506
|
*
|
|
507
|
+
* @param collection - Collection name
|
|
340
508
|
* @param queryString - VelesQL query string
|
|
341
|
-
* @param params -
|
|
342
|
-
* @
|
|
509
|
+
* @param params - Query parameters (vectors, scalars)
|
|
510
|
+
* @param options - Query options (timeout, streaming)
|
|
511
|
+
* @returns Query response with results and execution stats
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```typescript
|
|
515
|
+
* const response = await db.query('docs', `
|
|
516
|
+
* MATCH (d:Doc) WHERE vector NEAR $q LIMIT 20
|
|
517
|
+
* `, { q: queryVector });
|
|
518
|
+
*
|
|
519
|
+
* for (const r of response.results) {
|
|
520
|
+
* console.log(`Node ${r.nodeId}: ${r.fusedScore}`);
|
|
521
|
+
* }
|
|
522
|
+
* ```
|
|
343
523
|
*/
|
|
344
|
-
query(queryString: string, params?: Record<string, unknown
|
|
524
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
|
|
345
525
|
/**
|
|
346
526
|
* Multi-query fusion search combining results from multiple query vectors
|
|
347
527
|
*
|
|
@@ -391,6 +571,117 @@ declare class VelesDB {
|
|
|
391
571
|
* Get the current backend type
|
|
392
572
|
*/
|
|
393
573
|
get backendType(): string;
|
|
574
|
+
/**
|
|
575
|
+
* Create a property index for O(1) equality lookups or O(log n) range queries
|
|
576
|
+
*
|
|
577
|
+
* @param collection - Collection name
|
|
578
|
+
* @param options - Index configuration (label, property, indexType)
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```typescript
|
|
582
|
+
* // Create hash index for fast email lookups
|
|
583
|
+
* await db.createIndex('users', { label: 'Person', property: 'email' });
|
|
584
|
+
*
|
|
585
|
+
* // Create range index for timestamp queries
|
|
586
|
+
* await db.createIndex('events', { label: 'Event', property: 'timestamp', indexType: 'range' });
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* List all indexes on a collection
|
|
592
|
+
*
|
|
593
|
+
* @param collection - Collection name
|
|
594
|
+
* @returns Array of index information
|
|
595
|
+
*/
|
|
596
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
597
|
+
/**
|
|
598
|
+
* Check if an index exists
|
|
599
|
+
*
|
|
600
|
+
* @param collection - Collection name
|
|
601
|
+
* @param label - Node label
|
|
602
|
+
* @param property - Property name
|
|
603
|
+
* @returns true if index exists
|
|
604
|
+
*/
|
|
605
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
606
|
+
/**
|
|
607
|
+
* Drop an index
|
|
608
|
+
*
|
|
609
|
+
* @param collection - Collection name
|
|
610
|
+
* @param label - Node label
|
|
611
|
+
* @param property - Property name
|
|
612
|
+
* @returns true if index was dropped, false if it didn't exist
|
|
613
|
+
*/
|
|
614
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
615
|
+
/**
|
|
616
|
+
* Add an edge to the collection's knowledge graph
|
|
617
|
+
*
|
|
618
|
+
* @param collection - Collection name
|
|
619
|
+
* @param edge - Edge to add (id, source, target, label, properties)
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* await db.addEdge('social', {
|
|
624
|
+
* id: 1,
|
|
625
|
+
* source: 100,
|
|
626
|
+
* target: 200,
|
|
627
|
+
* label: 'FOLLOWS',
|
|
628
|
+
* properties: { since: '2024-01-01' }
|
|
629
|
+
* });
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
633
|
+
/**
|
|
634
|
+
* Get edges from the collection's knowledge graph
|
|
635
|
+
*
|
|
636
|
+
* @param collection - Collection name
|
|
637
|
+
* @param options - Query options (filter by label)
|
|
638
|
+
* @returns Array of edges
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```typescript
|
|
642
|
+
* // Get all edges with label "FOLLOWS"
|
|
643
|
+
* const edges = await db.getEdges('social', { label: 'FOLLOWS' });
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
647
|
+
/**
|
|
648
|
+
* Traverse the graph using BFS or DFS from a source node
|
|
649
|
+
*
|
|
650
|
+
* @param collection - Collection name
|
|
651
|
+
* @param request - Traversal request options
|
|
652
|
+
* @returns Traversal response with results and stats
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* // BFS traversal from node 100
|
|
657
|
+
* const result = await db.traverseGraph('social', {
|
|
658
|
+
* source: 100,
|
|
659
|
+
* strategy: 'bfs',
|
|
660
|
+
* maxDepth: 3,
|
|
661
|
+
* limit: 100,
|
|
662
|
+
* relTypes: ['FOLLOWS', 'KNOWS']
|
|
663
|
+
* });
|
|
664
|
+
*
|
|
665
|
+
* for (const node of result.results) {
|
|
666
|
+
* console.log(`Reached node ${node.targetId} at depth ${node.depth}`);
|
|
667
|
+
* }
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
671
|
+
/**
|
|
672
|
+
* Get the in-degree and out-degree of a node
|
|
673
|
+
*
|
|
674
|
+
* @param collection - Collection name
|
|
675
|
+
* @param nodeId - Node ID
|
|
676
|
+
* @returns Degree response with inDegree and outDegree
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* const degree = await db.getNodeDegree('social', 100);
|
|
681
|
+
* console.log(`In: ${degree.inDegree}, Out: ${degree.outDegree}`);
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
394
685
|
}
|
|
395
686
|
|
|
396
687
|
/**
|
|
@@ -435,12 +726,20 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
435
726
|
vectorWeight?: number;
|
|
436
727
|
filter?: Record<string, unknown>;
|
|
437
728
|
}): Promise<SearchResult[]>;
|
|
438
|
-
query(_queryString: string, _params?: Record<string, unknown
|
|
729
|
+
query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
|
|
439
730
|
multiQuerySearch(_collection: string, _vectors: Array<number[] | Float32Array>, _options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
440
731
|
isEmpty(collectionName: string): Promise<boolean>;
|
|
441
732
|
flush(collectionName: string): Promise<void>;
|
|
442
733
|
close(): Promise<void>;
|
|
443
734
|
private toNumericId;
|
|
735
|
+
createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
|
|
736
|
+
listIndexes(_collection: string): Promise<IndexInfo[]>;
|
|
737
|
+
hasIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
738
|
+
dropIndex(_collection: string, _label: string, _property: string): Promise<boolean>;
|
|
739
|
+
addEdge(_collection: string, _edge: AddEdgeRequest): Promise<void>;
|
|
740
|
+
getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
741
|
+
traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
|
|
742
|
+
getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
|
|
444
743
|
}
|
|
445
744
|
|
|
446
745
|
/**
|
|
@@ -463,6 +762,13 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
463
762
|
init(): Promise<void>;
|
|
464
763
|
isInitialized(): boolean;
|
|
465
764
|
private ensureInitialized;
|
|
765
|
+
private mapStatusToErrorCode;
|
|
766
|
+
private extractErrorPayload;
|
|
767
|
+
/**
|
|
768
|
+
* Parse node ID safely to handle u64 values above Number.MAX_SAFE_INTEGER.
|
|
769
|
+
* Returns bigint for large values, number for safe values.
|
|
770
|
+
*/
|
|
771
|
+
private parseNodeId;
|
|
466
772
|
private request;
|
|
467
773
|
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
|
468
774
|
deleteCollection(name: string): Promise<void>;
|
|
@@ -487,11 +793,209 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
487
793
|
vectorWeight?: number;
|
|
488
794
|
filter?: Record<string, unknown>;
|
|
489
795
|
}): Promise<SearchResult[]>;
|
|
490
|
-
query(queryString: string, params?: Record<string, unknown
|
|
796
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
|
|
491
797
|
multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
492
798
|
isEmpty(collection: string): Promise<boolean>;
|
|
493
799
|
flush(collection: string): Promise<void>;
|
|
494
800
|
close(): Promise<void>;
|
|
801
|
+
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
802
|
+
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
803
|
+
hasIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
804
|
+
dropIndex(collection: string, label: string, property: string): Promise<boolean>;
|
|
805
|
+
addEdge(collection: string, edge: AddEdgeRequest): Promise<void>;
|
|
806
|
+
getEdges(collection: string, options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
807
|
+
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
808
|
+
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* VelesQL Query Builder (EPIC-012/US-004)
|
|
813
|
+
*
|
|
814
|
+
* Fluent, type-safe API for building VelesQL queries.
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* ```typescript
|
|
818
|
+
* import { velesql } from '@velesdb/sdk';
|
|
819
|
+
*
|
|
820
|
+
* const query = velesql()
|
|
821
|
+
* .match('d', 'Document')
|
|
822
|
+
* .nearVector('$q', embedding)
|
|
823
|
+
* .andWhere('d.category = $cat', { cat: 'tech' })
|
|
824
|
+
* .limit(20)
|
|
825
|
+
* .toVelesQL();
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* @packageDocumentation
|
|
829
|
+
*/
|
|
830
|
+
/** Direction for relationship traversal */
|
|
831
|
+
type RelDirection = 'outgoing' | 'incoming' | 'both';
|
|
832
|
+
/** Fusion strategy for hybrid queries */
|
|
833
|
+
type FusionStrategy = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
834
|
+
/** Options for relationship patterns */
|
|
835
|
+
interface RelOptions {
|
|
836
|
+
direction?: RelDirection;
|
|
837
|
+
minHops?: number;
|
|
838
|
+
maxHops?: number;
|
|
839
|
+
}
|
|
840
|
+
/** Options for vector NEAR clause */
|
|
841
|
+
interface NearVectorOptions {
|
|
842
|
+
topK?: number;
|
|
843
|
+
}
|
|
844
|
+
/** Fusion configuration */
|
|
845
|
+
interface FusionOptions {
|
|
846
|
+
strategy: FusionStrategy;
|
|
847
|
+
k?: number;
|
|
848
|
+
vectorWeight?: number;
|
|
849
|
+
graphWeight?: number;
|
|
850
|
+
}
|
|
851
|
+
/** Internal state for the query builder */
|
|
852
|
+
interface BuilderState {
|
|
853
|
+
matchClauses: string[];
|
|
854
|
+
whereClauses: string[];
|
|
855
|
+
whereOperators: string[];
|
|
856
|
+
params: Record<string, unknown>;
|
|
857
|
+
limitValue?: number;
|
|
858
|
+
offsetValue?: number;
|
|
859
|
+
orderByClause?: string;
|
|
860
|
+
returnClause?: string;
|
|
861
|
+
fusionOptions?: FusionOptions;
|
|
862
|
+
currentNode?: string;
|
|
863
|
+
pendingRel?: {
|
|
864
|
+
type: string;
|
|
865
|
+
alias?: string;
|
|
866
|
+
options?: RelOptions;
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* VelesQL Query Builder
|
|
871
|
+
*
|
|
872
|
+
* Immutable builder for constructing VelesQL queries with type safety.
|
|
873
|
+
*/
|
|
874
|
+
declare class VelesQLBuilder {
|
|
875
|
+
private readonly state;
|
|
876
|
+
constructor(state?: Partial<BuilderState>);
|
|
877
|
+
private clone;
|
|
878
|
+
/**
|
|
879
|
+
* Start a MATCH clause with a node pattern
|
|
880
|
+
*
|
|
881
|
+
* @param alias - Node alias (e.g., 'n', 'person')
|
|
882
|
+
* @param label - Optional node label(s)
|
|
883
|
+
*/
|
|
884
|
+
match(alias: string, label?: string | string[]): VelesQLBuilder;
|
|
885
|
+
/**
|
|
886
|
+
* Add a relationship pattern
|
|
887
|
+
*
|
|
888
|
+
* @param type - Relationship type (e.g., 'KNOWS', 'FOLLOWS')
|
|
889
|
+
* @param alias - Optional relationship alias
|
|
890
|
+
* @param options - Relationship options (direction, hops)
|
|
891
|
+
*/
|
|
892
|
+
rel(type: string, alias?: string, options?: RelOptions): VelesQLBuilder;
|
|
893
|
+
/**
|
|
894
|
+
* Complete a relationship pattern with target node
|
|
895
|
+
*
|
|
896
|
+
* @param alias - Target node alias
|
|
897
|
+
* @param label - Optional target node label(s)
|
|
898
|
+
*/
|
|
899
|
+
to(alias: string, label?: string | string[]): VelesQLBuilder;
|
|
900
|
+
/**
|
|
901
|
+
* Add a WHERE clause
|
|
902
|
+
*
|
|
903
|
+
* @param condition - WHERE condition
|
|
904
|
+
* @param params - Optional parameters
|
|
905
|
+
*/
|
|
906
|
+
where(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
907
|
+
/**
|
|
908
|
+
* Add an AND WHERE clause
|
|
909
|
+
*
|
|
910
|
+
* @param condition - WHERE condition
|
|
911
|
+
* @param params - Optional parameters
|
|
912
|
+
*/
|
|
913
|
+
andWhere(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
914
|
+
/**
|
|
915
|
+
* Add an OR WHERE clause
|
|
916
|
+
*
|
|
917
|
+
* @param condition - WHERE condition
|
|
918
|
+
* @param params - Optional parameters
|
|
919
|
+
*/
|
|
920
|
+
orWhere(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
921
|
+
/**
|
|
922
|
+
* Add a vector NEAR clause for similarity search
|
|
923
|
+
*
|
|
924
|
+
* @param paramName - Parameter name (e.g., '$query', '$embedding')
|
|
925
|
+
* @param vector - Vector data
|
|
926
|
+
* @param options - NEAR options (topK)
|
|
927
|
+
*/
|
|
928
|
+
nearVector(paramName: string, vector: number[] | Float32Array, options?: NearVectorOptions): VelesQLBuilder;
|
|
929
|
+
/**
|
|
930
|
+
* Add LIMIT clause
|
|
931
|
+
*
|
|
932
|
+
* @param value - Maximum number of results
|
|
933
|
+
*/
|
|
934
|
+
limit(value: number): VelesQLBuilder;
|
|
935
|
+
/**
|
|
936
|
+
* Add OFFSET clause
|
|
937
|
+
*
|
|
938
|
+
* @param value - Number of results to skip
|
|
939
|
+
*/
|
|
940
|
+
offset(value: number): VelesQLBuilder;
|
|
941
|
+
/**
|
|
942
|
+
* Add ORDER BY clause
|
|
943
|
+
*
|
|
944
|
+
* @param field - Field to order by
|
|
945
|
+
* @param direction - Sort direction (ASC or DESC)
|
|
946
|
+
*/
|
|
947
|
+
orderBy(field: string, direction?: 'ASC' | 'DESC'): VelesQLBuilder;
|
|
948
|
+
/**
|
|
949
|
+
* Add RETURN clause with specific fields
|
|
950
|
+
*
|
|
951
|
+
* @param fields - Fields to return (array or object with aliases)
|
|
952
|
+
*/
|
|
953
|
+
return(fields: string[] | Record<string, string>): VelesQLBuilder;
|
|
954
|
+
/**
|
|
955
|
+
* Add RETURN * clause
|
|
956
|
+
*/
|
|
957
|
+
returnAll(): VelesQLBuilder;
|
|
958
|
+
/**
|
|
959
|
+
* Set fusion strategy for hybrid queries
|
|
960
|
+
*
|
|
961
|
+
* @param strategy - Fusion strategy
|
|
962
|
+
* @param options - Fusion parameters
|
|
963
|
+
*/
|
|
964
|
+
fusion(strategy: FusionStrategy, options?: {
|
|
965
|
+
k?: number;
|
|
966
|
+
vectorWeight?: number;
|
|
967
|
+
graphWeight?: number;
|
|
968
|
+
}): VelesQLBuilder;
|
|
969
|
+
/**
|
|
970
|
+
* Get the fusion options
|
|
971
|
+
*/
|
|
972
|
+
getFusionOptions(): FusionOptions | undefined;
|
|
973
|
+
/**
|
|
974
|
+
* Get all parameters
|
|
975
|
+
*/
|
|
976
|
+
getParams(): Record<string, unknown>;
|
|
977
|
+
/**
|
|
978
|
+
* Build the VelesQL query string
|
|
979
|
+
*/
|
|
980
|
+
toVelesQL(): string;
|
|
981
|
+
private formatLabel;
|
|
982
|
+
private formatRelationship;
|
|
983
|
+
private formatHops;
|
|
984
|
+
private buildWhereClause;
|
|
495
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* Create a new VelesQL query builder
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```typescript
|
|
991
|
+
* const query = velesql()
|
|
992
|
+
* .match('n', 'Person')
|
|
993
|
+
* .where('n.age > 21')
|
|
994
|
+
* .limit(10)
|
|
995
|
+
* .toVelesQL();
|
|
996
|
+
* // => "MATCH (n:Person) WHERE n.age > 21 LIMIT 10"
|
|
997
|
+
* ```
|
|
998
|
+
*/
|
|
999
|
+
declare function velesql(): VelesQLBuilder;
|
|
496
1000
|
|
|
497
|
-
export { type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type DistanceMetric, type FusionStrategy, type IVelesDBBackend, type MultiQuerySearchOptions, NotFoundError, RestBackend, type SearchOptions, type SearchResult, type StorageMode, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, WasmBackend };
|
|
1001
|
+
export { type AddEdgeRequest, type BackendType, type Collection, type CollectionConfig, type CollectionType, ConnectionError, type CreateIndexOptions, type DegreeResponse, type DistanceMetric, type EdgesResponse, type FusionOptions, type FusionStrategy$1 as FusionStrategy, type GetEdgesOptions, type GraphEdge, type IVelesDBBackend, type IndexInfo, type IndexType, type MultiQuerySearchOptions, type NearVectorOptions, NotFoundError, type QueryOptions, type QueryResponse, type QueryResult, type QueryStats, type RelDirection, type RelOptions, RestBackend, type SearchOptions, type SearchResult, type StorageMode, type TraversalResultItem, type TraversalStats, type TraverseRequest, type TraverseResponse, ValidationError, type VectorDocument, VelesDB, type VelesDBConfig, VelesDBError, VelesQLBuilder, WasmBackend, velesql };
|