@wiscale/velesdb-sdk 1.3.0 → 1.5.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 +157 -3
- package/dist/index.d.mts +386 -11
- package/dist/index.d.ts +386 -11
- package/dist/index.js +899 -60
- package/dist/index.mjs +895 -59
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,8 @@ type DistanceMetric = 'cosine' | 'euclidean' | 'dot' | 'hamming' | 'jaccard';
|
|
|
8
8
|
type StorageMode = 'full' | 'sq8' | 'binary';
|
|
9
9
|
/** Backend type for VelesDB connection */
|
|
10
10
|
type BackendType = 'wasm' | 'rest';
|
|
11
|
+
/** Numeric point ID required by velesdb-server REST API (`u64`). */
|
|
12
|
+
type RestPointId = number;
|
|
11
13
|
/** Configuration options for VelesDB client */
|
|
12
14
|
interface VelesDBConfig {
|
|
13
15
|
/** Backend type: 'wasm' for browser/Node.js, 'rest' for server */
|
|
@@ -53,6 +55,8 @@ interface Collection {
|
|
|
53
55
|
/** Creation timestamp */
|
|
54
56
|
createdAt?: Date;
|
|
55
57
|
}
|
|
58
|
+
/** Sparse vector: mapping from term/dimension index to weight */
|
|
59
|
+
type SparseVector = Record<number, number>;
|
|
56
60
|
/** Vector document to insert */
|
|
57
61
|
interface VectorDocument {
|
|
58
62
|
/** Unique identifier */
|
|
@@ -61,6 +65,8 @@ interface VectorDocument {
|
|
|
61
65
|
vector: number[] | Float32Array;
|
|
62
66
|
/** Optional payload/metadata */
|
|
63
67
|
payload?: Record<string, unknown>;
|
|
68
|
+
/** Optional sparse vector for hybrid search */
|
|
69
|
+
sparseVector?: SparseVector;
|
|
64
70
|
}
|
|
65
71
|
/** Search options */
|
|
66
72
|
interface SearchOptions {
|
|
@@ -70,15 +76,26 @@ interface SearchOptions {
|
|
|
70
76
|
filter?: Record<string, unknown>;
|
|
71
77
|
/** Include vectors in results (default: false) */
|
|
72
78
|
includeVectors?: boolean;
|
|
79
|
+
/** Optional sparse vector for hybrid sparse+dense search */
|
|
80
|
+
sparseVector?: SparseVector;
|
|
81
|
+
}
|
|
82
|
+
/** PQ (Product Quantization) training options */
|
|
83
|
+
interface PqTrainOptions {
|
|
84
|
+
/** Number of subquantizers (default: 8) */
|
|
85
|
+
m?: number;
|
|
86
|
+
/** Number of centroids per subquantizer (default: 256) */
|
|
87
|
+
k?: number;
|
|
88
|
+
/** Enable Optimized Product Quantization (default: false) */
|
|
89
|
+
opq?: boolean;
|
|
73
90
|
}
|
|
74
91
|
/** Fusion strategy for multi-query search */
|
|
75
|
-
type FusionStrategy = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
92
|
+
type FusionStrategy$1 = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
76
93
|
/** Multi-query search options */
|
|
77
94
|
interface MultiQuerySearchOptions {
|
|
78
95
|
/** Number of results to return (default: 10) */
|
|
79
96
|
k?: number;
|
|
80
97
|
/** Fusion strategy (default: 'rrf') */
|
|
81
|
-
fusion?: FusionStrategy;
|
|
98
|
+
fusion?: FusionStrategy$1;
|
|
82
99
|
/** Fusion parameters */
|
|
83
100
|
fusionParams?: {
|
|
84
101
|
/** RRF k parameter (default: 60) */
|
|
@@ -191,6 +208,106 @@ interface DegreeResponse {
|
|
|
191
208
|
/** Number of outgoing edges */
|
|
192
209
|
outDegree: number;
|
|
193
210
|
}
|
|
211
|
+
/** VelesQL query options */
|
|
212
|
+
interface QueryOptions {
|
|
213
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
214
|
+
timeoutMs?: number;
|
|
215
|
+
/** Enable streaming response */
|
|
216
|
+
stream?: boolean;
|
|
217
|
+
}
|
|
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
|
+
}
|
|
233
|
+
/** Query execution statistics */
|
|
234
|
+
interface QueryStats {
|
|
235
|
+
/** Execution time in milliseconds */
|
|
236
|
+
executionTimeMs: number;
|
|
237
|
+
/** Execution strategy used */
|
|
238
|
+
strategy: string;
|
|
239
|
+
/** Number of nodes scanned */
|
|
240
|
+
scannedNodes: number;
|
|
241
|
+
}
|
|
242
|
+
/** Full query response with results and stats */
|
|
243
|
+
interface QueryResponse {
|
|
244
|
+
/** Query results */
|
|
245
|
+
results: QueryResult[];
|
|
246
|
+
/** Execution statistics */
|
|
247
|
+
stats: QueryStats;
|
|
248
|
+
}
|
|
249
|
+
/** Aggregation query response from VelesQL (`GROUP BY`, `COUNT`, `SUM`, etc.). */
|
|
250
|
+
interface AggregationQueryResponse {
|
|
251
|
+
/** Aggregation result payload as returned by server. */
|
|
252
|
+
result: Record<string, unknown> | unknown[];
|
|
253
|
+
/** Execution statistics */
|
|
254
|
+
stats: QueryStats;
|
|
255
|
+
}
|
|
256
|
+
/** Unified response type for `query()` (rows or aggregation). */
|
|
257
|
+
type QueryApiResponse = QueryResponse | AggregationQueryResponse;
|
|
258
|
+
/** Query explain request/response metadata */
|
|
259
|
+
interface ExplainPlanStep {
|
|
260
|
+
step: number;
|
|
261
|
+
operation: string;
|
|
262
|
+
description: string;
|
|
263
|
+
estimatedRows: number | null;
|
|
264
|
+
}
|
|
265
|
+
interface ExplainCost {
|
|
266
|
+
usesIndex: boolean;
|
|
267
|
+
indexName: string | null;
|
|
268
|
+
selectivity: number;
|
|
269
|
+
complexity: string;
|
|
270
|
+
}
|
|
271
|
+
interface ExplainFeatures {
|
|
272
|
+
hasVectorSearch: boolean;
|
|
273
|
+
hasFilter: boolean;
|
|
274
|
+
hasOrderBy: boolean;
|
|
275
|
+
hasGroupBy: boolean;
|
|
276
|
+
hasAggregation: boolean;
|
|
277
|
+
hasJoin: boolean;
|
|
278
|
+
hasFusion: boolean;
|
|
279
|
+
limit: number | null;
|
|
280
|
+
offset: number | null;
|
|
281
|
+
}
|
|
282
|
+
interface ExplainResponse {
|
|
283
|
+
query: string;
|
|
284
|
+
queryType: string;
|
|
285
|
+
collection: string;
|
|
286
|
+
plan: ExplainPlanStep[];
|
|
287
|
+
estimatedCost: ExplainCost;
|
|
288
|
+
features: ExplainFeatures;
|
|
289
|
+
}
|
|
290
|
+
interface CollectionSanityChecks {
|
|
291
|
+
hasVectors: boolean;
|
|
292
|
+
searchReady: boolean;
|
|
293
|
+
dimensionConfigured: boolean;
|
|
294
|
+
}
|
|
295
|
+
interface CollectionSanityDiagnostics {
|
|
296
|
+
searchRequestsTotal: number;
|
|
297
|
+
dimensionMismatchTotal: number;
|
|
298
|
+
emptySearchResultsTotal: number;
|
|
299
|
+
filterParseErrorsTotal: number;
|
|
300
|
+
}
|
|
301
|
+
interface CollectionSanityResponse {
|
|
302
|
+
collection: string;
|
|
303
|
+
dimension: number;
|
|
304
|
+
metric: string;
|
|
305
|
+
pointCount: number;
|
|
306
|
+
isEmpty: boolean;
|
|
307
|
+
checks: CollectionSanityChecks;
|
|
308
|
+
diagnostics: CollectionSanityDiagnostics;
|
|
309
|
+
hints: string[];
|
|
310
|
+
}
|
|
194
311
|
/** Index type for property indexes */
|
|
195
312
|
type IndexType = 'hash' | 'range';
|
|
196
313
|
/** Index information */
|
|
@@ -256,8 +373,12 @@ interface IVelesDBBackend {
|
|
|
256
373
|
vectorWeight?: number;
|
|
257
374
|
filter?: Record<string, unknown>;
|
|
258
375
|
}): Promise<SearchResult[]>;
|
|
259
|
-
/** Execute VelesQL query */
|
|
260
|
-
query(queryString: string, params?: Record<string, unknown
|
|
376
|
+
/** Execute VelesQL multi-model query (EPIC-031 US-011) */
|
|
377
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
|
|
378
|
+
/** Explain a VelesQL query without executing it */
|
|
379
|
+
queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
|
|
380
|
+
/** Run collection sanity checks */
|
|
381
|
+
collectionSanity(collection: string): Promise<CollectionSanityResponse>;
|
|
261
382
|
/** Multi-query fusion search */
|
|
262
383
|
multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
263
384
|
/** Check if collection is empty */
|
|
@@ -282,6 +403,10 @@ interface IVelesDBBackend {
|
|
|
282
403
|
traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
|
|
283
404
|
/** Get the in-degree and out-degree of a node */
|
|
284
405
|
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
406
|
+
/** Train Product Quantization on a collection */
|
|
407
|
+
trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
|
|
408
|
+
/** Stream-insert documents with backpressure support */
|
|
409
|
+
streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
|
|
285
410
|
}
|
|
286
411
|
/** Error types */
|
|
287
412
|
declare class VelesDBError extends Error {
|
|
@@ -298,6 +423,10 @@ declare class ValidationError extends VelesDBError {
|
|
|
298
423
|
declare class NotFoundError extends VelesDBError {
|
|
299
424
|
constructor(resource: string);
|
|
300
425
|
}
|
|
426
|
+
/** Thrown when stream insert receives 429 Too Many Requests (backpressure) */
|
|
427
|
+
declare class BackpressureError extends VelesDBError {
|
|
428
|
+
constructor(message?: string);
|
|
429
|
+
}
|
|
301
430
|
|
|
302
431
|
/**
|
|
303
432
|
* VelesDB Client - Unified interface for all backends
|
|
@@ -398,6 +527,7 @@ declare class VelesDB {
|
|
|
398
527
|
*/
|
|
399
528
|
insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
|
|
400
529
|
private validateDocument;
|
|
530
|
+
private validateRestPointId;
|
|
401
531
|
/**
|
|
402
532
|
* Search for similar vectors
|
|
403
533
|
*
|
|
@@ -462,13 +592,28 @@ declare class VelesDB {
|
|
|
462
592
|
filter?: Record<string, unknown>;
|
|
463
593
|
}): Promise<SearchResult[]>;
|
|
464
594
|
/**
|
|
465
|
-
* Execute a VelesQL query
|
|
595
|
+
* Execute a VelesQL multi-model query (EPIC-031 US-011)
|
|
596
|
+
*
|
|
597
|
+
* Supports hybrid vector + graph queries with VelesQL syntax.
|
|
466
598
|
*
|
|
599
|
+
* @param collection - Collection name
|
|
467
600
|
* @param queryString - VelesQL query string
|
|
468
|
-
* @param params -
|
|
469
|
-
* @
|
|
601
|
+
* @param params - Query parameters (vectors, scalars)
|
|
602
|
+
* @param options - Query options (timeout, streaming)
|
|
603
|
+
* @returns Query response with results and execution stats
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```typescript
|
|
607
|
+
* const response = await db.query('docs', `
|
|
608
|
+
* MATCH (d:Doc) WHERE vector NEAR $q LIMIT 20
|
|
609
|
+
* `, { q: queryVector });
|
|
610
|
+
*
|
|
611
|
+
* for (const r of response.results) {
|
|
612
|
+
* console.log(`Node ${r.nodeId}: ${r.fusedScore}`);
|
|
613
|
+
* }
|
|
614
|
+
* ```
|
|
470
615
|
*/
|
|
471
|
-
query(queryString: string, params?: Record<string, unknown
|
|
616
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
|
|
472
617
|
/**
|
|
473
618
|
* Multi-query fusion search combining results from multiple query vectors
|
|
474
619
|
*
|
|
@@ -496,7 +641,27 @@ declare class VelesDB {
|
|
|
496
641
|
* });
|
|
497
642
|
* ```
|
|
498
643
|
*/
|
|
644
|
+
queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
|
|
645
|
+
collectionSanity(collection: string): Promise<CollectionSanityResponse>;
|
|
499
646
|
multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
647
|
+
/**
|
|
648
|
+
* Train Product Quantization on a collection
|
|
649
|
+
*
|
|
650
|
+
* @param collection - Collection name
|
|
651
|
+
* @param options - PQ training options (m, k, opq)
|
|
652
|
+
* @returns Server response message
|
|
653
|
+
*/
|
|
654
|
+
trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
|
|
655
|
+
/**
|
|
656
|
+
* Stream-insert documents with backpressure support
|
|
657
|
+
*
|
|
658
|
+
* Sends documents sequentially to respect server backpressure.
|
|
659
|
+
* Throws BackpressureError on 429 responses.
|
|
660
|
+
*
|
|
661
|
+
* @param collection - Collection name
|
|
662
|
+
* @param docs - Documents to insert
|
|
663
|
+
*/
|
|
664
|
+
streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
|
|
500
665
|
/**
|
|
501
666
|
* Check if a collection is empty
|
|
502
667
|
*
|
|
@@ -650,6 +815,9 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
650
815
|
init(): Promise<void>;
|
|
651
816
|
isInitialized(): boolean;
|
|
652
817
|
private ensureInitialized;
|
|
818
|
+
private normalizeIdString;
|
|
819
|
+
private canonicalPayloadKeyFromResultId;
|
|
820
|
+
private canonicalPayloadKey;
|
|
653
821
|
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
|
654
822
|
deleteCollection(name: string): Promise<void>;
|
|
655
823
|
getCollection(name: string): Promise<Collection | null>;
|
|
@@ -673,11 +841,14 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
673
841
|
vectorWeight?: number;
|
|
674
842
|
filter?: Record<string, unknown>;
|
|
675
843
|
}): Promise<SearchResult[]>;
|
|
676
|
-
query(_queryString: string, _params?: Record<string, unknown
|
|
844
|
+
query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryApiResponse>;
|
|
677
845
|
multiQuerySearch(_collection: string, _vectors: Array<number[] | Float32Array>, _options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
846
|
+
queryExplain(_queryString: string, _params?: Record<string, unknown>): Promise<ExplainResponse>;
|
|
847
|
+
collectionSanity(_collection: string): Promise<CollectionSanityResponse>;
|
|
678
848
|
isEmpty(collectionName: string): Promise<boolean>;
|
|
679
849
|
flush(collectionName: string): Promise<void>;
|
|
680
850
|
close(): Promise<void>;
|
|
851
|
+
private sparseVectorToArrays;
|
|
681
852
|
private toNumericId;
|
|
682
853
|
createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
|
|
683
854
|
listIndexes(_collection: string): Promise<IndexInfo[]>;
|
|
@@ -687,6 +858,8 @@ declare class WasmBackend implements IVelesDBBackend {
|
|
|
687
858
|
getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
|
|
688
859
|
traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
|
|
689
860
|
getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
|
|
861
|
+
trainPq(_collection: string, _options?: PqTrainOptions): Promise<string>;
|
|
862
|
+
streamInsert(_collection: string, _docs: VectorDocument[]): Promise<void>;
|
|
690
863
|
}
|
|
691
864
|
|
|
692
865
|
/**
|
|
@@ -711,6 +884,13 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
711
884
|
private ensureInitialized;
|
|
712
885
|
private mapStatusToErrorCode;
|
|
713
886
|
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
|
+
private parseNodeId;
|
|
892
|
+
private parseRestPointId;
|
|
893
|
+
private isLikelyAggregationQuery;
|
|
714
894
|
private request;
|
|
715
895
|
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
|
716
896
|
deleteCollection(name: string): Promise<void>;
|
|
@@ -718,6 +898,7 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
718
898
|
listCollections(): Promise<Collection[]>;
|
|
719
899
|
insert(collection: string, doc: VectorDocument): Promise<void>;
|
|
720
900
|
insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
|
|
901
|
+
private sparseVectorToRestFormat;
|
|
721
902
|
search(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
|
|
722
903
|
searchBatch(collection: string, searches: Array<{
|
|
723
904
|
vector: number[] | Float32Array;
|
|
@@ -735,10 +916,14 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
735
916
|
vectorWeight?: number;
|
|
736
917
|
filter?: Record<string, unknown>;
|
|
737
918
|
}): Promise<SearchResult[]>;
|
|
738
|
-
query(queryString: string, params?: Record<string, unknown
|
|
919
|
+
query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
|
|
920
|
+
queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
|
|
921
|
+
collectionSanity(collection: string): Promise<CollectionSanityResponse>;
|
|
739
922
|
multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
|
|
740
923
|
isEmpty(collection: string): Promise<boolean>;
|
|
741
924
|
flush(collection: string): Promise<void>;
|
|
925
|
+
trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
|
|
926
|
+
streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
|
|
742
927
|
close(): Promise<void>;
|
|
743
928
|
createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
|
|
744
929
|
listIndexes(collection: string): Promise<IndexInfo[]>;
|
|
@@ -750,4 +935,194 @@ declare class RestBackend implements IVelesDBBackend {
|
|
|
750
935
|
getNodeDegree(collection: string, nodeId: number): Promise<DegreeResponse>;
|
|
751
936
|
}
|
|
752
937
|
|
|
753
|
-
|
|
938
|
+
/**
|
|
939
|
+
* VelesQL Query Builder (EPIC-012/US-004)
|
|
940
|
+
*
|
|
941
|
+
* Fluent, type-safe API for building VelesQL queries.
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* import { velesql } from '@velesdb/sdk';
|
|
946
|
+
*
|
|
947
|
+
* const query = velesql()
|
|
948
|
+
* .match('d', 'Document')
|
|
949
|
+
* .nearVector('$q', embedding)
|
|
950
|
+
* .andWhere('d.category = $cat', { cat: 'tech' })
|
|
951
|
+
* .limit(20)
|
|
952
|
+
* .toVelesQL();
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* @packageDocumentation
|
|
956
|
+
*/
|
|
957
|
+
/** Direction for relationship traversal */
|
|
958
|
+
type RelDirection = 'outgoing' | 'incoming' | 'both';
|
|
959
|
+
/** Fusion strategy for hybrid queries */
|
|
960
|
+
type FusionStrategy = 'rrf' | 'average' | 'maximum' | 'weighted';
|
|
961
|
+
/** Options for relationship patterns */
|
|
962
|
+
interface RelOptions {
|
|
963
|
+
direction?: RelDirection;
|
|
964
|
+
minHops?: number;
|
|
965
|
+
maxHops?: number;
|
|
966
|
+
}
|
|
967
|
+
/** Options for vector NEAR clause */
|
|
968
|
+
interface NearVectorOptions {
|
|
969
|
+
topK?: number;
|
|
970
|
+
}
|
|
971
|
+
/** Fusion configuration */
|
|
972
|
+
interface FusionOptions {
|
|
973
|
+
strategy: FusionStrategy;
|
|
974
|
+
k?: number;
|
|
975
|
+
vectorWeight?: number;
|
|
976
|
+
graphWeight?: number;
|
|
977
|
+
}
|
|
978
|
+
/** Internal state for the query builder */
|
|
979
|
+
interface BuilderState {
|
|
980
|
+
matchClauses: string[];
|
|
981
|
+
whereClauses: string[];
|
|
982
|
+
whereOperators: string[];
|
|
983
|
+
params: Record<string, unknown>;
|
|
984
|
+
limitValue?: number;
|
|
985
|
+
offsetValue?: number;
|
|
986
|
+
orderByClause?: string;
|
|
987
|
+
returnClause?: string;
|
|
988
|
+
fusionOptions?: FusionOptions;
|
|
989
|
+
currentNode?: string;
|
|
990
|
+
pendingRel?: {
|
|
991
|
+
type: string;
|
|
992
|
+
alias?: string;
|
|
993
|
+
options?: RelOptions;
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* VelesQL Query Builder
|
|
998
|
+
*
|
|
999
|
+
* Immutable builder for constructing VelesQL queries with type safety.
|
|
1000
|
+
*/
|
|
1001
|
+
declare class VelesQLBuilder {
|
|
1002
|
+
private readonly state;
|
|
1003
|
+
constructor(state?: Partial<BuilderState>);
|
|
1004
|
+
private clone;
|
|
1005
|
+
/**
|
|
1006
|
+
* Start a MATCH clause with a node pattern
|
|
1007
|
+
*
|
|
1008
|
+
* @param alias - Node alias (e.g., 'n', 'person')
|
|
1009
|
+
* @param label - Optional node label(s)
|
|
1010
|
+
*/
|
|
1011
|
+
match(alias: string, label?: string | string[]): VelesQLBuilder;
|
|
1012
|
+
/**
|
|
1013
|
+
* Add a relationship pattern
|
|
1014
|
+
*
|
|
1015
|
+
* @param type - Relationship type (e.g., 'KNOWS', 'FOLLOWS')
|
|
1016
|
+
* @param alias - Optional relationship alias
|
|
1017
|
+
* @param options - Relationship options (direction, hops)
|
|
1018
|
+
*/
|
|
1019
|
+
rel(type: string, alias?: string, options?: RelOptions): VelesQLBuilder;
|
|
1020
|
+
/**
|
|
1021
|
+
* Complete a relationship pattern with target node
|
|
1022
|
+
*
|
|
1023
|
+
* @param alias - Target node alias
|
|
1024
|
+
* @param label - Optional target node label(s)
|
|
1025
|
+
*/
|
|
1026
|
+
to(alias: string, label?: string | string[]): VelesQLBuilder;
|
|
1027
|
+
/**
|
|
1028
|
+
* Add a WHERE clause
|
|
1029
|
+
*
|
|
1030
|
+
* @param condition - WHERE condition
|
|
1031
|
+
* @param params - Optional parameters
|
|
1032
|
+
*/
|
|
1033
|
+
where(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
1034
|
+
/**
|
|
1035
|
+
* Add an AND WHERE clause
|
|
1036
|
+
*
|
|
1037
|
+
* @param condition - WHERE condition
|
|
1038
|
+
* @param params - Optional parameters
|
|
1039
|
+
*/
|
|
1040
|
+
andWhere(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
1041
|
+
/**
|
|
1042
|
+
* Add an OR WHERE clause
|
|
1043
|
+
*
|
|
1044
|
+
* @param condition - WHERE condition
|
|
1045
|
+
* @param params - Optional parameters
|
|
1046
|
+
*/
|
|
1047
|
+
orWhere(condition: string, params?: Record<string, unknown>): VelesQLBuilder;
|
|
1048
|
+
/**
|
|
1049
|
+
* Add a vector NEAR clause for similarity search
|
|
1050
|
+
*
|
|
1051
|
+
* @param paramName - Parameter name (e.g., '$query', '$embedding')
|
|
1052
|
+
* @param vector - Vector data
|
|
1053
|
+
* @param options - NEAR options (topK)
|
|
1054
|
+
*/
|
|
1055
|
+
nearVector(paramName: string, vector: number[] | Float32Array, options?: NearVectorOptions): VelesQLBuilder;
|
|
1056
|
+
/**
|
|
1057
|
+
* Add LIMIT clause
|
|
1058
|
+
*
|
|
1059
|
+
* @param value - Maximum number of results
|
|
1060
|
+
*/
|
|
1061
|
+
limit(value: number): VelesQLBuilder;
|
|
1062
|
+
/**
|
|
1063
|
+
* Add OFFSET clause
|
|
1064
|
+
*
|
|
1065
|
+
* @param value - Number of results to skip
|
|
1066
|
+
*/
|
|
1067
|
+
offset(value: number): VelesQLBuilder;
|
|
1068
|
+
/**
|
|
1069
|
+
* Add ORDER BY clause
|
|
1070
|
+
*
|
|
1071
|
+
* @param field - Field to order by
|
|
1072
|
+
* @param direction - Sort direction (ASC or DESC)
|
|
1073
|
+
*/
|
|
1074
|
+
orderBy(field: string, direction?: 'ASC' | 'DESC'): VelesQLBuilder;
|
|
1075
|
+
/**
|
|
1076
|
+
* Add RETURN clause with specific fields
|
|
1077
|
+
*
|
|
1078
|
+
* @param fields - Fields to return (array or object with aliases)
|
|
1079
|
+
*/
|
|
1080
|
+
return(fields: string[] | Record<string, string>): VelesQLBuilder;
|
|
1081
|
+
/**
|
|
1082
|
+
* Add RETURN * clause
|
|
1083
|
+
*/
|
|
1084
|
+
returnAll(): VelesQLBuilder;
|
|
1085
|
+
/**
|
|
1086
|
+
* Set fusion strategy for hybrid queries
|
|
1087
|
+
*
|
|
1088
|
+
* @param strategy - Fusion strategy
|
|
1089
|
+
* @param options - Fusion parameters
|
|
1090
|
+
*/
|
|
1091
|
+
fusion(strategy: FusionStrategy, options?: {
|
|
1092
|
+
k?: number;
|
|
1093
|
+
vectorWeight?: number;
|
|
1094
|
+
graphWeight?: number;
|
|
1095
|
+
}): VelesQLBuilder;
|
|
1096
|
+
/**
|
|
1097
|
+
* Get the fusion options
|
|
1098
|
+
*/
|
|
1099
|
+
getFusionOptions(): FusionOptions | undefined;
|
|
1100
|
+
/**
|
|
1101
|
+
* Get all parameters
|
|
1102
|
+
*/
|
|
1103
|
+
getParams(): Record<string, unknown>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Build the VelesQL query string
|
|
1106
|
+
*/
|
|
1107
|
+
toVelesQL(): string;
|
|
1108
|
+
private formatLabel;
|
|
1109
|
+
private formatRelationship;
|
|
1110
|
+
private formatHops;
|
|
1111
|
+
private buildWhereClause;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Create a new VelesQL query builder
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* const query = velesql()
|
|
1119
|
+
* .match('n', 'Person')
|
|
1120
|
+
* .where('n.age > 21')
|
|
1121
|
+
* .limit(10)
|
|
1122
|
+
* .toVelesQL();
|
|
1123
|
+
* // => "MATCH (n:Person) WHERE n.age > 21 LIMIT 10"
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
declare function velesql(): VelesQLBuilder;
|
|
1127
|
+
|
|
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 };
|