@wiscale/velesdb-sdk 1.4.1 → 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 CHANGED
@@ -62,7 +62,7 @@ await db.init();
62
62
 
63
63
  // Same API as WASM backend
64
64
  await db.createCollection('products', { dimension: 1536 });
65
- await db.insert('products', { id: 'p1', vector: [...] });
65
+ await db.insert('products', { id: 1, vector: [...] });
66
66
  const results = await db.search('products', query, { k: 10 });
67
67
  ```
68
68
 
@@ -120,6 +120,10 @@ await db.insert('docs', {
120
120
  vector: [0.1, 0.2, ...], // or Float32Array
121
121
  payload: { key: 'value' } // optional metadata
122
122
  });
123
+
124
+ // REST backend note:
125
+ // IDs must be numeric and within JS safe integer range (0..Number.MAX_SAFE_INTEGER).
126
+ // Non-numeric strings are rejected.
123
127
  ```
124
128
 
125
129
  ### `db.insertBatch(collection, documents)`
@@ -189,6 +193,12 @@ const results = await db.query(
189
193
  "SELECT * FROM docs WHERE VECTOR NEAR $v AND content MATCH 'rust' LIMIT 10",
190
194
  { v: queryVector }
191
195
  );
196
+
197
+ // Aggregation query (returns { result, stats })
198
+ const agg = await db.query(
199
+ 'documents',
200
+ "SELECT COUNT(*) AS total FROM documents"
201
+ );
192
202
  ```
193
203
 
194
204
  ### `db.multiQuerySearch(collection, vectors, options)` (v1.1.0+) ⭐ NEW
@@ -224,7 +234,7 @@ const results = await db.multiQuerySearch('docs', vectors, {
224
234
  });
225
235
  ```
226
236
 
227
- > **Note:** Multi-query fusion is only available with the REST backend.
237
+ > **Note:** WASM supports `rrf`, `average`, `maximum`. `weighted` is REST-only.
228
238
 
229
239
  ### `db.isEmpty(collection)` (v0.8.11+)
230
240
 
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,6 +76,17 @@ 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
92
  type FusionStrategy$1 = 'rrf' | 'average' | 'maximum' | 'weighted';
@@ -229,6 +246,68 @@ interface QueryResponse {
229
246
  /** Execution statistics */
230
247
  stats: QueryStats;
231
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
+ }
232
311
  /** Index type for property indexes */
233
312
  type IndexType = 'hash' | 'range';
234
313
  /** Index information */
@@ -295,7 +374,11 @@ interface IVelesDBBackend {
295
374
  filter?: Record<string, unknown>;
296
375
  }): Promise<SearchResult[]>;
297
376
  /** Execute VelesQL multi-model query (EPIC-031 US-011) */
298
- query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
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>;
299
382
  /** Multi-query fusion search */
300
383
  multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
301
384
  /** Check if collection is empty */
@@ -320,6 +403,10 @@ interface IVelesDBBackend {
320
403
  traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
321
404
  /** Get the in-degree and out-degree of a node */
322
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>;
323
410
  }
324
411
  /** Error types */
325
412
  declare class VelesDBError extends Error {
@@ -336,6 +423,10 @@ declare class ValidationError extends VelesDBError {
336
423
  declare class NotFoundError extends VelesDBError {
337
424
  constructor(resource: string);
338
425
  }
426
+ /** Thrown when stream insert receives 429 Too Many Requests (backpressure) */
427
+ declare class BackpressureError extends VelesDBError {
428
+ constructor(message?: string);
429
+ }
339
430
 
340
431
  /**
341
432
  * VelesDB Client - Unified interface for all backends
@@ -436,6 +527,7 @@ declare class VelesDB {
436
527
  */
437
528
  insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
438
529
  private validateDocument;
530
+ private validateRestPointId;
439
531
  /**
440
532
  * Search for similar vectors
441
533
  *
@@ -521,7 +613,7 @@ declare class VelesDB {
521
613
  * }
522
614
  * ```
523
615
  */
524
- query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
616
+ query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
525
617
  /**
526
618
  * Multi-query fusion search combining results from multiple query vectors
527
619
  *
@@ -549,7 +641,27 @@ declare class VelesDB {
549
641
  * });
550
642
  * ```
551
643
  */
644
+ queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
645
+ collectionSanity(collection: string): Promise<CollectionSanityResponse>;
552
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>;
553
665
  /**
554
666
  * Check if a collection is empty
555
667
  *
@@ -703,6 +815,9 @@ declare class WasmBackend implements IVelesDBBackend {
703
815
  init(): Promise<void>;
704
816
  isInitialized(): boolean;
705
817
  private ensureInitialized;
818
+ private normalizeIdString;
819
+ private canonicalPayloadKeyFromResultId;
820
+ private canonicalPayloadKey;
706
821
  createCollection(name: string, config: CollectionConfig): Promise<void>;
707
822
  deleteCollection(name: string): Promise<void>;
708
823
  getCollection(name: string): Promise<Collection | null>;
@@ -726,11 +841,14 @@ declare class WasmBackend implements IVelesDBBackend {
726
841
  vectorWeight?: number;
727
842
  filter?: Record<string, unknown>;
728
843
  }): Promise<SearchResult[]>;
729
- query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
844
+ query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryApiResponse>;
730
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>;
731
848
  isEmpty(collectionName: string): Promise<boolean>;
732
849
  flush(collectionName: string): Promise<void>;
733
850
  close(): Promise<void>;
851
+ private sparseVectorToArrays;
734
852
  private toNumericId;
735
853
  createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
736
854
  listIndexes(_collection: string): Promise<IndexInfo[]>;
@@ -740,6 +858,8 @@ declare class WasmBackend implements IVelesDBBackend {
740
858
  getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
741
859
  traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
742
860
  getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
861
+ trainPq(_collection: string, _options?: PqTrainOptions): Promise<string>;
862
+ streamInsert(_collection: string, _docs: VectorDocument[]): Promise<void>;
743
863
  }
744
864
 
745
865
  /**
@@ -769,6 +889,8 @@ declare class RestBackend implements IVelesDBBackend {
769
889
  * Returns bigint for large values, number for safe values.
770
890
  */
771
891
  private parseNodeId;
892
+ private parseRestPointId;
893
+ private isLikelyAggregationQuery;
772
894
  private request;
773
895
  createCollection(name: string, config: CollectionConfig): Promise<void>;
774
896
  deleteCollection(name: string): Promise<void>;
@@ -776,6 +898,7 @@ declare class RestBackend implements IVelesDBBackend {
776
898
  listCollections(): Promise<Collection[]>;
777
899
  insert(collection: string, doc: VectorDocument): Promise<void>;
778
900
  insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
901
+ private sparseVectorToRestFormat;
779
902
  search(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
780
903
  searchBatch(collection: string, searches: Array<{
781
904
  vector: number[] | Float32Array;
@@ -793,10 +916,14 @@ declare class RestBackend implements IVelesDBBackend {
793
916
  vectorWeight?: number;
794
917
  filter?: Record<string, unknown>;
795
918
  }): Promise<SearchResult[]>;
796
- query(collection: string, queryString: string, params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
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>;
797
922
  multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
798
923
  isEmpty(collection: string): Promise<boolean>;
799
924
  flush(collection: string): Promise<void>;
925
+ trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
926
+ streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
800
927
  close(): Promise<void>;
801
928
  createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
802
929
  listIndexes(collection: string): Promise<IndexInfo[]>;
@@ -998,4 +1125,4 @@ declare class VelesQLBuilder {
998
1125
  */
999
1126
  declare function velesql(): VelesQLBuilder;
1000
1127
 
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 };
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 };
package/dist/index.d.ts 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,6 +76,17 @@ 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
92
  type FusionStrategy$1 = 'rrf' | 'average' | 'maximum' | 'weighted';
@@ -229,6 +246,68 @@ interface QueryResponse {
229
246
  /** Execution statistics */
230
247
  stats: QueryStats;
231
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
+ }
232
311
  /** Index type for property indexes */
233
312
  type IndexType = 'hash' | 'range';
234
313
  /** Index information */
@@ -295,7 +374,11 @@ interface IVelesDBBackend {
295
374
  filter?: Record<string, unknown>;
296
375
  }): Promise<SearchResult[]>;
297
376
  /** Execute VelesQL multi-model query (EPIC-031 US-011) */
298
- query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
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>;
299
382
  /** Multi-query fusion search */
300
383
  multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
301
384
  /** Check if collection is empty */
@@ -320,6 +403,10 @@ interface IVelesDBBackend {
320
403
  traverseGraph(collection: string, request: TraverseRequest): Promise<TraverseResponse>;
321
404
  /** Get the in-degree and out-degree of a node */
322
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>;
323
410
  }
324
411
  /** Error types */
325
412
  declare class VelesDBError extends Error {
@@ -336,6 +423,10 @@ declare class ValidationError extends VelesDBError {
336
423
  declare class NotFoundError extends VelesDBError {
337
424
  constructor(resource: string);
338
425
  }
426
+ /** Thrown when stream insert receives 429 Too Many Requests (backpressure) */
427
+ declare class BackpressureError extends VelesDBError {
428
+ constructor(message?: string);
429
+ }
339
430
 
340
431
  /**
341
432
  * VelesDB Client - Unified interface for all backends
@@ -436,6 +527,7 @@ declare class VelesDB {
436
527
  */
437
528
  insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
438
529
  private validateDocument;
530
+ private validateRestPointId;
439
531
  /**
440
532
  * Search for similar vectors
441
533
  *
@@ -521,7 +613,7 @@ declare class VelesDB {
521
613
  * }
522
614
  * ```
523
615
  */
524
- query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryResponse>;
616
+ query(collection: string, queryString: string, params?: Record<string, unknown>, options?: QueryOptions): Promise<QueryApiResponse>;
525
617
  /**
526
618
  * Multi-query fusion search combining results from multiple query vectors
527
619
  *
@@ -549,7 +641,27 @@ declare class VelesDB {
549
641
  * });
550
642
  * ```
551
643
  */
644
+ queryExplain(queryString: string, params?: Record<string, unknown>): Promise<ExplainResponse>;
645
+ collectionSanity(collection: string): Promise<CollectionSanityResponse>;
552
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>;
553
665
  /**
554
666
  * Check if a collection is empty
555
667
  *
@@ -703,6 +815,9 @@ declare class WasmBackend implements IVelesDBBackend {
703
815
  init(): Promise<void>;
704
816
  isInitialized(): boolean;
705
817
  private ensureInitialized;
818
+ private normalizeIdString;
819
+ private canonicalPayloadKeyFromResultId;
820
+ private canonicalPayloadKey;
706
821
  createCollection(name: string, config: CollectionConfig): Promise<void>;
707
822
  deleteCollection(name: string): Promise<void>;
708
823
  getCollection(name: string): Promise<Collection | null>;
@@ -726,11 +841,14 @@ declare class WasmBackend implements IVelesDBBackend {
726
841
  vectorWeight?: number;
727
842
  filter?: Record<string, unknown>;
728
843
  }): Promise<SearchResult[]>;
729
- query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
844
+ query(_collection: string, _queryString: string, _params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryApiResponse>;
730
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>;
731
848
  isEmpty(collectionName: string): Promise<boolean>;
732
849
  flush(collectionName: string): Promise<void>;
733
850
  close(): Promise<void>;
851
+ private sparseVectorToArrays;
734
852
  private toNumericId;
735
853
  createIndex(_collection: string, _options: CreateIndexOptions): Promise<void>;
736
854
  listIndexes(_collection: string): Promise<IndexInfo[]>;
@@ -740,6 +858,8 @@ declare class WasmBackend implements IVelesDBBackend {
740
858
  getEdges(_collection: string, _options?: GetEdgesOptions): Promise<GraphEdge[]>;
741
859
  traverseGraph(_collection: string, _request: TraverseRequest): Promise<TraverseResponse>;
742
860
  getNodeDegree(_collection: string, _nodeId: number): Promise<DegreeResponse>;
861
+ trainPq(_collection: string, _options?: PqTrainOptions): Promise<string>;
862
+ streamInsert(_collection: string, _docs: VectorDocument[]): Promise<void>;
743
863
  }
744
864
 
745
865
  /**
@@ -769,6 +889,8 @@ declare class RestBackend implements IVelesDBBackend {
769
889
  * Returns bigint for large values, number for safe values.
770
890
  */
771
891
  private parseNodeId;
892
+ private parseRestPointId;
893
+ private isLikelyAggregationQuery;
772
894
  private request;
773
895
  createCollection(name: string, config: CollectionConfig): Promise<void>;
774
896
  deleteCollection(name: string): Promise<void>;
@@ -776,6 +898,7 @@ declare class RestBackend implements IVelesDBBackend {
776
898
  listCollections(): Promise<Collection[]>;
777
899
  insert(collection: string, doc: VectorDocument): Promise<void>;
778
900
  insertBatch(collection: string, docs: VectorDocument[]): Promise<void>;
901
+ private sparseVectorToRestFormat;
779
902
  search(collection: string, query: number[] | Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
780
903
  searchBatch(collection: string, searches: Array<{
781
904
  vector: number[] | Float32Array;
@@ -793,10 +916,14 @@ declare class RestBackend implements IVelesDBBackend {
793
916
  vectorWeight?: number;
794
917
  filter?: Record<string, unknown>;
795
918
  }): Promise<SearchResult[]>;
796
- query(collection: string, queryString: string, params?: Record<string, unknown>, _options?: QueryOptions): Promise<QueryResponse>;
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>;
797
922
  multiQuerySearch(collection: string, vectors: Array<number[] | Float32Array>, options?: MultiQuerySearchOptions): Promise<SearchResult[]>;
798
923
  isEmpty(collection: string): Promise<boolean>;
799
924
  flush(collection: string): Promise<void>;
925
+ trainPq(collection: string, options?: PqTrainOptions): Promise<string>;
926
+ streamInsert(collection: string, docs: VectorDocument[]): Promise<void>;
800
927
  close(): Promise<void>;
801
928
  createIndex(collection: string, options: CreateIndexOptions): Promise<void>;
802
929
  listIndexes(collection: string): Promise<IndexInfo[]>;
@@ -998,4 +1125,4 @@ declare class VelesQLBuilder {
998
1125
  */
999
1126
  declare function velesql(): VelesQLBuilder;
1000
1127
 
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 };
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 };