@delali/narsil 0.1.6 → 0.1.7

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.ts CHANGED
@@ -1,46 +1,6 @@
1
1
  import { L as LanguageModule } from './language-ClUGLuoC.js';
2
- import { P as PersistenceAdapter, I as InvalidationAdapter } from './adapters-XODT2F3h.js';
3
- export { a as InvalidationEvent, b as PartitionStatistics } from './adapters-XODT2F3h.js';
4
-
5
- declare const ErrorCodes: {
6
- readonly SCHEMA_INVALID_TYPE: "SCHEMA_INVALID_TYPE";
7
- readonly SCHEMA_MISSING_FIELD: "SCHEMA_MISSING_FIELD";
8
- readonly SCHEMA_DEPTH_EXCEEDED: "SCHEMA_DEPTH_EXCEEDED";
9
- readonly SCHEMA_INVALID_VECTOR_DIMENSION: "SCHEMA_INVALID_VECTOR_DIMENSION";
10
- readonly SCHEMA_INVALID_GEOPOINT: "SCHEMA_INVALID_GEOPOINT";
11
- readonly DOC_NOT_FOUND: "DOC_NOT_FOUND";
12
- readonly DOC_ALREADY_EXISTS: "DOC_ALREADY_EXISTS";
13
- readonly DOC_VALIDATION_FAILED: "DOC_VALIDATION_FAILED";
14
- readonly INDEX_NOT_FOUND: "INDEX_NOT_FOUND";
15
- readonly INDEX_ALREADY_EXISTS: "INDEX_ALREADY_EXISTS";
16
- readonly PARTITION_CORRUPTED: "PARTITION_CORRUPTED";
17
- readonly PARTITION_REBALANCING_BACKPRESSURE: "PARTITION_REBALANCING_BACKPRESSURE";
18
- readonly WORKER_CRASHED: "WORKER_CRASHED";
19
- readonly WORKER_BUSY: "WORKER_BUSY";
20
- readonly WORKER_TIMEOUT: "WORKER_TIMEOUT";
21
- readonly PERSISTENCE_SAVE_FAILED: "PERSISTENCE_SAVE_FAILED";
22
- readonly PERSISTENCE_LOAD_FAILED: "PERSISTENCE_LOAD_FAILED";
23
- readonly PERSISTENCE_DELETE_FAILED: "PERSISTENCE_DELETE_FAILED";
24
- readonly PERSISTENCE_CRC_MISMATCH: "PERSISTENCE_CRC_MISMATCH";
25
- readonly SEARCH_INVALID_FIELD: "SEARCH_INVALID_FIELD";
26
- readonly SEARCH_INVALID_VECTOR_SIZE: "SEARCH_INVALID_VECTOR_SIZE";
27
- readonly SEARCH_INVALID_FILTER: "SEARCH_INVALID_FILTER";
28
- readonly SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE";
29
- readonly SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR";
30
- readonly LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED";
31
- readonly ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH";
32
- readonly ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC";
33
- readonly PARTITION_CAPACITY_EXCEEDED: "PARTITION_CAPACITY_EXCEEDED";
34
- };
35
- type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
36
- declare class NarsilError extends Error {
37
- readonly code: ErrorCode;
38
- readonly details: Record<string, unknown>;
39
- constructor(code: ErrorCode, message: string, details?: Record<string, unknown>);
40
- }
41
-
42
- declare function registerLanguage(module: LanguageModule): void;
43
- declare function getLanguage(name: string): LanguageModule;
2
+ import { E as EmbeddingAdapter, P as PersistenceAdapter, I as InvalidationAdapter } from './adapters-BbRkoiu9.js';
3
+ export { a as InvalidationEvent, b as PartitionStatistics } from './adapters-BbRkoiu9.js';
44
4
 
45
5
  type AnyDocument = Record<string, unknown> & {
46
6
  id?: string;
@@ -49,14 +9,20 @@ type FieldType = 'string' | 'number' | 'boolean' | 'enum' | 'geopoint' | `vector
49
9
  type SchemaDefinition = {
50
10
  [field: string]: FieldType | SchemaDefinition;
51
11
  };
52
- interface VectorPromotionConfig {
12
+ type VectorQuantizationMode = 'sq8' | 'none';
13
+ interface VectorIndexConfig {
53
14
  threshold?: number;
15
+ filterThreshold?: number;
54
16
  hnswConfig?: {
55
17
  m?: number;
56
18
  efConstruction?: number;
57
19
  metric?: 'cosine' | 'dotProduct' | 'euclidean';
58
20
  };
59
- workerStrategy?: 'worker-threads' | 'web-worker' | 'synchronous';
21
+ quantization?: VectorQuantizationMode;
22
+ }
23
+ interface EmbeddingFieldConfig {
24
+ adapter?: EmbeddingAdapter;
25
+ fields: Record<string, string | string[]>;
60
26
  }
61
27
  interface IndexConfig {
62
28
  schema: SchemaDefinition;
@@ -67,8 +33,10 @@ interface IndexConfig {
67
33
  stopWords?: Set<string> | ((defaults: Set<string>) => Set<string>);
68
34
  tokenizer?: CustomTokenizer;
69
35
  trackPositions?: boolean;
70
- vectorPromotion?: VectorPromotionConfig;
36
+ vectorPromotion?: VectorIndexConfig;
71
37
  strict?: boolean;
38
+ embedding?: EmbeddingFieldConfig;
39
+ required?: string[];
72
40
  }
73
41
  interface BM25Params {
74
42
  k1?: number;
@@ -89,6 +57,58 @@ interface InsertOptions {
89
57
  skipClone?: boolean;
90
58
  }
91
59
 
60
+ declare function configureNormalizationCache(maxSize: number): void;
61
+ declare function clearNormalizationCache(): void;
62
+ declare function resetNormalizationCache(): void;
63
+ declare function getNormalizationCacheSize(): number;
64
+
65
+ declare const ErrorCodes: {
66
+ readonly SCHEMA_INVALID_TYPE: "SCHEMA_INVALID_TYPE";
67
+ readonly SCHEMA_MISSING_FIELD: "SCHEMA_MISSING_FIELD";
68
+ readonly SCHEMA_DEPTH_EXCEEDED: "SCHEMA_DEPTH_EXCEEDED";
69
+ readonly SCHEMA_INVALID_VECTOR_DIMENSION: "SCHEMA_INVALID_VECTOR_DIMENSION";
70
+ readonly SCHEMA_INVALID_GEOPOINT: "SCHEMA_INVALID_GEOPOINT";
71
+ readonly DOC_NOT_FOUND: "DOC_NOT_FOUND";
72
+ readonly DOC_ALREADY_EXISTS: "DOC_ALREADY_EXISTS";
73
+ readonly DOC_VALIDATION_FAILED: "DOC_VALIDATION_FAILED";
74
+ readonly INDEX_NOT_FOUND: "INDEX_NOT_FOUND";
75
+ readonly INDEX_ALREADY_EXISTS: "INDEX_ALREADY_EXISTS";
76
+ readonly PARTITION_CORRUPTED: "PARTITION_CORRUPTED";
77
+ readonly PARTITION_REBALANCING_BACKPRESSURE: "PARTITION_REBALANCING_BACKPRESSURE";
78
+ readonly WORKER_CRASHED: "WORKER_CRASHED";
79
+ readonly WORKER_BUSY: "WORKER_BUSY";
80
+ readonly WORKER_TIMEOUT: "WORKER_TIMEOUT";
81
+ readonly PERSISTENCE_SAVE_FAILED: "PERSISTENCE_SAVE_FAILED";
82
+ readonly PERSISTENCE_LOAD_FAILED: "PERSISTENCE_LOAD_FAILED";
83
+ readonly PERSISTENCE_DELETE_FAILED: "PERSISTENCE_DELETE_FAILED";
84
+ readonly PERSISTENCE_CRC_MISMATCH: "PERSISTENCE_CRC_MISMATCH";
85
+ readonly SEARCH_INVALID_FIELD: "SEARCH_INVALID_FIELD";
86
+ readonly SEARCH_INVALID_VECTOR_SIZE: "SEARCH_INVALID_VECTOR_SIZE";
87
+ readonly VECTOR_DIMENSION_MISMATCH: "VECTOR_DIMENSION_MISMATCH";
88
+ readonly SEARCH_INVALID_FILTER: "SEARCH_INVALID_FILTER";
89
+ readonly SEARCH_INVALID_MODE: "SEARCH_INVALID_MODE";
90
+ readonly SEARCH_INVALID_CURSOR: "SEARCH_INVALID_CURSOR";
91
+ readonly LANGUAGE_NOT_SUPPORTED: "LANGUAGE_NOT_SUPPORTED";
92
+ readonly ENVELOPE_VERSION_MISMATCH: "ENVELOPE_VERSION_MISMATCH";
93
+ readonly ENVELOPE_INVALID_MAGIC: "ENVELOPE_INVALID_MAGIC";
94
+ readonly PARTITION_CAPACITY_EXCEEDED: "PARTITION_CAPACITY_EXCEEDED";
95
+ readonly EMBEDDING_FAILED: "EMBEDDING_FAILED";
96
+ readonly EMBEDDING_DIMENSION_MISMATCH: "EMBEDDING_DIMENSION_MISMATCH";
97
+ readonly EMBEDDING_NO_SOURCE: "EMBEDDING_NO_SOURCE";
98
+ readonly EMBEDDING_CONFIG_INVALID: "EMBEDDING_CONFIG_INVALID";
99
+ readonly DOC_MISSING_REQUIRED_FIELD: "DOC_MISSING_REQUIRED_FIELD";
100
+ readonly CONFIG_INVALID: "CONFIG_INVALID";
101
+ };
102
+ type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
103
+ declare class NarsilError extends Error {
104
+ readonly code: ErrorCode;
105
+ readonly details: Record<string, unknown>;
106
+ constructor(code: ErrorCode, message: string, details?: Record<string, unknown>);
107
+ }
108
+
109
+ declare function registerLanguage(module: LanguageModule): void;
110
+ declare function getLanguage(name: string): LanguageModule;
111
+
92
112
  interface QueryResult<T = AnyDocument> {
93
113
  hits: Array<Hit<T>>;
94
114
  count: number;
@@ -153,8 +173,6 @@ interface PartitionStatsResult {
153
173
  partitionId: number;
154
174
  documentCount: number;
155
175
  estimatedMemoryBytes: number;
156
- vectorFieldCount: number;
157
- isHnswPromoted: boolean;
158
176
  }
159
177
  interface SuggestResult {
160
178
  terms: Array<{
@@ -172,6 +190,15 @@ interface MemoryStats {
172
190
  external: number;
173
191
  }>;
174
192
  }
193
+ interface VectorMaintenanceResult {
194
+ fieldName: string;
195
+ tombstoneRatio: number;
196
+ graphCount: number;
197
+ bufferSize: number;
198
+ building: boolean;
199
+ estimatedCompactMs: number;
200
+ estimatedOptimizeMs: number;
201
+ }
175
202
 
176
203
  type ComparisonFilter = {
177
204
  eq?: number | string | boolean;
@@ -258,12 +285,15 @@ interface QueryParams {
258
285
  }
259
286
  interface VectorQueryConfig {
260
287
  field: string;
261
- value: number[];
288
+ value?: number[];
289
+ text?: string;
262
290
  similarity?: number;
263
291
  metric?: 'cosine' | 'dotProduct' | 'euclidean';
264
292
  efSearch?: number;
265
293
  }
266
294
  interface HybridConfig {
295
+ strategy?: 'rrf' | 'linear';
296
+ k?: number;
267
297
  alpha?: number;
268
298
  }
269
299
  interface FacetConfig {
@@ -353,6 +383,7 @@ interface NarsilConfig {
353
383
  workers?: WorkerConfig;
354
384
  flush?: FlushConfig;
355
385
  eagerLoad?: boolean;
386
+ embedding?: EmbeddingAdapter;
356
387
  }
357
388
  interface WorkerConfig {
358
389
  enabled?: boolean;
@@ -416,6 +447,9 @@ interface Narsil {
416
447
  rebalance(indexName: string, targetPartitionCount: number): Promise<void>;
417
448
  updatePartitionConfig(indexName: string, config: Partial<PartitionConfig>): Promise<void>;
418
449
  getMemoryStats(): MemoryStats;
450
+ compactVectors(indexName: string, fieldName?: string): Promise<void>;
451
+ optimizeVectors(indexName: string, fieldName?: string): Promise<void>;
452
+ vectorMaintenanceStatus(indexName: string): VectorMaintenanceResult[];
419
453
  on<K extends keyof NarsilEventMap>(event: K, handler: (payload: NarsilEventMap[K]) => void): void;
420
454
  off<K extends keyof NarsilEventMap>(event: K, handler: (payload: NarsilEventMap[K]) => void): void;
421
455
  shutdown(): Promise<void>;
@@ -426,4 +460,4 @@ declare function isSimdAvailable(): boolean;
426
460
 
427
461
  declare const VERSION = "0.1.0";
428
462
 
429
- export { type AnyDocument, type ArrayFilter, type BM25Params, type BatchResult, type ComparisonFilter, type CustomTokenizer, type ErrorCode, ErrorCodes, type FacetConfig, type FacetResult, type FieldType, type FilterExpression, type FlushConfig, type GeoPolygonFilter, type GeoRadiusFilter, type GroupConfig, type GroupReducer, type GroupResult, type HighlightConfig, type HighlightMatch, type Hit, type HybridConfig, type IndexConfig, type IndexContext, type IndexInfo, type IndexStats, type InsertContext, type InsertOptions, InvalidationAdapter, LanguageModule, type MemoryStats, type Narsil, type NarsilConfig, NarsilError, type NarsilEventMap, type NarsilPlugin, type PartitionConfig, type PartitionContext, type PartitionStatsResult, PersistenceAdapter, type PreflightResult, type PresenceFilter, type QueryParams, type QueryResult, type RemoveContext, type SchemaDefinition, type ScoreComponents, type ScoringMode, type SearchContext, type SearchMode, type StringFilter, type SuggestParams, type SuggestResult, type TermMatchPolicy, type UpdateContext, VERSION, type VectorQueryConfig, type WorkerConfig, type WorkerContext, createNarsil, getLanguage, isSimdAvailable, registerLanguage };
463
+ export { type AnyDocument, type ArrayFilter, type BM25Params, type BatchResult, type ComparisonFilter, type CustomTokenizer, EmbeddingAdapter, type EmbeddingFieldConfig, type ErrorCode, ErrorCodes, type FacetConfig, type FacetResult, type FieldType, type FilterExpression, type FlushConfig, type GeoPolygonFilter, type GeoRadiusFilter, type GroupConfig, type GroupReducer, type GroupResult, type HighlightConfig, type HighlightMatch, type Hit, type HybridConfig, type IndexConfig, type IndexContext, type IndexInfo, type IndexStats, type InsertContext, type InsertOptions, InvalidationAdapter, LanguageModule, type MemoryStats, type Narsil, type NarsilConfig, NarsilError, type NarsilEventMap, type NarsilPlugin, type PartitionConfig, type PartitionContext, type PartitionStatsResult, PersistenceAdapter, type PreflightResult, type PresenceFilter, type QueryParams, type QueryResult, type RemoveContext, type SchemaDefinition, type ScoreComponents, type ScoringMode, type SearchContext, type SearchMode, type StringFilter, type SuggestParams, type SuggestResult, type TermMatchPolicy, type UpdateContext, VERSION, type VectorMaintenanceResult, type VectorQueryConfig, type WorkerConfig, type WorkerContext, clearNormalizationCache, configureNormalizationCache, createNarsil, getLanguage, getNormalizationCacheSize, isSimdAvailable, registerLanguage, resetNormalizationCache };