@topgunbuild/core 0.8.0 → 0.9.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
@@ -1161,12 +1161,35 @@ declare function serialize(data: unknown): Uint8Array;
1161
1161
  */
1162
1162
  declare function deserialize<T = unknown>(data: Uint8Array | ArrayBuffer): T;
1163
1163
 
1164
- type PredicateOp = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'regex' | 'contains' | 'containsAll' | 'containsAny' | 'and' | 'or' | 'not';
1164
+ type PredicateOp = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'regex' | 'contains' | 'containsAll' | 'containsAny' | 'and' | 'or' | 'not' | 'match' | 'matchPhrase' | 'matchPrefix';
1165
+ /**
1166
+ * Options for full-text search match predicate.
1167
+ */
1168
+ interface MatchOptions {
1169
+ /** Minimum BM25 score threshold */
1170
+ minScore?: number;
1171
+ /** Boost factor for this field */
1172
+ boost?: number;
1173
+ /** Operator for multi-term queries: 'and' requires all terms, 'or' requires any */
1174
+ operator?: 'and' | 'or';
1175
+ /** Fuzziness level for typo tolerance (0 = exact, 1 = 1 edit, 2 = 2 edits) */
1176
+ fuzziness?: number;
1177
+ }
1165
1178
  interface PredicateNode {
1166
1179
  op: PredicateOp;
1167
1180
  attribute?: string;
1168
1181
  value?: any;
1169
1182
  children?: PredicateNode[];
1183
+ /** FTS-specific: search query string */
1184
+ query?: string;
1185
+ /** FTS-specific: match options */
1186
+ matchOptions?: MatchOptions;
1187
+ /** FTS-specific: phrase slop (word distance tolerance) */
1188
+ slop?: number;
1189
+ /** FTS-specific: prefix for matchPrefix */
1190
+ prefix?: string;
1191
+ /** FTS-specific: max prefix expansions */
1192
+ maxExpansions?: number;
1170
1193
  }
1171
1194
  declare class Predicates {
1172
1195
  static equal(attribute: string, value: any): PredicateNode;
@@ -1205,6 +1228,82 @@ declare class Predicates {
1205
1228
  * @param values - Text values, any of which can match
1206
1229
  */
1207
1230
  static containsAny(attribute: string, values: string[]): PredicateNode;
1231
+ /**
1232
+ * Create a 'match' predicate for full-text search.
1233
+ * Uses BM25 scoring to find relevant documents.
1234
+ *
1235
+ * @param attribute - Field to search in
1236
+ * @param query - Search query string
1237
+ * @param options - Match options (minScore, boost, operator, fuzziness)
1238
+ *
1239
+ * @example
1240
+ * ```typescript
1241
+ * // Simple match
1242
+ * Predicates.match('title', 'machine learning')
1243
+ *
1244
+ * // With options
1245
+ * Predicates.match('body', 'neural networks', { minScore: 1.0, boost: 2.0 })
1246
+ * ```
1247
+ */
1248
+ static match(attribute: string, query: string, options?: MatchOptions): PredicateNode;
1249
+ /**
1250
+ * Create a 'matchPhrase' predicate for exact phrase matching.
1251
+ * Matches documents containing the exact phrase (words in order).
1252
+ *
1253
+ * @param attribute - Field to search in
1254
+ * @param query - Phrase to match
1255
+ * @param slop - Word distance tolerance (0 = exact, 1 = allow 1 word between)
1256
+ *
1257
+ * @example
1258
+ * ```typescript
1259
+ * // Exact phrase
1260
+ * Predicates.matchPhrase('body', 'machine learning')
1261
+ *
1262
+ * // With slop (allows "machine deep learning")
1263
+ * Predicates.matchPhrase('body', 'machine learning', 1)
1264
+ * ```
1265
+ */
1266
+ static matchPhrase(attribute: string, query: string, slop?: number): PredicateNode;
1267
+ /**
1268
+ * Create a 'matchPrefix' predicate for prefix matching.
1269
+ * Matches documents where field starts with the given prefix.
1270
+ *
1271
+ * @param attribute - Field to search in
1272
+ * @param prefix - Prefix to match
1273
+ * @param maxExpansions - Maximum number of term expansions
1274
+ *
1275
+ * @example
1276
+ * ```typescript
1277
+ * // Match titles starting with "mach"
1278
+ * Predicates.matchPrefix('title', 'mach')
1279
+ *
1280
+ * // Limit expansions for performance
1281
+ * Predicates.matchPrefix('title', 'mach', 50)
1282
+ * ```
1283
+ */
1284
+ static matchPrefix(attribute: string, prefix: string, maxExpansions?: number): PredicateNode;
1285
+ /**
1286
+ * Create a multi-field match predicate.
1287
+ * Searches across multiple fields with optional per-field boosting.
1288
+ *
1289
+ * @param attributes - Fields to search in
1290
+ * @param query - Search query string
1291
+ * @param options - Options including per-field boost factors
1292
+ *
1293
+ * @example
1294
+ * ```typescript
1295
+ * // Search title and body
1296
+ * Predicates.multiMatch(['title', 'body'], 'machine learning')
1297
+ *
1298
+ * // With boosting (title 2x more important)
1299
+ * Predicates.multiMatch(['title', 'body'], 'machine learning', {
1300
+ * boost: { title: 2.0, body: 1.0 }
1301
+ * })
1302
+ * ```
1303
+ */
1304
+ static multiMatch(attributes: string[], query: string, options?: {
1305
+ boost?: Record<string, number>;
1306
+ }): PredicateNode;
1208
1307
  }
1209
1308
  declare function evaluatePredicate(predicate: PredicateNode, data: any): boolean;
1210
1309
 
@@ -3767,6 +3866,52 @@ interface SimpleQueryNode extends QueryNode {
3767
3866
  /** For 'between' queries: include upper bound (default: false) */
3768
3867
  toInclusive?: boolean;
3769
3868
  }
3869
+ /**
3870
+ * Options for full-text search match queries.
3871
+ */
3872
+ interface MatchQueryOptions {
3873
+ /** Minimum BM25 score threshold */
3874
+ minScore?: number;
3875
+ /** Boost factor for this field */
3876
+ boost?: number;
3877
+ /** Operator for multi-term queries: 'and' requires all terms, 'or' requires any */
3878
+ operator?: 'and' | 'or';
3879
+ /** Fuzziness level for typo tolerance (0 = exact, 1 = 1 edit, 2 = 2 edits) */
3880
+ fuzziness?: number;
3881
+ }
3882
+ /**
3883
+ * Match query node for BM25 full-text search.
3884
+ */
3885
+ interface MatchQueryNode extends QueryNode {
3886
+ type: 'match';
3887
+ attribute: string;
3888
+ query: string;
3889
+ options?: MatchQueryOptions;
3890
+ }
3891
+ /**
3892
+ * Match phrase query node for exact phrase matching.
3893
+ */
3894
+ interface MatchPhraseQueryNode extends QueryNode {
3895
+ type: 'matchPhrase';
3896
+ attribute: string;
3897
+ query: string;
3898
+ /** Word distance tolerance (0 = exact phrase) */
3899
+ slop?: number;
3900
+ }
3901
+ /**
3902
+ * Match prefix query node for prefix matching.
3903
+ */
3904
+ interface MatchPrefixQueryNode extends QueryNode {
3905
+ type: 'matchPrefix';
3906
+ attribute: string;
3907
+ prefix: string;
3908
+ /** Maximum number of term expansions */
3909
+ maxExpansions?: number;
3910
+ }
3911
+ /**
3912
+ * Union type for FTS query nodes.
3913
+ */
3914
+ type FTSQueryNode = MatchQueryNode | MatchPhraseQueryNode | MatchPrefixQueryNode;
3770
3915
  /**
3771
3916
  * Logical query node for combining conditions.
3772
3917
  */
@@ -3778,7 +3923,7 @@ interface LogicalQueryNode {
3778
3923
  /**
3779
3924
  * Union type for all query types.
3780
3925
  */
3781
- type Query = SimpleQueryNode | LogicalQueryNode;
3926
+ type Query = SimpleQueryNode | LogicalQueryNode | FTSQueryNode;
3782
3927
  /**
3783
3928
  * Query execution options for sort/limit/offset.
3784
3929
  */
@@ -3794,7 +3939,7 @@ interface QueryOptions {
3794
3939
  * Execution plan step.
3795
3940
  * Represents a single operation in the query execution plan.
3796
3941
  */
3797
- type PlanStep = IndexScanStep | FullScanStep | IntersectionStep | UnionStep | FilterStep | NotStep;
3942
+ type PlanStep = IndexScanStep | FullScanStep | IntersectionStep | UnionStep | FilterStep | NotStep | FTSScanStep | FusionStep;
3798
3943
  /**
3799
3944
  * Index scan step - retrieves from an index.
3800
3945
  */
@@ -3840,6 +3985,41 @@ interface NotStep {
3840
3985
  source: PlanStep;
3841
3986
  allKeys: () => Set<unknown>;
3842
3987
  }
3988
+ /**
3989
+ * Fusion strategy for combining results from different search methods.
3990
+ */
3991
+ type FusionStrategy = 'intersection' | 'rrf' | 'score-filter';
3992
+ /**
3993
+ * FTS scan step - full-text search using FullTextIndex.
3994
+ * Returns scored results (documents with BM25 scores).
3995
+ */
3996
+ interface FTSScanStep {
3997
+ type: 'fts-scan';
3998
+ /** Field to search */
3999
+ field: string;
4000
+ /** Search query or phrase */
4001
+ query: string;
4002
+ /** Type of FTS query */
4003
+ ftsType: 'match' | 'matchPhrase' | 'matchPrefix';
4004
+ /** Query options (minScore, boost, etc.) */
4005
+ options?: MatchQueryOptions;
4006
+ /** This step returns scored results */
4007
+ returnsScored: true;
4008
+ /** Estimated cost */
4009
+ estimatedCost: number;
4010
+ }
4011
+ /**
4012
+ * Fusion step - combines results from multiple steps using RRF or other strategy.
4013
+ */
4014
+ interface FusionStep {
4015
+ type: 'fusion';
4016
+ /** Steps to combine */
4017
+ steps: PlanStep[];
4018
+ /** Fusion strategy */
4019
+ strategy: FusionStrategy;
4020
+ /** Whether result is scored (true if any child is scored) */
4021
+ returnsScored: boolean;
4022
+ }
3843
4023
  /**
3844
4024
  * Complete query execution plan.
3845
4025
  */
@@ -4939,160 +5119,764 @@ declare class LazyInvertedIndex<K, V, A extends string = string> implements Lazy
4939
5119
  }
4940
5120
 
4941
5121
  /**
4942
- * SetResultSet Implementation
4943
- *
4944
- * ResultSet backed by a Set, used for HashIndex results.
4945
- *
4946
- * @module query/resultset/SetResultSet
4947
- */
4948
-
4949
- /**
4950
- * ResultSet backed by a Set.
4951
- * Provides O(1) contains() check and direct iteration.
4952
- */
4953
- declare class SetResultSet<K> implements ResultSet<K> {
4954
- private readonly keys;
4955
- private readonly retrievalCost;
4956
- constructor(keys: Set<K>, retrievalCost: number);
4957
- [Symbol.iterator](): Iterator<K>;
4958
- getRetrievalCost(): number;
4959
- getMergeCost(): number;
4960
- contains(key: K): boolean;
4961
- size(): number;
4962
- toArray(): K[];
4963
- isEmpty(): boolean;
4964
- }
4965
-
4966
- /**
4967
- * LazyResultSet Implementation
5122
+ * Full-Text Search Types
4968
5123
  *
4969
- * Lazily evaluated result set for range queries.
4970
- * Used when materializing all results upfront would be expensive.
5124
+ * Type definitions for the FTS (Full-Text Search) module.
5125
+ * This module provides BM25-based keyword search capabilities.
4971
5126
  *
4972
- * @module query/resultset/LazyResultSet
4973
- */
4974
-
4975
- /**
4976
- * Factory function type that creates a generator for lazy iteration.
5127
+ * @module fts/types
4977
5128
  */
4978
- type IteratorFactory<K> = () => Generator<K>;
4979
5129
  /**
4980
- * Lazily evaluated result set.
4981
- * Used for range queries where materializing all results upfront is expensive.
4982
- *
4983
- * K = record key type
5130
+ * Options for configuring the FTS Tokenizer.
4984
5131
  */
4985
- declare class LazyResultSet<K> implements ResultSet<K> {
4986
- private readonly iteratorFactory;
4987
- private readonly retrievalCost;
4988
- private readonly estimatedSize;
4989
- /** Cached materialized results */
4990
- private cached;
5132
+ interface TokenizerOptions {
4991
5133
  /**
4992
- * Create a LazyResultSet.
4993
- *
4994
- * @param iteratorFactory - Factory that creates a fresh generator each time
4995
- * @param retrievalCost - Cost of retrieving results from the index
4996
- * @param estimatedSize - Estimated result count for merge cost calculation
5134
+ * Convert all text to lowercase before tokenization.
5135
+ * @default true
4997
5136
  */
4998
- constructor(iteratorFactory: IteratorFactory<K>, retrievalCost: number, estimatedSize: number);
4999
- [Symbol.iterator](): Generator<K>;
5000
- getRetrievalCost(): number;
5001
- getMergeCost(): number;
5002
- contains(key: K): boolean;
5003
- size(): number;
5004
- toArray(): K[];
5005
- isEmpty(): boolean;
5137
+ lowercase?: boolean;
5006
5138
  /**
5007
- * Check if the result set has been materialized.
5008
- * Useful for testing lazy evaluation behavior.
5139
+ * Set of words to exclude from tokenization (e.g., "the", "and", "is").
5140
+ * @default ENGLISH_STOPWORDS (174 words)
5009
5141
  */
5010
- isMaterialized(): boolean;
5142
+ stopwords?: Set<string>;
5011
5143
  /**
5012
- * Force materialization of the result set.
5013
- * Returns the cached array.
5144
+ * Function to reduce words to their root form.
5145
+ * @default Porter stemmer
5014
5146
  */
5015
- materialize(): K[];
5147
+ stemmer?: (word: string) => string;
5016
5148
  /**
5017
- * Get the estimated size before materialization.
5149
+ * Minimum token length to include in results.
5150
+ * @default 2
5018
5151
  */
5019
- getEstimatedSize(): number;
5152
+ minLength?: number;
5153
+ /**
5154
+ * Maximum token length to include in results.
5155
+ * @default 40
5156
+ */
5157
+ maxLength?: number;
5020
5158
  }
5021
-
5022
5159
  /**
5023
- * IntersectionResultSet Implementation
5024
- *
5025
- * Intersection of multiple result sets (AND logic).
5026
- * Implements CQEngine "smallest first" strategy:
5027
- * iterate the smallest set, check membership in others.
5028
- *
5029
- * @module query/resultset/IntersectionResultSet
5160
+ * Information about a term's occurrence in a document.
5030
5161
  */
5031
-
5162
+ interface TermInfo {
5163
+ /** Document ID where the term appears */
5164
+ docId: string;
5165
+ /** Number of times the term appears in the document */
5166
+ termFrequency: number;
5167
+ /** Optional: positions of the term for phrase search (future) */
5168
+ fieldPositions?: number[];
5169
+ }
5032
5170
  /**
5033
- * Intersection of multiple result sets (AND logic).
5034
- * CQEngine strategy: iterate smallest set, check membership in others.
5035
- *
5036
- * K = record key type
5171
+ * Posting list entry for the inverted index.
5037
5172
  */
5038
- declare class IntersectionResultSet<K> implements ResultSet<K> {
5039
- /** Cached materialized results */
5040
- private cached;
5041
- /** Result sets sorted by merge cost */
5042
- private sortedResultSets;
5043
- /**
5044
- * Create an IntersectionResultSet.
5045
- *
5046
- * @param resultSets - Result sets to intersect
5047
- */
5048
- constructor(resultSets: ResultSet<K>[]);
5049
- /**
5050
- * Lazy iteration over intersection.
5051
- * Iterates smallest set, yields only keys present in all sets.
5052
- */
5053
- [Symbol.iterator](): Generator<K>;
5054
- /**
5055
- * Retrieval cost is minimum of all (we only iterate smallest).
5056
- */
5057
- getRetrievalCost(): number;
5058
- /**
5059
- * Merge cost is estimated as smallest set size (upper bound).
5060
- */
5061
- getMergeCost(): number;
5062
- /**
5063
- * Check if key is in all result sets.
5064
- */
5065
- contains(key: K): boolean;
5066
- /**
5067
- * Get size by materializing results.
5068
- */
5069
- size(): number;
5070
- /**
5071
- * Materialize to array with caching.
5072
- */
5073
- toArray(): K[];
5173
+ interface Posting {
5174
+ /** Document ID */
5175
+ docId: string;
5176
+ /** Term frequency in this document */
5177
+ termFrequency: number;
5178
+ /** Optional: positions for phrase search */
5179
+ positions?: number[];
5180
+ }
5181
+ /**
5182
+ * BM25 algorithm configuration options.
5183
+ */
5184
+ interface BM25Options {
5074
5185
  /**
5075
- * Check if empty (tries to avoid full materialization).
5186
+ * Term frequency saturation parameter.
5187
+ * Higher values give more weight to repeated terms.
5188
+ * @default 1.2
5076
5189
  */
5077
- isEmpty(): boolean;
5190
+ k1?: number;
5078
5191
  /**
5079
- * Check if results have been materialized.
5192
+ * Document length normalization parameter.
5193
+ * 0 = no length normalization, 1 = full normalization.
5194
+ * @default 0.75
5080
5195
  */
5081
- isMaterialized(): boolean;
5196
+ b?: number;
5082
5197
  }
5083
-
5084
5198
  /**
5085
- * UnionResultSet Implementation
5086
- *
5087
- * Union of multiple result sets (OR logic).
5088
- * Deduplicates results using a Set during iteration.
5089
- *
5090
- * @module query/resultset/UnionResultSet
5199
+ * A document with its BM25 relevance score.
5091
5200
  */
5092
-
5201
+ interface ScoredDocument {
5202
+ /** Document ID */
5203
+ docId: string;
5204
+ /** BM25 relevance score */
5205
+ score: number;
5206
+ /** Terms from the query that matched this document */
5207
+ matchedTerms: string[];
5208
+ }
5093
5209
  /**
5094
- * Union of multiple result sets (OR logic).
5095
- * Deduplicates results.
5210
+ * Configuration for a FullTextIndex.
5211
+ */
5212
+ interface FullTextIndexConfig {
5213
+ /** Fields to index for full-text search (e.g., ['title', 'body']) */
5214
+ fields: string[];
5215
+ /** Tokenizer configuration */
5216
+ tokenizer?: TokenizerOptions;
5217
+ /** BM25 scoring parameters */
5218
+ bm25?: BM25Options;
5219
+ }
5220
+ /**
5221
+ * Options for search queries.
5222
+ */
5223
+ interface SearchOptions {
5224
+ /** Maximum number of results to return */
5225
+ limit?: number;
5226
+ /** Minimum BM25 score threshold */
5227
+ minScore?: number;
5228
+ /** Restrict search to specific fields */
5229
+ fields?: string[];
5230
+ /** Field boost weights (e.g., { title: 2.0, body: 1.0 }) */
5231
+ boost?: Record<string, number>;
5232
+ }
5233
+ /**
5234
+ * Search result with full details.
5235
+ */
5236
+ interface SearchResult {
5237
+ /** Document ID */
5238
+ docId: string;
5239
+ /** BM25 relevance score */
5240
+ score: number;
5241
+ /** Source of the match (for hybrid search) */
5242
+ source?: 'exact' | 'fulltext' | 'vector' | 'bfs';
5243
+ /** Original document data (if requested) */
5244
+ data?: unknown;
5245
+ /** Highlighted text snippet (if requested) */
5246
+ highlightedText?: string;
5247
+ /** Terms that matched */
5248
+ matchedTerms?: string[];
5249
+ /** Document embedding (if available) */
5250
+ embedding?: number[];
5251
+ /** Cosine similarity to query (0-1) */
5252
+ embeddingSimilarity?: number;
5253
+ /** Debug information */
5254
+ debug?: {
5255
+ exactScore?: number;
5256
+ fulltextScore?: number;
5257
+ vectorScore?: number;
5258
+ rangeScore?: number;
5259
+ };
5260
+ }
5261
+ /**
5262
+ * Serialized format for index persistence.
5263
+ */
5264
+ interface SerializedIndex {
5265
+ /** Schema version for backwards compatibility */
5266
+ version: number;
5267
+ /** Index metadata */
5268
+ metadata: {
5269
+ totalDocs: number;
5270
+ avgDocLength: number;
5271
+ createdAt: number;
5272
+ lastModified: number;
5273
+ };
5274
+ /** Serialized term data */
5275
+ terms: Array<{
5276
+ term: string;
5277
+ idf: number;
5278
+ postings: Array<{
5279
+ docId: string;
5280
+ termFrequency: number;
5281
+ positions?: number[];
5282
+ }>;
5283
+ }>;
5284
+ /** Document lengths for BM25 normalization */
5285
+ docLengths: Record<string, number>;
5286
+ }
5287
+
5288
+ /**
5289
+ * English stopwords list (174 common words).
5290
+ * These words are filtered out during tokenization as they
5291
+ * don't contribute to search relevance.
5292
+ */
5293
+ declare const ENGLISH_STOPWORDS: Set<string>;
5294
+
5295
+ /**
5296
+ * Porter Stemming Algorithm
5297
+ *
5298
+ * Reduces English words to their stem (root form).
5299
+ * Based on the algorithm by Martin Porter (1980).
5300
+ *
5301
+ * @see https://tartarus.org/martin/PorterStemmer/
5302
+ *
5303
+ * @param word - Word to stem (should be lowercase)
5304
+ * @returns Stemmed word
5305
+ */
5306
+ declare function porterStem(word: string): string;
5307
+
5308
+ /**
5309
+ * FTS Tokenizer with Porter Stemming and Stopwords
5310
+ *
5311
+ * Provides text tokenization for BM25 full-text search.
5312
+ * Features:
5313
+ * - Unicode-aware word boundary detection
5314
+ * - English stopwords filtering (174 words)
5315
+ * - Porter stemming algorithm for word normalization
5316
+ * - Configurable min/max token length
5317
+ *
5318
+ * @module fts/Tokenizer
5319
+ */
5320
+
5321
+ /**
5322
+ * FTS Tokenizer
5323
+ *
5324
+ * Splits text into searchable tokens with normalization.
5325
+ *
5326
+ * @example
5327
+ * ```typescript
5328
+ * const tokenizer = new BM25Tokenizer();
5329
+ * const tokens = tokenizer.tokenize('The quick brown foxes');
5330
+ * // ['quick', 'brown', 'fox']
5331
+ * ```
5332
+ */
5333
+ declare class BM25Tokenizer implements Tokenizer {
5334
+ private readonly options;
5335
+ /**
5336
+ * Create a new BM25Tokenizer.
5337
+ *
5338
+ * @param options - Configuration options
5339
+ */
5340
+ constructor(options?: TokenizerOptions);
5341
+ /**
5342
+ * Tokenize text into an array of normalized tokens.
5343
+ *
5344
+ * @param text - Text to tokenize
5345
+ * @returns Array of tokens
5346
+ */
5347
+ tokenize(text: string): string[];
5348
+ }
5349
+
5350
+ /**
5351
+ * FTS Inverted Index
5352
+ *
5353
+ * Data structure for full-text search that maps terms to documents.
5354
+ * Supports efficient term lookup, document frequency calculation,
5355
+ * and IDF (Inverse Document Frequency) for BM25 scoring.
5356
+ *
5357
+ * @module fts/BM25InvertedIndex
5358
+ */
5359
+
5360
+ /**
5361
+ * Inverted Index for Full-Text Search (BM25)
5362
+ *
5363
+ * Maps terms to the documents containing them, along with term frequency
5364
+ * information needed for BM25 scoring.
5365
+ *
5366
+ * @example
5367
+ * ```typescript
5368
+ * const index = new BM25InvertedIndex();
5369
+ * index.addDocument('doc1', ['hello', 'world']);
5370
+ * index.addDocument('doc2', ['hello', 'there']);
5371
+ *
5372
+ * const docs = index.getDocumentsForTerm('hello');
5373
+ * // [{ docId: 'doc1', termFrequency: 1 }, { docId: 'doc2', termFrequency: 1 }]
5374
+ * ```
5375
+ */
5376
+ declare class BM25InvertedIndex {
5377
+ /** term → list of documents containing term */
5378
+ private index;
5379
+ /** document → total term count (for length normalization) */
5380
+ private docLengths;
5381
+ /** document → set of terms (for efficient removal) */
5382
+ private docTerms;
5383
+ /** Inverse Document Frequency cache */
5384
+ private idfCache;
5385
+ /** Total number of documents */
5386
+ private totalDocs;
5387
+ /** Average document length */
5388
+ private avgDocLength;
5389
+ constructor();
5390
+ /**
5391
+ * Add a document to the index.
5392
+ *
5393
+ * @param docId - Unique document identifier
5394
+ * @param tokens - Array of tokens (already tokenized/stemmed)
5395
+ */
5396
+ addDocument(docId: string, tokens: string[]): void;
5397
+ /**
5398
+ * Remove a document from the index.
5399
+ *
5400
+ * @param docId - Document identifier to remove
5401
+ */
5402
+ removeDocument(docId: string): void;
5403
+ /**
5404
+ * Get all documents containing a term.
5405
+ *
5406
+ * @param term - Term to look up
5407
+ * @returns Array of TermInfo objects
5408
+ */
5409
+ getDocumentsForTerm(term: string): TermInfo[];
5410
+ /**
5411
+ * Calculate IDF (Inverse Document Frequency) for a term.
5412
+ *
5413
+ * Uses BM25 IDF formula:
5414
+ * IDF = log((N - df + 0.5) / (df + 0.5) + 1)
5415
+ *
5416
+ * Where:
5417
+ * - N = total documents
5418
+ * - df = document frequency (docs containing term)
5419
+ *
5420
+ * @param term - Term to calculate IDF for
5421
+ * @returns IDF value (0 if term doesn't exist)
5422
+ */
5423
+ getIDF(term: string): number;
5424
+ /**
5425
+ * Get the length of a document (number of tokens).
5426
+ *
5427
+ * @param docId - Document identifier
5428
+ * @returns Document length (0 if not found)
5429
+ */
5430
+ getDocLength(docId: string): number;
5431
+ /**
5432
+ * Get the average document length.
5433
+ *
5434
+ * @returns Average length across all documents
5435
+ */
5436
+ getAvgDocLength(): number;
5437
+ /**
5438
+ * Get the total number of documents in the index.
5439
+ *
5440
+ * @returns Total document count
5441
+ */
5442
+ getTotalDocs(): number;
5443
+ /**
5444
+ * Get iterator for document lengths (useful for serialization).
5445
+ *
5446
+ * @returns Iterator of [docId, length] pairs
5447
+ */
5448
+ getDocLengths(): IterableIterator<[string, number]>;
5449
+ /**
5450
+ * Get the number of documents in the index (alias for getTotalDocs).
5451
+ *
5452
+ * @returns Number of indexed documents
5453
+ */
5454
+ getSize(): number;
5455
+ /**
5456
+ * Clear all data from the index.
5457
+ */
5458
+ clear(): void;
5459
+ /**
5460
+ * Check if a document exists in the index.
5461
+ *
5462
+ * @param docId - Document identifier
5463
+ * @returns True if document exists
5464
+ */
5465
+ hasDocument(docId: string): boolean;
5466
+ /**
5467
+ * Get all unique terms in the index.
5468
+ *
5469
+ * @returns Iterator of all terms
5470
+ */
5471
+ getTerms(): IterableIterator<string>;
5472
+ /**
5473
+ * Get the number of unique terms in the index.
5474
+ *
5475
+ * @returns Number of unique terms
5476
+ */
5477
+ getTermCount(): number;
5478
+ /**
5479
+ * Update the average document length after add/remove.
5480
+ */
5481
+ private updateAvgDocLength;
5482
+ }
5483
+
5484
+ /**
5485
+ * BM25 Scorer
5486
+ *
5487
+ * Implements the Okapi BM25 ranking algorithm for full-text search.
5488
+ * BM25 is a probabilistic relevance ranking function used to estimate
5489
+ * the relevance of documents to a given search query.
5490
+ *
5491
+ * @see https://en.wikipedia.org/wiki/Okapi_BM25
5492
+ * @module fts/BM25Scorer
5493
+ */
5494
+
5495
+ /**
5496
+ * BM25 Scorer for relevance ranking
5497
+ *
5498
+ * The BM25 formula:
5499
+ * score(D,Q) = Σ IDF(qi) × (f(qi,D) × (k1 + 1)) / (f(qi,D) + k1 × (1 - b + b × |D| / avgdl))
5500
+ *
5501
+ * Where:
5502
+ * - D = document
5503
+ * - Q = query
5504
+ * - qi = query term i
5505
+ * - f(qi,D) = term frequency of qi in D
5506
+ * - |D| = length of D (number of terms)
5507
+ * - avgdl = average document length
5508
+ * - k1 = term frequency saturation parameter (default: 1.2)
5509
+ * - b = document length normalization parameter (default: 0.75)
5510
+ *
5511
+ * @example
5512
+ * ```typescript
5513
+ * const index = new BM25InvertedIndex();
5514
+ * index.addDocument('doc1', ['hello', 'world']);
5515
+ * index.addDocument('doc2', ['hello', 'there']);
5516
+ *
5517
+ * const scorer = new BM25Scorer();
5518
+ * const results = scorer.score(['hello'], index);
5519
+ * // [{ docId: 'doc1', score: 0.28, matchedTerms: ['hello'] }, ...]
5520
+ * ```
5521
+ */
5522
+ declare class BM25Scorer {
5523
+ /**
5524
+ * Term frequency saturation parameter.
5525
+ * Higher values give more weight to repeated terms.
5526
+ * Typical range: 1.2 - 2.0
5527
+ */
5528
+ private readonly k1;
5529
+ /**
5530
+ * Document length normalization parameter.
5531
+ * 0 = no length normalization
5532
+ * 1 = full length normalization
5533
+ * Typical value: 0.75
5534
+ */
5535
+ private readonly b;
5536
+ /**
5537
+ * Create a new BM25 scorer.
5538
+ *
5539
+ * @param options - BM25 configuration options
5540
+ */
5541
+ constructor(options?: BM25Options);
5542
+ /**
5543
+ * Score documents against a query.
5544
+ *
5545
+ * @param queryTerms - Array of query terms (already tokenized/stemmed)
5546
+ * @param index - The inverted index to search
5547
+ * @returns Array of scored documents, sorted by relevance (descending)
5548
+ */
5549
+ score(queryTerms: string[], index: BM25InvertedIndex): ScoredDocument[];
5550
+ /**
5551
+ * Score a single document against query terms.
5552
+ * Uses pre-computed IDF from index but calculates TF locally.
5553
+ *
5554
+ * Complexity: O(Q × D) where Q = query terms, D = document tokens
5555
+ *
5556
+ * @param queryTerms - Tokenized query terms
5557
+ * @param docTokens - Tokenized document terms
5558
+ * @param index - Inverted index for IDF and avgDocLength
5559
+ * @returns BM25 score (0 if no matching terms)
5560
+ */
5561
+ scoreSingleDocument(queryTerms: string[], docTokens: string[], index: BM25InvertedIndex): number;
5562
+ /**
5563
+ * Get the k1 parameter value.
5564
+ */
5565
+ getK1(): number;
5566
+ /**
5567
+ * Get the b parameter value.
5568
+ */
5569
+ getB(): number;
5570
+ }
5571
+
5572
+ /**
5573
+ * Full-Text Index
5574
+ *
5575
+ * High-level integration class that combines Tokenizer, InvertedIndex,
5576
+ * and BM25Scorer for complete full-text search functionality.
5577
+ * Designed to integrate with TopGun's CRDT maps.
5578
+ *
5579
+ * @module fts/FullTextIndex
5580
+ */
5581
+
5582
+ /**
5583
+ * Full-Text Index for TopGun
5584
+ *
5585
+ * Provides BM25-based full-text search across document fields.
5586
+ * Supports incremental updates (add/update/remove) for real-time sync.
5587
+ *
5588
+ * @example
5589
+ * ```typescript
5590
+ * const index = new FullTextIndex({
5591
+ * fields: ['title', 'body'],
5592
+ * tokenizer: { minLength: 2 },
5593
+ * bm25: { k1: 1.2, b: 0.75 }
5594
+ * });
5595
+ *
5596
+ * index.onSet('doc1', { title: 'Hello World', body: 'Test content' });
5597
+ * const results = index.search('hello');
5598
+ * // [{ docId: 'doc1', score: 0.5, matchedTerms: ['hello'] }]
5599
+ * ```
5600
+ */
5601
+ declare class FullTextIndex {
5602
+ /** Fields to index from documents */
5603
+ private readonly fields;
5604
+ /** Tokenizer for text processing */
5605
+ private readonly tokenizer;
5606
+ /** BM25 scorer for relevance ranking */
5607
+ private readonly scorer;
5608
+ /** Per-field inverted indexes for field boosting */
5609
+ private readonly fieldIndexes;
5610
+ /** Combined index for all fields */
5611
+ private combinedIndex;
5612
+ /** Track indexed documents */
5613
+ private readonly indexedDocs;
5614
+ /** Serializer for persistence */
5615
+ private readonly serializer;
5616
+ /**
5617
+ * Cache of document tokens for fast single-document scoring.
5618
+ * Maps docId → tokenized terms from all indexed fields.
5619
+ */
5620
+ private readonly documentTokensCache;
5621
+ /**
5622
+ * Create a new FullTextIndex.
5623
+ *
5624
+ * @param config - Index configuration
5625
+ */
5626
+ constructor(config: FullTextIndexConfig);
5627
+ /**
5628
+ * Index a document (add or update).
5629
+ * Called when a document is set in the CRDT map.
5630
+ *
5631
+ * @param docId - Document identifier
5632
+ * @param document - Document data containing fields to index
5633
+ */
5634
+ onSet(docId: string, document: Record<string, unknown> | null | undefined): void;
5635
+ /**
5636
+ * Remove a document from the index.
5637
+ * Called when a document is deleted from the CRDT map.
5638
+ *
5639
+ * @param docId - Document identifier to remove
5640
+ */
5641
+ onRemove(docId: string): void;
5642
+ /**
5643
+ * Search the index with a query.
5644
+ *
5645
+ * @param query - Search query text
5646
+ * @param options - Search options (limit, minScore, boost)
5647
+ * @returns Array of search results, sorted by relevance
5648
+ */
5649
+ search(query: string, options?: SearchOptions): SearchResult[];
5650
+ /**
5651
+ * Serialize the index state.
5652
+ *
5653
+ * @returns Serialized index data
5654
+ */
5655
+ serialize(): SerializedIndex;
5656
+ /**
5657
+ * Load index from serialized state.
5658
+ *
5659
+ * @param data - Serialized index data
5660
+ */
5661
+ load(data: SerializedIndex): void;
5662
+ /**
5663
+ * Build the index from an array of entries.
5664
+ * Useful for initial bulk loading.
5665
+ *
5666
+ * @param entries - Array of [docId, document] tuples
5667
+ */
5668
+ buildFromEntries(entries: Array<[string, Record<string, unknown> | null]>): void;
5669
+ /**
5670
+ * Clear all data from the index.
5671
+ */
5672
+ clear(): void;
5673
+ /**
5674
+ * Get the number of indexed documents.
5675
+ *
5676
+ * @returns Number of documents in the index
5677
+ */
5678
+ getSize(): number;
5679
+ /**
5680
+ * Tokenize a query string using the index's tokenizer.
5681
+ * Public method for external use (e.g., SearchCoordinator).
5682
+ *
5683
+ * @param query - Query text to tokenize
5684
+ * @returns Array of tokenized terms
5685
+ */
5686
+ tokenizeQuery(query: string): string[];
5687
+ /**
5688
+ * Score a single document against query terms.
5689
+ * O(Q × D) complexity where Q = query terms, D = document tokens.
5690
+ *
5691
+ * This method is optimized for checking if a single document
5692
+ * matches a query, avoiding full index scan.
5693
+ *
5694
+ * @param docId - Document ID to score
5695
+ * @param queryTerms - Pre-tokenized query terms
5696
+ * @param document - Optional document data (used if not in cache)
5697
+ * @returns SearchResult with score and matched terms, or null if no match
5698
+ */
5699
+ scoreSingleDocument(docId: string, queryTerms: string[], document?: Record<string, unknown>): SearchResult | null;
5700
+ /**
5701
+ * Tokenize all indexed fields of a document.
5702
+ * Internal helper for scoreSingleDocument when document not in cache.
5703
+ *
5704
+ * @param document - Document data
5705
+ * @returns Array of all tokens from indexed fields
5706
+ */
5707
+ private tokenizeDocument;
5708
+ /**
5709
+ * Get the index name (for debugging/display).
5710
+ *
5711
+ * @returns Descriptive name including indexed fields
5712
+ */
5713
+ get name(): string;
5714
+ /**
5715
+ * Remove document from all indexes (internal).
5716
+ */
5717
+ private removeFromIndexes;
5718
+ /**
5719
+ * Search with field boosting.
5720
+ * Scores are computed per-field and combined with boost weights.
5721
+ */
5722
+ private searchWithBoost;
5723
+ }
5724
+
5725
+ /**
5726
+ * SetResultSet Implementation
5727
+ *
5728
+ * ResultSet backed by a Set, used for HashIndex results.
5729
+ *
5730
+ * @module query/resultset/SetResultSet
5731
+ */
5732
+
5733
+ /**
5734
+ * ResultSet backed by a Set.
5735
+ * Provides O(1) contains() check and direct iteration.
5736
+ */
5737
+ declare class SetResultSet<K> implements ResultSet<K> {
5738
+ private readonly keys;
5739
+ private readonly retrievalCost;
5740
+ constructor(keys: Set<K>, retrievalCost: number);
5741
+ [Symbol.iterator](): Iterator<K>;
5742
+ getRetrievalCost(): number;
5743
+ getMergeCost(): number;
5744
+ contains(key: K): boolean;
5745
+ size(): number;
5746
+ toArray(): K[];
5747
+ isEmpty(): boolean;
5748
+ }
5749
+
5750
+ /**
5751
+ * LazyResultSet Implementation
5752
+ *
5753
+ * Lazily evaluated result set for range queries.
5754
+ * Used when materializing all results upfront would be expensive.
5755
+ *
5756
+ * @module query/resultset/LazyResultSet
5757
+ */
5758
+
5759
+ /**
5760
+ * Factory function type that creates a generator for lazy iteration.
5761
+ */
5762
+ type IteratorFactory<K> = () => Generator<K>;
5763
+ /**
5764
+ * Lazily evaluated result set.
5765
+ * Used for range queries where materializing all results upfront is expensive.
5766
+ *
5767
+ * K = record key type
5768
+ */
5769
+ declare class LazyResultSet<K> implements ResultSet<K> {
5770
+ private readonly iteratorFactory;
5771
+ private readonly retrievalCost;
5772
+ private readonly estimatedSize;
5773
+ /** Cached materialized results */
5774
+ private cached;
5775
+ /**
5776
+ * Create a LazyResultSet.
5777
+ *
5778
+ * @param iteratorFactory - Factory that creates a fresh generator each time
5779
+ * @param retrievalCost - Cost of retrieving results from the index
5780
+ * @param estimatedSize - Estimated result count for merge cost calculation
5781
+ */
5782
+ constructor(iteratorFactory: IteratorFactory<K>, retrievalCost: number, estimatedSize: number);
5783
+ [Symbol.iterator](): Generator<K>;
5784
+ getRetrievalCost(): number;
5785
+ getMergeCost(): number;
5786
+ contains(key: K): boolean;
5787
+ size(): number;
5788
+ toArray(): K[];
5789
+ isEmpty(): boolean;
5790
+ /**
5791
+ * Check if the result set has been materialized.
5792
+ * Useful for testing lazy evaluation behavior.
5793
+ */
5794
+ isMaterialized(): boolean;
5795
+ /**
5796
+ * Force materialization of the result set.
5797
+ * Returns the cached array.
5798
+ */
5799
+ materialize(): K[];
5800
+ /**
5801
+ * Get the estimated size before materialization.
5802
+ */
5803
+ getEstimatedSize(): number;
5804
+ }
5805
+
5806
+ /**
5807
+ * IntersectionResultSet Implementation
5808
+ *
5809
+ * Intersection of multiple result sets (AND logic).
5810
+ * Implements CQEngine "smallest first" strategy:
5811
+ * iterate the smallest set, check membership in others.
5812
+ *
5813
+ * @module query/resultset/IntersectionResultSet
5814
+ */
5815
+
5816
+ /**
5817
+ * Intersection of multiple result sets (AND logic).
5818
+ * CQEngine strategy: iterate smallest set, check membership in others.
5819
+ *
5820
+ * K = record key type
5821
+ */
5822
+ declare class IntersectionResultSet<K> implements ResultSet<K> {
5823
+ /** Cached materialized results */
5824
+ private cached;
5825
+ /** Result sets sorted by merge cost */
5826
+ private sortedResultSets;
5827
+ /**
5828
+ * Create an IntersectionResultSet.
5829
+ *
5830
+ * @param resultSets - Result sets to intersect
5831
+ */
5832
+ constructor(resultSets: ResultSet<K>[]);
5833
+ /**
5834
+ * Lazy iteration over intersection.
5835
+ * Iterates smallest set, yields only keys present in all sets.
5836
+ */
5837
+ [Symbol.iterator](): Generator<K>;
5838
+ /**
5839
+ * Retrieval cost is minimum of all (we only iterate smallest).
5840
+ */
5841
+ getRetrievalCost(): number;
5842
+ /**
5843
+ * Merge cost is estimated as smallest set size (upper bound).
5844
+ */
5845
+ getMergeCost(): number;
5846
+ /**
5847
+ * Check if key is in all result sets.
5848
+ */
5849
+ contains(key: K): boolean;
5850
+ /**
5851
+ * Get size by materializing results.
5852
+ */
5853
+ size(): number;
5854
+ /**
5855
+ * Materialize to array with caching.
5856
+ */
5857
+ toArray(): K[];
5858
+ /**
5859
+ * Check if empty (tries to avoid full materialization).
5860
+ */
5861
+ isEmpty(): boolean;
5862
+ /**
5863
+ * Check if results have been materialized.
5864
+ */
5865
+ isMaterialized(): boolean;
5866
+ }
5867
+
5868
+ /**
5869
+ * UnionResultSet Implementation
5870
+ *
5871
+ * Union of multiple result sets (OR logic).
5872
+ * Deduplicates results using a Set during iteration.
5873
+ *
5874
+ * @module query/resultset/UnionResultSet
5875
+ */
5876
+
5877
+ /**
5878
+ * Union of multiple result sets (OR logic).
5879
+ * Deduplicates results.
5096
5880
  *
5097
5881
  * K = record key type
5098
5882
  */
@@ -5740,6 +6524,21 @@ interface QueryOptimizerOptions<K, V> {
5740
6524
  indexRegistry: IndexRegistry<K, V>;
5741
6525
  /** Standing query registry for pre-computed queries (optional) */
5742
6526
  standingQueryRegistry?: StandingQueryRegistry<K, V>;
6527
+ /** Full-text index registry for FTS queries (Phase 12) */
6528
+ fullTextIndexes?: Map<string, FullTextIndex>;
6529
+ }
6530
+ /**
6531
+ * Classified predicates by type for hybrid query planning.
6532
+ */
6533
+ interface ClassifiedPredicates {
6534
+ /** Exact match predicates (eq, neq, in) */
6535
+ exactPredicates: Query[];
6536
+ /** Range predicates (gt, gte, lt, lte, between) */
6537
+ rangePredicates: Query[];
6538
+ /** Full-text search predicates (match, matchPhrase, matchPrefix) */
6539
+ ftsPredicates: FTSQueryNode[];
6540
+ /** Other predicates (like, regex, contains, etc.) */
6541
+ otherPredicates: Query[];
5743
6542
  }
5744
6543
  /**
5745
6544
  * Cost-based query optimizer.
@@ -5750,6 +6549,7 @@ interface QueryOptimizerOptions<K, V> {
5750
6549
  declare class QueryOptimizer<K, V> {
5751
6550
  private readonly indexRegistry;
5752
6551
  private readonly standingQueryRegistry?;
6552
+ private readonly fullTextIndexes;
5753
6553
  /**
5754
6554
  * Create a QueryOptimizer.
5755
6555
  *
@@ -5757,6 +6557,33 @@ declare class QueryOptimizer<K, V> {
5757
6557
  * @param standingQueryRegistry - Optional StandingQueryRegistry (deprecated, use options)
5758
6558
  */
5759
6559
  constructor(indexRegistryOrOptions: IndexRegistry<K, V> | QueryOptimizerOptions<K, V>, standingQueryRegistry?: StandingQueryRegistry<K, V>);
6560
+ /**
6561
+ * Register a full-text index for a field (Phase 12).
6562
+ *
6563
+ * @param field - Field name
6564
+ * @param index - FullTextIndex instance
6565
+ */
6566
+ registerFullTextIndex(field: string, index: FullTextIndex): void;
6567
+ /**
6568
+ * Unregister a full-text index (Phase 12).
6569
+ *
6570
+ * @param field - Field name
6571
+ */
6572
+ unregisterFullTextIndex(field: string): void;
6573
+ /**
6574
+ * Get registered full-text index for a field (Phase 12).
6575
+ *
6576
+ * @param field - Field name
6577
+ * @returns FullTextIndex or undefined
6578
+ */
6579
+ getFullTextIndex(field: string): FullTextIndex | undefined;
6580
+ /**
6581
+ * Check if a full-text index exists for a field (Phase 12).
6582
+ *
6583
+ * @param field - Field name
6584
+ * @returns True if FTS index exists
6585
+ */
6586
+ hasFullTextIndex(field: string): boolean;
5760
6587
  /**
5761
6588
  * Optimize a query and return an execution plan.
5762
6589
  *
@@ -5780,6 +6607,41 @@ declare class QueryOptimizer<K, V> {
5780
6607
  * Optimize a single query node.
5781
6608
  */
5782
6609
  private optimizeNode;
6610
+ /**
6611
+ * Optimize a full-text search query (Phase 12).
6612
+ */
6613
+ private optimizeFTS;
6614
+ /**
6615
+ * Build an FTS scan step from a query node (Phase 12).
6616
+ */
6617
+ private buildFTSScanStep;
6618
+ /**
6619
+ * Estimate cost of FTS query based on index size (Phase 12).
6620
+ */
6621
+ private estimateFTSCost;
6622
+ /**
6623
+ * Classify predicates by type for hybrid query planning (Phase 12).
6624
+ *
6625
+ * @param predicates - Array of predicates to classify
6626
+ * @returns Classified predicates
6627
+ */
6628
+ classifyPredicates(predicates: Query[]): ClassifiedPredicates;
6629
+ /**
6630
+ * Determine fusion strategy based on step types (Phase 12).
6631
+ *
6632
+ * Strategy selection:
6633
+ * - All binary (exact/range with no scores) → 'intersection'
6634
+ * - All scored (FTS) → 'score-filter' (filter by score, sort by score)
6635
+ * - Mixed (binary + scored) → 'rrf' (Reciprocal Rank Fusion)
6636
+ *
6637
+ * @param steps - Plan steps to fuse
6638
+ * @returns Fusion strategy
6639
+ */
6640
+ determineFusionStrategy(steps: PlanStep[]): FusionStrategy;
6641
+ /**
6642
+ * Check if a plan step returns scored results (Phase 12).
6643
+ */
6644
+ private stepReturnsScored;
5783
6645
  /**
5784
6646
  * Optimize a simple (attribute-based) query.
5785
6647
  */
@@ -6674,472 +7536,152 @@ declare class IndexedLWWMap<K extends string, V> extends LWWMap<K, V> {
6674
7536
  /**
6675
7537
  * Get current live query results (snapshot).
6676
7538
  *
6677
- * @param query - Query to execute
6678
- * @returns Array of matching keys
6679
- */
6680
- getLiveQueryResults(query: Query): K[];
6681
- /**
6682
- * Check if a query has active subscribers.
6683
- *
6684
- * @param query - Query to check
6685
- * @returns true if query has subscribers
6686
- */
6687
- hasLiveQuerySubscribers(query: Query): boolean;
6688
- /**
6689
- * Set a value (with index updates).
6690
- */
6691
- set(key: K, value: V, ttlMs?: number): LWWRecord<V>;
6692
- /**
6693
- * Remove a value (with index updates).
6694
- */
6695
- remove(key: K): LWWRecord<V>;
6696
- /**
6697
- * Merge a remote record (with index updates).
6698
- */
6699
- merge(key: K, remote: LWWRecord<V>): boolean;
6700
- /**
6701
- * Clear all data (and indexes).
6702
- */
6703
- clear(): void;
6704
- /**
6705
- * Returns all keys (non-tombstoned, non-expired).
6706
- */
6707
- keys(): Iterable<K>;
6708
- /**
6709
- * Get index statistics.
6710
- */
6711
- getIndexStats(): Map<string, IndexStats>;
6712
- /**
6713
- * Get index registry statistics.
6714
- */
6715
- getIndexRegistryStats(): IndexRegistryStats;
6716
- /**
6717
- * Get query optimizer for plan inspection.
6718
- */
6719
- getQueryOptimizer(): QueryOptimizer<K, V>;
6720
- /**
6721
- * Get live query manager for direct access.
6722
- */
6723
- getLiveQueryManager(): LiveQueryManager<K, V>;
6724
- /**
6725
- * Get standing query registry for direct access.
6726
- */
6727
- getStandingQueryRegistry(): StandingQueryRegistry<K, V>;
6728
- /**
6729
- * Explain query execution plan.
6730
- *
6731
- * @param query - Query to explain
6732
- * @returns Query execution plan
6733
- */
6734
- explainQuery(query: Query): QueryPlan;
6735
- /**
6736
- * Register an attribute for auto-indexing.
6737
- * Required before auto-index can create indexes on this attribute.
6738
- *
6739
- * @param attribute - The attribute to register
6740
- * @param allowedIndexTypes - Optional list of allowed index types
6741
- */
6742
- registerAttribute<A>(attribute: Attribute<V, A>, allowedIndexTypes?: RecommendedIndexType[]): void;
6743
- /**
6744
- * Unregister an attribute from auto-indexing.
6745
- *
6746
- * @param attributeName - Name of attribute to unregister
6747
- */
6748
- unregisterAttribute(attributeName: string): void;
6749
- /**
6750
- * Get index suggestions based on query patterns.
6751
- * Use this in production to get recommendations for manual index creation.
6752
- *
6753
- * @param options - Suggestion options
6754
- * @returns Array of index suggestions sorted by priority
6755
- *
6756
- * @example
6757
- * ```typescript
6758
- * const suggestions = products.getIndexSuggestions();
6759
- * // [{ attribute: 'category', indexType: 'hash', priority: 'high', ... }]
6760
- * ```
6761
- */
6762
- getIndexSuggestions(options?: IndexSuggestionOptions): IndexSuggestion[];
6763
- /**
6764
- * Get query pattern statistics.
6765
- * Useful for debugging and understanding query patterns.
6766
- *
6767
- * @returns Array of query statistics
6768
- */
6769
- getQueryStatistics(): QueryStatistics[];
6770
- /**
6771
- * Reset query statistics.
6772
- * Call this to clear accumulated query patterns.
6773
- */
6774
- resetQueryStatistics(): void;
6775
- /**
6776
- * Get query pattern tracker for advanced usage.
6777
- */
6778
- getQueryTracker(): QueryPatternTracker;
6779
- /**
6780
- * Get index advisor for advanced usage.
6781
- */
6782
- getIndexAdvisor(): IndexAdvisor;
6783
- /**
6784
- * Get auto-index manager (if enabled).
6785
- */
6786
- getAutoIndexManager(): AutoIndexManager<K, V> | null;
6787
- /**
6788
- * Check if auto-indexing is enabled.
6789
- */
6790
- isAutoIndexingEnabled(): boolean;
6791
- /**
6792
- * Check if lazy index building is enabled.
6793
- */
6794
- isLazyIndexingEnabled(): boolean;
6795
- /**
6796
- * Force materialization of all lazy indexes.
6797
- * Useful to pre-warm indexes before critical operations.
6798
- *
6799
- * @param progressCallback - Optional progress callback
7539
+ * @param query - Query to execute
7540
+ * @returns Array of matching keys
6800
7541
  */
6801
- materializeAllIndexes(progressCallback?: IndexBuildProgressCallback): void;
7542
+ getLiveQueryResults(query: Query): K[];
6802
7543
  /**
6803
- * Get count of pending records across all lazy indexes.
6804
- * Returns 0 if no lazy indexes or all are materialized.
7544
+ * Check if a query has active subscribers.
7545
+ *
7546
+ * @param query - Query to check
7547
+ * @returns true if query has subscribers
6805
7548
  */
6806
- getPendingIndexCount(): number;
7549
+ hasLiveQuerySubscribers(query: Query): boolean;
6807
7550
  /**
6808
- * Check if any lazy indexes are still pending (not built).
7551
+ * Set a value (with index updates).
6809
7552
  */
6810
- hasUnbuiltIndexes(): boolean;
7553
+ set(key: K, value: V, ttlMs?: number): LWWRecord<V>;
6811
7554
  /**
6812
- * Track query pattern for adaptive indexing.
7555
+ * Remove a value (with index updates).
6813
7556
  */
6814
- private trackQueryPattern;
7557
+ remove(key: K): LWWRecord<V>;
6815
7558
  /**
6816
- * Extract attribute name from query.
7559
+ * Merge a remote record (with index updates).
6817
7560
  */
6818
- private extractAttribute;
7561
+ merge(key: K, remote: LWWRecord<V>): boolean;
6819
7562
  /**
6820
- * Extract query type from query.
7563
+ * Clear all data (and indexes).
6821
7564
  */
6822
- private extractQueryType;
6823
- }
6824
-
6825
- /**
6826
- * Full-Text Search Types
6827
- *
6828
- * Type definitions for the FTS (Full-Text Search) module.
6829
- * This module provides BM25-based keyword search capabilities.
6830
- *
6831
- * @module fts/types
6832
- */
6833
- /**
6834
- * Options for configuring the FTS Tokenizer.
6835
- */
6836
- interface TokenizerOptions {
7565
+ clear(): void;
6837
7566
  /**
6838
- * Convert all text to lowercase before tokenization.
6839
- * @default true
7567
+ * Returns all keys (non-tombstoned, non-expired).
6840
7568
  */
6841
- lowercase?: boolean;
7569
+ keys(): Iterable<K>;
6842
7570
  /**
6843
- * Set of words to exclude from tokenization (e.g., "the", "and", "is").
6844
- * @default ENGLISH_STOPWORDS (174 words)
7571
+ * Get index statistics.
6845
7572
  */
6846
- stopwords?: Set<string>;
7573
+ getIndexStats(): Map<string, IndexStats>;
6847
7574
  /**
6848
- * Function to reduce words to their root form.
6849
- * @default Porter stemmer
7575
+ * Get index registry statistics.
6850
7576
  */
6851
- stemmer?: (word: string) => string;
7577
+ getIndexRegistryStats(): IndexRegistryStats;
6852
7578
  /**
6853
- * Minimum token length to include in results.
6854
- * @default 2
7579
+ * Get query optimizer for plan inspection.
6855
7580
  */
6856
- minLength?: number;
7581
+ getQueryOptimizer(): QueryOptimizer<K, V>;
6857
7582
  /**
6858
- * Maximum token length to include in results.
6859
- * @default 40
7583
+ * Get live query manager for direct access.
6860
7584
  */
6861
- maxLength?: number;
6862
- }
6863
- /**
6864
- * Information about a term's occurrence in a document.
6865
- */
6866
- interface TermInfo {
6867
- /** Document ID where the term appears */
6868
- docId: string;
6869
- /** Number of times the term appears in the document */
6870
- termFrequency: number;
6871
- /** Optional: positions of the term for phrase search (future) */
6872
- fieldPositions?: number[];
6873
- }
6874
- /**
6875
- * Posting list entry for the inverted index.
6876
- */
6877
- interface Posting {
6878
- /** Document ID */
6879
- docId: string;
6880
- /** Term frequency in this document */
6881
- termFrequency: number;
6882
- /** Optional: positions for phrase search */
6883
- positions?: number[];
6884
- }
6885
- /**
6886
- * BM25 algorithm configuration options.
6887
- */
6888
- interface BM25Options {
7585
+ getLiveQueryManager(): LiveQueryManager<K, V>;
6889
7586
  /**
6890
- * Term frequency saturation parameter.
6891
- * Higher values give more weight to repeated terms.
6892
- * @default 1.2
7587
+ * Get standing query registry for direct access.
6893
7588
  */
6894
- k1?: number;
7589
+ getStandingQueryRegistry(): StandingQueryRegistry<K, V>;
6895
7590
  /**
6896
- * Document length normalization parameter.
6897
- * 0 = no length normalization, 1 = full normalization.
6898
- * @default 0.75
7591
+ * Explain query execution plan.
7592
+ *
7593
+ * @param query - Query to explain
7594
+ * @returns Query execution plan
6899
7595
  */
6900
- b?: number;
6901
- }
6902
- /**
6903
- * A document with its BM25 relevance score.
6904
- */
6905
- interface ScoredDocument {
6906
- /** Document ID */
6907
- docId: string;
6908
- /** BM25 relevance score */
6909
- score: number;
6910
- /** Terms from the query that matched this document */
6911
- matchedTerms: string[];
6912
- }
6913
- /**
6914
- * Configuration for a FullTextIndex.
6915
- */
6916
- interface FullTextIndexConfig {
6917
- /** Fields to index for full-text search (e.g., ['title', 'body']) */
6918
- fields: string[];
6919
- /** Tokenizer configuration */
6920
- tokenizer?: TokenizerOptions;
6921
- /** BM25 scoring parameters */
6922
- bm25?: BM25Options;
6923
- }
6924
- /**
6925
- * Options for search queries.
6926
- */
6927
- interface SearchOptions {
6928
- /** Maximum number of results to return */
6929
- limit?: number;
6930
- /** Minimum BM25 score threshold */
6931
- minScore?: number;
6932
- /** Restrict search to specific fields */
6933
- fields?: string[];
6934
- /** Field boost weights (e.g., { title: 2.0, body: 1.0 }) */
6935
- boost?: Record<string, number>;
6936
- }
6937
- /**
6938
- * Search result with full details.
6939
- */
6940
- interface SearchResult {
6941
- /** Document ID */
6942
- docId: string;
6943
- /** BM25 relevance score */
6944
- score: number;
6945
- /** Source of the match (for hybrid search) */
6946
- source?: 'exact' | 'fulltext' | 'vector' | 'bfs';
6947
- /** Original document data (if requested) */
6948
- data?: unknown;
6949
- /** Highlighted text snippet (if requested) */
6950
- highlightedText?: string;
6951
- /** Terms that matched */
6952
- matchedTerms?: string[];
6953
- /** Document embedding (if available) */
6954
- embedding?: number[];
6955
- /** Cosine similarity to query (0-1) */
6956
- embeddingSimilarity?: number;
6957
- /** Debug information */
6958
- debug?: {
6959
- exactScore?: number;
6960
- fulltextScore?: number;
6961
- vectorScore?: number;
6962
- rangeScore?: number;
6963
- };
6964
- }
6965
- /**
6966
- * Serialized format for index persistence.
6967
- */
6968
- interface SerializedIndex {
6969
- /** Schema version for backwards compatibility */
6970
- version: number;
6971
- /** Index metadata */
6972
- metadata: {
6973
- totalDocs: number;
6974
- avgDocLength: number;
6975
- createdAt: number;
6976
- lastModified: number;
6977
- };
6978
- /** Serialized term data */
6979
- terms: Array<{
6980
- term: string;
6981
- idf: number;
6982
- postings: Array<{
6983
- docId: string;
6984
- termFrequency: number;
6985
- positions?: number[];
6986
- }>;
6987
- }>;
6988
- /** Document lengths for BM25 normalization */
6989
- docLengths: Record<string, number>;
6990
- }
6991
-
6992
- /**
6993
- * Full-Text Index
6994
- *
6995
- * High-level integration class that combines Tokenizer, InvertedIndex,
6996
- * and BM25Scorer for complete full-text search functionality.
6997
- * Designed to integrate with TopGun's CRDT maps.
6998
- *
6999
- * @module fts/FullTextIndex
7000
- */
7001
-
7002
- /**
7003
- * Full-Text Index for TopGun
7004
- *
7005
- * Provides BM25-based full-text search across document fields.
7006
- * Supports incremental updates (add/update/remove) for real-time sync.
7007
- *
7008
- * @example
7009
- * ```typescript
7010
- * const index = new FullTextIndex({
7011
- * fields: ['title', 'body'],
7012
- * tokenizer: { minLength: 2 },
7013
- * bm25: { k1: 1.2, b: 0.75 }
7014
- * });
7015
- *
7016
- * index.onSet('doc1', { title: 'Hello World', body: 'Test content' });
7017
- * const results = index.search('hello');
7018
- * // [{ docId: 'doc1', score: 0.5, matchedTerms: ['hello'] }]
7019
- * ```
7020
- */
7021
- declare class FullTextIndex {
7022
- /** Fields to index from documents */
7023
- private readonly fields;
7024
- /** Tokenizer for text processing */
7025
- private readonly tokenizer;
7026
- /** BM25 scorer for relevance ranking */
7027
- private readonly scorer;
7028
- /** Per-field inverted indexes for field boosting */
7029
- private readonly fieldIndexes;
7030
- /** Combined index for all fields */
7031
- private combinedIndex;
7032
- /** Track indexed documents */
7033
- private readonly indexedDocs;
7034
- /** Serializer for persistence */
7035
- private readonly serializer;
7596
+ explainQuery(query: Query): QueryPlan;
7036
7597
  /**
7037
- * Cache of document tokens for fast single-document scoring.
7038
- * Maps docId tokenized terms from all indexed fields.
7598
+ * Register an attribute for auto-indexing.
7599
+ * Required before auto-index can create indexes on this attribute.
7600
+ *
7601
+ * @param attribute - The attribute to register
7602
+ * @param allowedIndexTypes - Optional list of allowed index types
7039
7603
  */
7040
- private readonly documentTokensCache;
7604
+ registerAttribute<A>(attribute: Attribute<V, A>, allowedIndexTypes?: RecommendedIndexType[]): void;
7041
7605
  /**
7042
- * Create a new FullTextIndex.
7606
+ * Unregister an attribute from auto-indexing.
7043
7607
  *
7044
- * @param config - Index configuration
7608
+ * @param attributeName - Name of attribute to unregister
7045
7609
  */
7046
- constructor(config: FullTextIndexConfig);
7610
+ unregisterAttribute(attributeName: string): void;
7047
7611
  /**
7048
- * Index a document (add or update).
7049
- * Called when a document is set in the CRDT map.
7612
+ * Get index suggestions based on query patterns.
7613
+ * Use this in production to get recommendations for manual index creation.
7050
7614
  *
7051
- * @param docId - Document identifier
7052
- * @param document - Document data containing fields to index
7615
+ * @param options - Suggestion options
7616
+ * @returns Array of index suggestions sorted by priority
7617
+ *
7618
+ * @example
7619
+ * ```typescript
7620
+ * const suggestions = products.getIndexSuggestions();
7621
+ * // [{ attribute: 'category', indexType: 'hash', priority: 'high', ... }]
7622
+ * ```
7053
7623
  */
7054
- onSet(docId: string, document: Record<string, unknown> | null | undefined): void;
7624
+ getIndexSuggestions(options?: IndexSuggestionOptions): IndexSuggestion[];
7055
7625
  /**
7056
- * Remove a document from the index.
7057
- * Called when a document is deleted from the CRDT map.
7626
+ * Get query pattern statistics.
7627
+ * Useful for debugging and understanding query patterns.
7058
7628
  *
7059
- * @param docId - Document identifier to remove
7629
+ * @returns Array of query statistics
7060
7630
  */
7061
- onRemove(docId: string): void;
7631
+ getQueryStatistics(): QueryStatistics[];
7062
7632
  /**
7063
- * Search the index with a query.
7064
- *
7065
- * @param query - Search query text
7066
- * @param options - Search options (limit, minScore, boost)
7067
- * @returns Array of search results, sorted by relevance
7633
+ * Reset query statistics.
7634
+ * Call this to clear accumulated query patterns.
7068
7635
  */
7069
- search(query: string, options?: SearchOptions): SearchResult[];
7636
+ resetQueryStatistics(): void;
7070
7637
  /**
7071
- * Serialize the index state.
7072
- *
7073
- * @returns Serialized index data
7638
+ * Get query pattern tracker for advanced usage.
7074
7639
  */
7075
- serialize(): SerializedIndex;
7640
+ getQueryTracker(): QueryPatternTracker;
7076
7641
  /**
7077
- * Load index from serialized state.
7078
- *
7079
- * @param data - Serialized index data
7642
+ * Get index advisor for advanced usage.
7080
7643
  */
7081
- load(data: SerializedIndex): void;
7644
+ getIndexAdvisor(): IndexAdvisor;
7082
7645
  /**
7083
- * Build the index from an array of entries.
7084
- * Useful for initial bulk loading.
7085
- *
7086
- * @param entries - Array of [docId, document] tuples
7646
+ * Get auto-index manager (if enabled).
7087
7647
  */
7088
- buildFromEntries(entries: Array<[string, Record<string, unknown> | null]>): void;
7648
+ getAutoIndexManager(): AutoIndexManager<K, V> | null;
7089
7649
  /**
7090
- * Clear all data from the index.
7650
+ * Check if auto-indexing is enabled.
7091
7651
  */
7092
- clear(): void;
7652
+ isAutoIndexingEnabled(): boolean;
7093
7653
  /**
7094
- * Get the number of indexed documents.
7095
- *
7096
- * @returns Number of documents in the index
7654
+ * Check if lazy index building is enabled.
7097
7655
  */
7098
- getSize(): number;
7656
+ isLazyIndexingEnabled(): boolean;
7099
7657
  /**
7100
- * Tokenize a query string using the index's tokenizer.
7101
- * Public method for external use (e.g., SearchCoordinator).
7658
+ * Force materialization of all lazy indexes.
7659
+ * Useful to pre-warm indexes before critical operations.
7102
7660
  *
7103
- * @param query - Query text to tokenize
7104
- * @returns Array of tokenized terms
7661
+ * @param progressCallback - Optional progress callback
7105
7662
  */
7106
- tokenizeQuery(query: string): string[];
7663
+ materializeAllIndexes(progressCallback?: IndexBuildProgressCallback): void;
7107
7664
  /**
7108
- * Score a single document against query terms.
7109
- * O(Q × D) complexity where Q = query terms, D = document tokens.
7110
- *
7111
- * This method is optimized for checking if a single document
7112
- * matches a query, avoiding full index scan.
7113
- *
7114
- * @param docId - Document ID to score
7115
- * @param queryTerms - Pre-tokenized query terms
7116
- * @param document - Optional document data (used if not in cache)
7117
- * @returns SearchResult with score and matched terms, or null if no match
7665
+ * Get count of pending records across all lazy indexes.
7666
+ * Returns 0 if no lazy indexes or all are materialized.
7118
7667
  */
7119
- scoreSingleDocument(docId: string, queryTerms: string[], document?: Record<string, unknown>): SearchResult | null;
7668
+ getPendingIndexCount(): number;
7120
7669
  /**
7121
- * Tokenize all indexed fields of a document.
7122
- * Internal helper for scoreSingleDocument when document not in cache.
7123
- *
7124
- * @param document - Document data
7125
- * @returns Array of all tokens from indexed fields
7670
+ * Check if any lazy indexes are still pending (not built).
7126
7671
  */
7127
- private tokenizeDocument;
7672
+ hasUnbuiltIndexes(): boolean;
7128
7673
  /**
7129
- * Get the index name (for debugging/display).
7130
- *
7131
- * @returns Descriptive name including indexed fields
7674
+ * Track query pattern for adaptive indexing.
7132
7675
  */
7133
- get name(): string;
7676
+ private trackQueryPattern;
7134
7677
  /**
7135
- * Remove document from all indexes (internal).
7678
+ * Extract attribute name from query.
7136
7679
  */
7137
- private removeFromIndexes;
7680
+ private extractAttribute;
7138
7681
  /**
7139
- * Search with field boosting.
7140
- * Scores are computed per-field and combined with boost weights.
7682
+ * Extract query type from query.
7141
7683
  */
7142
- private searchWithBoost;
7684
+ private extractQueryType;
7143
7685
  }
7144
7686
 
7145
7687
  /**
@@ -7375,385 +7917,212 @@ declare class IndexedORMap<K extends string, V> extends ORMap<K, V> {
7375
7917
  /**
7376
7918
  * Get record by composite key.
7377
7919
  */
7378
- private getRecordByCompositeKey;
7379
- /**
7380
- * Check if record matches predicate.
7381
- */
7382
- private matchesPredicate;
7383
- /**
7384
- * Check if record matches IndexQuery (used by FallbackIndex).
7385
- * This is a simplified matcher for full scan fallback.
7386
- */
7387
- private matchesIndexQuery;
7388
- /**
7389
- * Convert Query to PredicateNode format.
7390
- */
7391
- private queryToPredicate;
7392
- /**
7393
- * Get index statistics.
7394
- */
7395
- getIndexStats(): Map<string, IndexStats>;
7396
- /**
7397
- * Get index registry statistics.
7398
- */
7399
- getIndexRegistryStats(): IndexRegistryStats;
7400
- /**
7401
- * Get query optimizer for plan inspection.
7402
- */
7403
- getQueryOptimizer(): QueryOptimizer<string, V>;
7404
- /**
7405
- * Explain query execution plan.
7406
- *
7407
- * @param query - Query to explain
7408
- * @returns Query execution plan
7409
- */
7410
- explainQuery(query: Query): QueryPlan;
7411
- /**
7412
- * Register an attribute for auto-indexing.
7413
- * Required before auto-index can create indexes on this attribute.
7414
- *
7415
- * @param attribute - The attribute to register
7416
- * @param allowedIndexTypes - Optional list of allowed index types
7417
- */
7418
- registerAttribute<A>(attribute: Attribute<V, A>, allowedIndexTypes?: RecommendedIndexType[]): void;
7419
- /**
7420
- * Unregister an attribute from auto-indexing.
7421
- *
7422
- * @param attributeName - Name of attribute to unregister
7423
- */
7424
- unregisterAttribute(attributeName: string): void;
7425
- /**
7426
- * Get index suggestions based on query patterns.
7427
- * Use this in production to get recommendations for manual index creation.
7428
- *
7429
- * @param options - Suggestion options
7430
- * @returns Array of index suggestions sorted by priority
7431
- */
7432
- getIndexSuggestions(options?: IndexSuggestionOptions): IndexSuggestion[];
7433
- /**
7434
- * Get query pattern statistics.
7435
- * Useful for debugging and understanding query patterns.
7436
- *
7437
- * @returns Array of query statistics
7438
- */
7439
- getQueryStatistics(): QueryStatistics[];
7440
- /**
7441
- * Reset query statistics.
7442
- * Call this to clear accumulated query patterns.
7443
- */
7444
- resetQueryStatistics(): void;
7445
- /**
7446
- * Get query pattern tracker for advanced usage.
7447
- */
7448
- getQueryTracker(): QueryPatternTracker;
7449
- /**
7450
- * Get index advisor for advanced usage.
7451
- */
7452
- getIndexAdvisor(): IndexAdvisor;
7453
- /**
7454
- * Get auto-index manager (if enabled).
7455
- */
7456
- getAutoIndexManager(): AutoIndexManager<string, V> | null;
7457
- /**
7458
- * Check if auto-indexing is enabled.
7459
- */
7460
- isAutoIndexingEnabled(): boolean;
7461
- /**
7462
- * Track query pattern for adaptive indexing.
7463
- */
7464
- private trackQueryPattern;
7465
- /**
7466
- * Extract attribute name from query.
7467
- */
7468
- private extractAttribute;
7469
- /**
7470
- * Extract query type from query.
7471
- */
7472
- private extractQueryType;
7473
- }
7474
-
7475
- /**
7476
- * English stopwords list (174 common words).
7477
- * These words are filtered out during tokenization as they
7478
- * don't contribute to search relevance.
7479
- */
7480
- declare const ENGLISH_STOPWORDS: Set<string>;
7481
-
7482
- /**
7483
- * Porter Stemming Algorithm
7484
- *
7485
- * Reduces English words to their stem (root form).
7486
- * Based on the algorithm by Martin Porter (1980).
7487
- *
7488
- * @see https://tartarus.org/martin/PorterStemmer/
7489
- *
7490
- * @param word - Word to stem (should be lowercase)
7491
- * @returns Stemmed word
7492
- */
7493
- declare function porterStem(word: string): string;
7494
-
7495
- /**
7496
- * FTS Tokenizer with Porter Stemming and Stopwords
7497
- *
7498
- * Provides text tokenization for BM25 full-text search.
7499
- * Features:
7500
- * - Unicode-aware word boundary detection
7501
- * - English stopwords filtering (174 words)
7502
- * - Porter stemming algorithm for word normalization
7503
- * - Configurable min/max token length
7504
- *
7505
- * @module fts/Tokenizer
7506
- */
7507
-
7508
- /**
7509
- * FTS Tokenizer
7510
- *
7511
- * Splits text into searchable tokens with normalization.
7512
- *
7513
- * @example
7514
- * ```typescript
7515
- * const tokenizer = new BM25Tokenizer();
7516
- * const tokens = tokenizer.tokenize('The quick brown foxes');
7517
- * // ['quick', 'brown', 'fox']
7518
- * ```
7519
- */
7520
- declare class BM25Tokenizer implements Tokenizer {
7521
- private readonly options;
7920
+ private getRecordByCompositeKey;
7522
7921
  /**
7523
- * Create a new BM25Tokenizer.
7524
- *
7525
- * @param options - Configuration options
7922
+ * Check if record matches predicate.
7526
7923
  */
7527
- constructor(options?: TokenizerOptions);
7924
+ private matchesPredicate;
7528
7925
  /**
7529
- * Tokenize text into an array of normalized tokens.
7530
- *
7531
- * @param text - Text to tokenize
7532
- * @returns Array of tokens
7926
+ * Check if record matches IndexQuery (used by FallbackIndex).
7927
+ * This is a simplified matcher for full scan fallback.
7533
7928
  */
7534
- tokenize(text: string): string[];
7535
- }
7536
-
7537
- /**
7538
- * FTS Inverted Index
7539
- *
7540
- * Data structure for full-text search that maps terms to documents.
7541
- * Supports efficient term lookup, document frequency calculation,
7542
- * and IDF (Inverse Document Frequency) for BM25 scoring.
7543
- *
7544
- * @module fts/BM25InvertedIndex
7545
- */
7546
-
7547
- /**
7548
- * Inverted Index for Full-Text Search (BM25)
7549
- *
7550
- * Maps terms to the documents containing them, along with term frequency
7551
- * information needed for BM25 scoring.
7552
- *
7553
- * @example
7554
- * ```typescript
7555
- * const index = new BM25InvertedIndex();
7556
- * index.addDocument('doc1', ['hello', 'world']);
7557
- * index.addDocument('doc2', ['hello', 'there']);
7558
- *
7559
- * const docs = index.getDocumentsForTerm('hello');
7560
- * // [{ docId: 'doc1', termFrequency: 1 }, { docId: 'doc2', termFrequency: 1 }]
7561
- * ```
7562
- */
7563
- declare class BM25InvertedIndex {
7564
- /** term → list of documents containing term */
7565
- private index;
7566
- /** document → total term count (for length normalization) */
7567
- private docLengths;
7568
- /** document → set of terms (for efficient removal) */
7569
- private docTerms;
7570
- /** Inverse Document Frequency cache */
7571
- private idfCache;
7572
- /** Total number of documents */
7573
- private totalDocs;
7574
- /** Average document length */
7575
- private avgDocLength;
7576
- constructor();
7929
+ private matchesIndexQuery;
7577
7930
  /**
7578
- * Add a document to the index.
7579
- *
7580
- * @param docId - Unique document identifier
7581
- * @param tokens - Array of tokens (already tokenized/stemmed)
7931
+ * Convert Query to PredicateNode format.
7582
7932
  */
7583
- addDocument(docId: string, tokens: string[]): void;
7933
+ private queryToPredicate;
7584
7934
  /**
7585
- * Remove a document from the index.
7586
- *
7587
- * @param docId - Document identifier to remove
7935
+ * Get index statistics.
7588
7936
  */
7589
- removeDocument(docId: string): void;
7937
+ getIndexStats(): Map<string, IndexStats>;
7590
7938
  /**
7591
- * Get all documents containing a term.
7592
- *
7593
- * @param term - Term to look up
7594
- * @returns Array of TermInfo objects
7939
+ * Get index registry statistics.
7595
7940
  */
7596
- getDocumentsForTerm(term: string): TermInfo[];
7941
+ getIndexRegistryStats(): IndexRegistryStats;
7597
7942
  /**
7598
- * Calculate IDF (Inverse Document Frequency) for a term.
7599
- *
7600
- * Uses BM25 IDF formula:
7601
- * IDF = log((N - df + 0.5) / (df + 0.5) + 1)
7602
- *
7603
- * Where:
7604
- * - N = total documents
7605
- * - df = document frequency (docs containing term)
7606
- *
7607
- * @param term - Term to calculate IDF for
7608
- * @returns IDF value (0 if term doesn't exist)
7943
+ * Get query optimizer for plan inspection.
7609
7944
  */
7610
- getIDF(term: string): number;
7945
+ getQueryOptimizer(): QueryOptimizer<string, V>;
7611
7946
  /**
7612
- * Get the length of a document (number of tokens).
7947
+ * Explain query execution plan.
7613
7948
  *
7614
- * @param docId - Document identifier
7615
- * @returns Document length (0 if not found)
7949
+ * @param query - Query to explain
7950
+ * @returns Query execution plan
7616
7951
  */
7617
- getDocLength(docId: string): number;
7952
+ explainQuery(query: Query): QueryPlan;
7618
7953
  /**
7619
- * Get the average document length.
7954
+ * Register an attribute for auto-indexing.
7955
+ * Required before auto-index can create indexes on this attribute.
7620
7956
  *
7621
- * @returns Average length across all documents
7957
+ * @param attribute - The attribute to register
7958
+ * @param allowedIndexTypes - Optional list of allowed index types
7622
7959
  */
7623
- getAvgDocLength(): number;
7960
+ registerAttribute<A>(attribute: Attribute<V, A>, allowedIndexTypes?: RecommendedIndexType[]): void;
7624
7961
  /**
7625
- * Get the total number of documents in the index.
7962
+ * Unregister an attribute from auto-indexing.
7626
7963
  *
7627
- * @returns Total document count
7964
+ * @param attributeName - Name of attribute to unregister
7628
7965
  */
7629
- getTotalDocs(): number;
7966
+ unregisterAttribute(attributeName: string): void;
7630
7967
  /**
7631
- * Get iterator for document lengths (useful for serialization).
7968
+ * Get index suggestions based on query patterns.
7969
+ * Use this in production to get recommendations for manual index creation.
7632
7970
  *
7633
- * @returns Iterator of [docId, length] pairs
7971
+ * @param options - Suggestion options
7972
+ * @returns Array of index suggestions sorted by priority
7634
7973
  */
7635
- getDocLengths(): IterableIterator<[string, number]>;
7974
+ getIndexSuggestions(options?: IndexSuggestionOptions): IndexSuggestion[];
7636
7975
  /**
7637
- * Get the number of documents in the index (alias for getTotalDocs).
7976
+ * Get query pattern statistics.
7977
+ * Useful for debugging and understanding query patterns.
7638
7978
  *
7639
- * @returns Number of indexed documents
7979
+ * @returns Array of query statistics
7640
7980
  */
7641
- getSize(): number;
7981
+ getQueryStatistics(): QueryStatistics[];
7642
7982
  /**
7643
- * Clear all data from the index.
7983
+ * Reset query statistics.
7984
+ * Call this to clear accumulated query patterns.
7644
7985
  */
7645
- clear(): void;
7986
+ resetQueryStatistics(): void;
7646
7987
  /**
7647
- * Check if a document exists in the index.
7648
- *
7649
- * @param docId - Document identifier
7650
- * @returns True if document exists
7988
+ * Get query pattern tracker for advanced usage.
7651
7989
  */
7652
- hasDocument(docId: string): boolean;
7990
+ getQueryTracker(): QueryPatternTracker;
7653
7991
  /**
7654
- * Get all unique terms in the index.
7655
- *
7656
- * @returns Iterator of all terms
7992
+ * Get index advisor for advanced usage.
7657
7993
  */
7658
- getTerms(): IterableIterator<string>;
7994
+ getIndexAdvisor(): IndexAdvisor;
7659
7995
  /**
7660
- * Get the number of unique terms in the index.
7661
- *
7662
- * @returns Number of unique terms
7996
+ * Get auto-index manager (if enabled).
7663
7997
  */
7664
- getTermCount(): number;
7998
+ getAutoIndexManager(): AutoIndexManager<string, V> | null;
7665
7999
  /**
7666
- * Update the average document length after add/remove.
8000
+ * Check if auto-indexing is enabled.
7667
8001
  */
7668
- private updateAvgDocLength;
8002
+ isAutoIndexingEnabled(): boolean;
8003
+ /**
8004
+ * Track query pattern for adaptive indexing.
8005
+ */
8006
+ private trackQueryPattern;
8007
+ /**
8008
+ * Extract attribute name from query.
8009
+ */
8010
+ private extractAttribute;
8011
+ /**
8012
+ * Extract query type from query.
8013
+ */
8014
+ private extractQueryType;
7669
8015
  }
7670
8016
 
7671
8017
  /**
7672
- * BM25 Scorer
8018
+ * Reciprocal Rank Fusion (RRF)
7673
8019
  *
7674
- * Implements the Okapi BM25 ranking algorithm for full-text search.
7675
- * BM25 is a probabilistic relevance ranking function used to estimate
7676
- * the relevance of documents to a given search query.
8020
+ * Implements RRF algorithm for merging ranked results from multiple search methods.
8021
+ * Used in hybrid queries that combine exact matches, range queries, and full-text search.
7677
8022
  *
7678
- * @see https://en.wikipedia.org/wiki/Okapi_BM25
7679
- * @module fts/BM25Scorer
8023
+ * Formula: RRF_score(d) = Σ 1 / (k + rank_i(d))
8024
+ *
8025
+ * Reference: Cormack, Clarke, Buettcher (2009) - "Reciprocal Rank Fusion outperforms
8026
+ * Condorcet and individual Rank Learning Methods"
8027
+ *
8028
+ * @module search/ReciprocalRankFusion
7680
8029
  */
7681
-
7682
8030
  /**
7683
- * BM25 Scorer for relevance ranking
7684
- *
7685
- * The BM25 formula:
7686
- * score(D,Q) = Σ IDF(qi) × (f(qi,D) × (k1 + 1)) / (f(qi,D) + k1 × (1 - b + b × |D| / avgdl))
8031
+ * A ranked result from a single search method.
8032
+ */
8033
+ interface RankedResult {
8034
+ /** Unique document identifier */
8035
+ docId: string;
8036
+ /** Original score from the search method (e.g., BM25 score) */
8037
+ score: number;
8038
+ /** Source of this result: 'exact' | 'fulltext' | 'range' | custom */
8039
+ source: string;
8040
+ }
8041
+ /**
8042
+ * Configuration for RRF algorithm.
8043
+ */
8044
+ interface RRFConfig {
8045
+ /**
8046
+ * Ranking constant k.
8047
+ * Higher values reduce the impact of high rankings.
8048
+ * Default: 60 (standard value from literature)
8049
+ */
8050
+ k?: number;
8051
+ }
8052
+ /**
8053
+ * Merged result with combined RRF score.
8054
+ */
8055
+ interface MergedResult {
8056
+ /** Unique document identifier */
8057
+ docId: string;
8058
+ /** Combined RRF score */
8059
+ score: number;
8060
+ /** Combined sources (e.g., "exact+fulltext") */
8061
+ source: string;
8062
+ /** Original scores from each source */
8063
+ originalScores: Record<string, number>;
8064
+ }
8065
+ /**
8066
+ * Reciprocal Rank Fusion implementation.
7687
8067
  *
7688
- * Where:
7689
- * - D = document
7690
- * - Q = query
7691
- * - qi = query term i
7692
- * - f(qi,D) = term frequency of qi in D
7693
- * - |D| = length of D (number of terms)
7694
- * - avgdl = average document length
7695
- * - k1 = term frequency saturation parameter (default: 1.2)
7696
- * - b = document length normalization parameter (default: 0.75)
8068
+ * Merges results from multiple ranked lists using the RRF formula.
8069
+ * Documents appearing in multiple result sets get boosted scores.
7697
8070
  *
7698
8071
  * @example
7699
8072
  * ```typescript
7700
- * const index = new BM25InvertedIndex();
7701
- * index.addDocument('doc1', ['hello', 'world']);
7702
- * index.addDocument('doc2', ['hello', 'there']);
8073
+ * const rrf = new ReciprocalRankFusion({ k: 60 });
7703
8074
  *
7704
- * const scorer = new BM25Scorer();
7705
- * const results = scorer.score(['hello'], index);
7706
- * // [{ docId: 'doc1', score: 0.28, matchedTerms: ['hello'] }, ...]
8075
+ * const exactResults = [
8076
+ * { docId: 'doc1', score: 1.0, source: 'exact' },
8077
+ * { docId: 'doc2', score: 1.0, source: 'exact' },
8078
+ * ];
8079
+ *
8080
+ * const ftsResults = [
8081
+ * { docId: 'doc2', score: 2.5, source: 'fulltext' },
8082
+ * { docId: 'doc3', score: 1.8, source: 'fulltext' },
8083
+ * ];
8084
+ *
8085
+ * const merged = rrf.merge([exactResults, ftsResults]);
8086
+ * // doc2 ranks highest (appears in both sets)
7707
8087
  * ```
7708
8088
  */
7709
- declare class BM25Scorer {
7710
- /**
7711
- * Term frequency saturation parameter.
7712
- * Higher values give more weight to repeated terms.
7713
- * Typical range: 1.2 - 2.0
7714
- */
7715
- private readonly k1;
7716
- /**
7717
- * Document length normalization parameter.
7718
- * 0 = no length normalization
7719
- * 1 = full length normalization
7720
- * Typical value: 0.75
7721
- */
7722
- private readonly b;
8089
+ declare class ReciprocalRankFusion {
8090
+ private readonly k;
8091
+ constructor(config?: RRFConfig);
7723
8092
  /**
7724
- * Create a new BM25 scorer.
8093
+ * Merge multiple ranked result lists using RRF.
7725
8094
  *
7726
- * @param options - BM25 configuration options
7727
- */
7728
- constructor(options?: BM25Options);
7729
- /**
7730
- * Score documents against a query.
8095
+ * Formula: RRF_score(d) = Σ 1 / (k + rank_i(d))
7731
8096
  *
7732
- * @param queryTerms - Array of query terms (already tokenized/stemmed)
7733
- * @param index - The inverted index to search
7734
- * @returns Array of scored documents, sorted by relevance (descending)
8097
+ * @param resultSets - Array of ranked result lists from different search methods
8098
+ * @returns Merged results sorted by RRF score (descending)
7735
8099
  */
7736
- score(queryTerms: string[], index: BM25InvertedIndex): ScoredDocument[];
8100
+ merge(resultSets: RankedResult[][]): MergedResult[];
7737
8101
  /**
7738
- * Score a single document against query terms.
7739
- * Uses pre-computed IDF from index but calculates TF locally.
8102
+ * Merge with weighted RRF for different method priorities.
7740
8103
  *
7741
- * Complexity: O(Q × D) where Q = query terms, D = document tokens
8104
+ * Weighted formula: RRF_score(d) = Σ weight_i * (1 / (k + rank_i(d)))
7742
8105
  *
7743
- * @param queryTerms - Tokenized query terms
7744
- * @param docTokens - Tokenized document terms
7745
- * @param index - Inverted index for IDF and avgDocLength
7746
- * @returns BM25 score (0 if no matching terms)
7747
- */
7748
- scoreSingleDocument(queryTerms: string[], docTokens: string[], index: BM25InvertedIndex): number;
7749
- /**
7750
- * Get the k1 parameter value.
8106
+ * @param resultSets - Array of ranked result lists
8107
+ * @param weights - Weights for each result set (same order as resultSets)
8108
+ * @returns Merged results sorted by weighted RRF score (descending)
8109
+ *
8110
+ * @example
8111
+ * ```typescript
8112
+ * const rrf = new ReciprocalRankFusion();
8113
+ *
8114
+ * // Prioritize exact matches (weight 2.0) over FTS (weight 1.0)
8115
+ * const merged = rrf.mergeWeighted(
8116
+ * [exactResults, ftsResults],
8117
+ * [2.0, 1.0]
8118
+ * );
8119
+ * ```
7751
8120
  */
7752
- getK1(): number;
8121
+ mergeWeighted(resultSets: RankedResult[][], weights: number[]): MergedResult[];
7753
8122
  /**
7754
- * Get the b parameter value.
8123
+ * Get the k constant used for RRF calculation.
7755
8124
  */
7756
- getB(): number;
8125
+ getK(): number;
7757
8126
  }
7758
8127
 
7759
- export { type Attribute, AuthMessageSchema, type BM25Options, BM25Scorer, type BatchMessage, BatchMessageSchema, BuiltInProcessors, BuiltInResolvers, type CircuitBreakerConfig, type ClientOp, ClientOpMessageSchema, ClientOpSchema, type ClusterClientConfig, type ClusterEvents, type ReadOptions as ClusterReadOptions, type WriteOptions as ClusterWriteOptions, type CompareFn, type ConflictResolver, type ConflictResolverDef, ConflictResolverDefSchema, type ConflictResolverFn, ConflictResolverSchema, type ConnectionPoolConfig, type ConnectionState, ConsistencyLevel, CounterRequestSchema, CounterResponseSchema, CounterSyncSchema, CounterUpdateSchema, DEFAULT_BACKUP_COUNT, DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_EVENT_JOURNAL_CONFIG, DEFAULT_MIGRATION_CONFIG, DEFAULT_PARTITION_ROUTER_CONFIG, DEFAULT_PROCESSOR_RATE_LIMITS, DEFAULT_REPLICATION_CONFIG, DEFAULT_RESOLVER_RATE_LIMITS, DEFAULT_STOP_WORDS, DEFAULT_WRITE_CONCERN_TIMEOUT, ENGLISH_STOPWORDS, type EntryProcessBatchRequest, EntryProcessBatchRequestSchema, type EntryProcessBatchResponse, EntryProcessBatchResponseSchema, type EntryProcessKeyResult, EntryProcessKeyResultSchema, type EntryProcessRequest, EntryProcessRequestSchema, type EntryProcessResponse, EntryProcessResponseSchema, type EntryProcessorDef, EntryProcessorDefSchema, type EntryProcessorFn, type EntryProcessorResult, EntryProcessorSchema, type EventJournal, type EventJournalConfig, EventJournalImpl, FORBIDDEN_PATTERNS, BM25InvertedIndex as FTSInvertedIndex, type SearchOptions as FTSSearchOptions, type SearchResult as FTSSearchResult, BM25Tokenizer as FTSTokenizer, type TokenizerOptions as FTSTokenizerOptions, FallbackIndex, type FilterStep, FilteringResultSet, type FullScanStep, FullTextIndex, type FullTextIndexConfig, HLC, HashIndex, type Index, type IndexQuery, IndexRegistry, type IndexRegistryStats, type IndexScanStep, type IndexStats, IndexedLWWMap, IndexedORMap, IntersectionResultSet, type IntersectionStep, InvertedIndex, type InvertedIndexStats, type IteratorFactory, type JournalEvent, type JournalEventData, JournalEventDataSchema, type JournalEventInput, type JournalEventListener, type JournalEventMessage, JournalEventMessageSchema, type JournalEventType, JournalEventTypeSchema, type JournalReadRequest, JournalReadRequestSchema, type JournalReadResponse, JournalReadResponseSchema, type JournalSubscribeRequest, JournalSubscribeRequestSchema, type JournalUnsubscribeRequest, JournalUnsubscribeRequestSchema, LWWMap, type LWWRecord, LWWRecordSchema, LazyResultSet, LimitResultSet, type ListResolversRequest, ListResolversRequestSchema, type ListResolversResponse, ListResolversResponseSchema, type LiveQueryCallback, type LiveQueryDeltaEvent, type LiveQueryEvent, type LiveQueryInitialEvent, LiveQueryManager, type LiveQueryManagerOptions, type LiveQueryManagerStats, LockReleaseSchema, LockRequestSchema, type LogicalQueryNode, LowercaseFilter, MaxLengthFilter, type MergeContext, type MergeKeyResult, type MergeRejectedMessage, MergeRejectedMessageSchema, type MergeRejection, type MergeResult, MerkleReqBucketMessageSchema, MerkleTree, type Message, MessageSchema, type MigrationChunkAckMessage, type MigrationChunkMessage, type MigrationCompleteMessage, type MigrationConfig, type MigrationMessage, type MigrationMetrics, type MigrationStartMessage, type MigrationStatus, type MigrationVerifyMessage, MinLengthFilter, MultiValueAttribute, NGramTokenizer, NavigableIndex, type NodeHealth, type NodeInfo, type NodeStatus, type NotOwnerError, type NotStep, ORMap, ORMapDiffRequestSchema, ORMapDiffResponseSchema, type ORMapMerkleNode, ORMapMerkleReqBucketSchema, ORMapMerkleTree, ORMapPushDiffSchema, type ORMapQueryResult, type ORMapRecord, ORMapRecordSchema, type ORMapSearchResult, type ORMapSnapshot, ORMapSyncInitSchema, ORMapSyncRespBucketsSchema, ORMapSyncRespLeafSchema, ORMapSyncRespRootSchema, type OpAckMessage, OpAckMessageSchema, OpBatchMessageSchema, type OpRejectedMessage, OpRejectedMessageSchema, type OpResult, OpResultSchema, PARTITION_COUNT, type PNCounter, type PNCounterConfig, PNCounterImpl, type PNCounterState, type PNCounterStateObject, PNCounterStateObjectSchema, type PartitionChange, type PartitionInfo, type PartitionMap, type PartitionMapDeltaMessage, type PartitionMapMessage, type PartitionMapRequestMessage, PartitionMapRequestSchema, type PartitionMigration, type PartitionRouterConfig, PartitionState, type PendingWrite, type PermissionPolicy, type PermissionType, type PingMessage, PingMessageSchema, type PlanStep, type PongMessage, PongMessageSchema, type Posting, type PredicateFn, type PredicateNode, PredicateNodeSchema, type PredicateOp, PredicateOpSchema, Predicates, type Principal, type ProcessorRateLimitConfig, type Query$1 as Query, type Query as QueryExpression, type QueryNode, QueryOptimizer, type QueryOptimizerOptions, type QueryOptions, type QueryPlan, QuerySchema, QuerySubMessageSchema, QueryUnsubMessageSchema, RESOLVER_FORBIDDEN_PATTERNS, type RegisterResolverRequest, RegisterResolverRequestSchema, type RegisterResolverResponse, RegisterResolverResponseSchema, type ReplicationAckMessage, type ReplicationBatchAckMessage, type ReplicationBatchMessage, type ReplicationConfig, type ReplicationHealth, type ReplicationLag, type ReplicationMessage, type ReplicationProtocolMessage, type ReplicationResult, type ReplicationTask, type ResolverRateLimitConfig, type ResultSet, Ringbuffer, type RoutingError, type ScoredDocument, type SearchMessage, SearchMessageSchema, type SearchOptions$1 as SearchOptions, SearchOptionsSchema, type SearchPayload, SearchPayloadSchema, type SearchRespMessage, SearchRespMessageSchema, type SearchRespPayload, SearchRespPayloadSchema, type SearchSubMessage, SearchSubMessageSchema, type SearchSubPayload, SearchSubPayloadSchema, type SearchUnsubMessage, SearchUnsubMessageSchema, type SearchUnsubPayload, SearchUnsubPayloadSchema, type SearchUpdateMessage, SearchUpdateMessageSchema, type SearchUpdatePayload, SearchUpdatePayloadSchema, type SearchUpdateType, SearchUpdateTypeSchema, type SerializedIndex, SetResultSet, SimpleAttribute, type SimpleQueryNode, SortedMap, SortedResultSet, type StaleMapError, type StandingQueryChange, StandingQueryIndex, type StandingQueryIndexOptions, StandingQueryRegistry, type StandingQueryRegistryOptions, type StandingQueryRegistryStats, StopWordFilter, SyncInitMessageSchema, SyncRespBucketsMessageSchema, SyncRespLeafMessageSchema, SyncRespRootMessageSchema, type TermInfo, type Timestamp, TimestampSchema, type TokenFilter, TokenizationPipeline, type TokenizationPipelineOptions, type Tokenizer, TopicMessageEventSchema, TopicPubSchema, TopicSubSchema, TopicUnsubSchema, TrimFilter, UnionResultSet, type UnionStep, UniqueFilter, type UnregisterResolverRequest, UnregisterResolverRequestSchema, type UnregisterResolverResponse, UnregisterResolverResponseSchema, WRITE_CONCERN_ORDER, WhitespaceTokenizer, WordBoundaryTokenizer, WriteConcern, WriteConcernSchema, type WriteConcernValue, type WriteOptions$1 as WriteOptions, type WriteResult, combineHashes, compareHLCTimestamps, compareTimestamps, createFieldComparator, createPredicateMatcher, deepMerge, deserialize, disableNativeHash, evaluatePredicate, getHighestWriteConcernLevel, hashORMapEntry, hashORMapRecord, hashString, isLogicalQuery, isSimpleQuery, isUsingNativeHash, isWriteConcernAchieved, multiAttribute, porterStem, resetNativeHash, serialize, simpleAttribute, timestampToString, validateProcessorCode, validateResolverCode };
8128
+ export { type Attribute, AuthMessageSchema, type BM25Options, BM25Scorer, type BatchMessage, BatchMessageSchema, BuiltInProcessors, BuiltInResolvers, type CircuitBreakerConfig, type ClientOp, ClientOpMessageSchema, ClientOpSchema, type ClusterClientConfig, type ClusterEvents, type ReadOptions as ClusterReadOptions, type WriteOptions as ClusterWriteOptions, type CompareFn, type ConflictResolver, type ConflictResolverDef, ConflictResolverDefSchema, type ConflictResolverFn, ConflictResolverSchema, type ConnectionPoolConfig, type ConnectionState, ConsistencyLevel, CounterRequestSchema, CounterResponseSchema, CounterSyncSchema, CounterUpdateSchema, DEFAULT_BACKUP_COUNT, DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_CONNECTION_POOL_CONFIG, DEFAULT_EVENT_JOURNAL_CONFIG, DEFAULT_MIGRATION_CONFIG, DEFAULT_PARTITION_ROUTER_CONFIG, DEFAULT_PROCESSOR_RATE_LIMITS, DEFAULT_REPLICATION_CONFIG, DEFAULT_RESOLVER_RATE_LIMITS, DEFAULT_STOP_WORDS, DEFAULT_WRITE_CONCERN_TIMEOUT, ENGLISH_STOPWORDS, type EntryProcessBatchRequest, EntryProcessBatchRequestSchema, type EntryProcessBatchResponse, EntryProcessBatchResponseSchema, type EntryProcessKeyResult, EntryProcessKeyResultSchema, type EntryProcessRequest, EntryProcessRequestSchema, type EntryProcessResponse, EntryProcessResponseSchema, type EntryProcessorDef, EntryProcessorDefSchema, type EntryProcessorFn, type EntryProcessorResult, EntryProcessorSchema, type EventJournal, type EventJournalConfig, EventJournalImpl, FORBIDDEN_PATTERNS, BM25InvertedIndex as FTSInvertedIndex, type SearchOptions as FTSSearchOptions, type SearchResult as FTSSearchResult, BM25Tokenizer as FTSTokenizer, type TokenizerOptions as FTSTokenizerOptions, FallbackIndex, type FilterStep, FilteringResultSet, type FullScanStep, FullTextIndex, type FullTextIndexConfig, HLC, HashIndex, type Index, type IndexQuery, IndexRegistry, type IndexRegistryStats, type IndexScanStep, type IndexStats, IndexedLWWMap, IndexedORMap, IntersectionResultSet, type IntersectionStep, InvertedIndex, type InvertedIndexStats, type IteratorFactory, type JournalEvent, type JournalEventData, JournalEventDataSchema, type JournalEventInput, type JournalEventListener, type JournalEventMessage, JournalEventMessageSchema, type JournalEventType, JournalEventTypeSchema, type JournalReadRequest, JournalReadRequestSchema, type JournalReadResponse, JournalReadResponseSchema, type JournalSubscribeRequest, JournalSubscribeRequestSchema, type JournalUnsubscribeRequest, JournalUnsubscribeRequestSchema, LWWMap, type LWWRecord, LWWRecordSchema, LazyResultSet, LimitResultSet, type ListResolversRequest, ListResolversRequestSchema, type ListResolversResponse, ListResolversResponseSchema, type LiveQueryCallback, type LiveQueryDeltaEvent, type LiveQueryEvent, type LiveQueryInitialEvent, LiveQueryManager, type LiveQueryManagerOptions, type LiveQueryManagerStats, LockReleaseSchema, LockRequestSchema, type LogicalQueryNode, LowercaseFilter, type MatchOptions, MaxLengthFilter, type MergeContext, type MergeKeyResult, type MergeRejectedMessage, MergeRejectedMessageSchema, type MergeRejection, type MergeResult, type MergedResult, MerkleReqBucketMessageSchema, MerkleTree, type Message, MessageSchema, type MigrationChunkAckMessage, type MigrationChunkMessage, type MigrationCompleteMessage, type MigrationConfig, type MigrationMessage, type MigrationMetrics, type MigrationStartMessage, type MigrationStatus, type MigrationVerifyMessage, MinLengthFilter, MultiValueAttribute, NGramTokenizer, NavigableIndex, type NodeHealth, type NodeInfo, type NodeStatus, type NotOwnerError, type NotStep, ORMap, ORMapDiffRequestSchema, ORMapDiffResponseSchema, type ORMapMerkleNode, ORMapMerkleReqBucketSchema, ORMapMerkleTree, ORMapPushDiffSchema, type ORMapQueryResult, type ORMapRecord, ORMapRecordSchema, type ORMapSearchResult, type ORMapSnapshot, ORMapSyncInitSchema, ORMapSyncRespBucketsSchema, ORMapSyncRespLeafSchema, ORMapSyncRespRootSchema, type OpAckMessage, OpAckMessageSchema, OpBatchMessageSchema, type OpRejectedMessage, OpRejectedMessageSchema, type OpResult, OpResultSchema, PARTITION_COUNT, type PNCounter, type PNCounterConfig, PNCounterImpl, type PNCounterState, type PNCounterStateObject, PNCounterStateObjectSchema, type PartitionChange, type PartitionInfo, type PartitionMap, type PartitionMapDeltaMessage, type PartitionMapMessage, type PartitionMapRequestMessage, PartitionMapRequestSchema, type PartitionMigration, type PartitionRouterConfig, PartitionState, type PendingWrite, type PermissionPolicy, type PermissionType, type PingMessage, PingMessageSchema, type PlanStep, type PongMessage, PongMessageSchema, type Posting, type PredicateFn, type PredicateNode, PredicateNodeSchema, type PredicateOp, PredicateOpSchema, Predicates, type Principal, type ProcessorRateLimitConfig, type Query$1 as Query, type Query as QueryExpression, type QueryNode, QueryOptimizer, type QueryOptimizerOptions, type QueryOptions, type QueryPlan, QuerySchema, QuerySubMessageSchema, QueryUnsubMessageSchema, RESOLVER_FORBIDDEN_PATTERNS, type RRFConfig, type RankedResult, ReciprocalRankFusion, type RegisterResolverRequest, RegisterResolverRequestSchema, type RegisterResolverResponse, RegisterResolverResponseSchema, type ReplicationAckMessage, type ReplicationBatchAckMessage, type ReplicationBatchMessage, type ReplicationConfig, type ReplicationHealth, type ReplicationLag, type ReplicationMessage, type ReplicationProtocolMessage, type ReplicationResult, type ReplicationTask, type ResolverRateLimitConfig, type ResultSet, Ringbuffer, type RoutingError, type ScoredDocument, type SearchMessage, SearchMessageSchema, type SearchOptions$1 as SearchOptions, SearchOptionsSchema, type SearchPayload, SearchPayloadSchema, type SearchRespMessage, SearchRespMessageSchema, type SearchRespPayload, SearchRespPayloadSchema, type SearchSubMessage, SearchSubMessageSchema, type SearchSubPayload, SearchSubPayloadSchema, type SearchUnsubMessage, SearchUnsubMessageSchema, type SearchUnsubPayload, SearchUnsubPayloadSchema, type SearchUpdateMessage, SearchUpdateMessageSchema, type SearchUpdatePayload, SearchUpdatePayloadSchema, type SearchUpdateType, SearchUpdateTypeSchema, type SerializedIndex, SetResultSet, SimpleAttribute, type SimpleQueryNode, SortedMap, SortedResultSet, type StaleMapError, type StandingQueryChange, StandingQueryIndex, type StandingQueryIndexOptions, StandingQueryRegistry, type StandingQueryRegistryOptions, type StandingQueryRegistryStats, StopWordFilter, SyncInitMessageSchema, SyncRespBucketsMessageSchema, SyncRespLeafMessageSchema, SyncRespRootMessageSchema, type TermInfo, type Timestamp, TimestampSchema, type TokenFilter, TokenizationPipeline, type TokenizationPipelineOptions, type Tokenizer, TopicMessageEventSchema, TopicPubSchema, TopicSubSchema, TopicUnsubSchema, TrimFilter, UnionResultSet, type UnionStep, UniqueFilter, type UnregisterResolverRequest, UnregisterResolverRequestSchema, type UnregisterResolverResponse, UnregisterResolverResponseSchema, WRITE_CONCERN_ORDER, WhitespaceTokenizer, WordBoundaryTokenizer, WriteConcern, WriteConcernSchema, type WriteConcernValue, type WriteOptions$1 as WriteOptions, type WriteResult, combineHashes, compareHLCTimestamps, compareTimestamps, createFieldComparator, createPredicateMatcher, deepMerge, deserialize, disableNativeHash, evaluatePredicate, getHighestWriteConcernLevel, hashORMapEntry, hashORMapRecord, hashString, isLogicalQuery, isSimpleQuery, isUsingNativeHash, isWriteConcernAchieved, multiAttribute, porterStem, resetNativeHash, serialize, simpleAttribute, timestampToString, validateProcessorCode, validateResolverCode };