@denizsvnc/ai-rag-engine 2.2.1 → 2.2.3

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.
@@ -11,17 +11,53 @@ export interface EmbeddingExtractor {
11
11
  export declare class CircuitBreakerOpenError extends Error {
12
12
  constructor(message: string);
13
13
  }
14
+ /**
15
+ * Industry-standard ONNX embedding model presets for the Small Machine Learning (SML) engine.
16
+ * Powered by `@huggingface/transformers` without requiring Python or external API keys.
17
+ */
18
+ export declare const SMLModelPresets: {
19
+ /**
20
+ * Ultra-fast English embedding model (~30MB q8 ONNX).
21
+ * Ideal for English-only workloads, low-latency semantic routing, and minimal RAM footprint.
22
+ */
23
+ readonly ENGLISH_FAST: 'Xenova/all-MiniLM-L6-v2';
24
+ /**
25
+ * Highly recommended balanced multilingual model (~117MB q8 ONNX).
26
+ * Provides exceptional semantic similarity across 50+ languages including Turkish, German, English, French, and Spanish.
27
+ */
28
+ readonly MULTILINGUAL: 'Xenova/paraphrase-multilingual-MiniLM-L12-v2';
29
+ /**
30
+ * Heavyweight high-accuracy multilingual foundation model (1024-dim, long context, 100+ languages).
31
+ * Highest precision across mixed-language corpora, but requires higher memory and CPU allocation.
32
+ */
33
+ readonly MULTILINGUAL_ACCURATE: 'Xenova/bge-m3';
34
+ };
35
+ export type SMLModelPreset = typeof SMLModelPresets[keyof typeof SMLModelPresets];
14
36
  export interface SMLEngineConfig {
37
+ /** Directory where downloaded ONNX models are cached. Defaults to process.env.RAG_MODEL_CACHE_DIR or './data/models'. */
15
38
  cacheDir?: string | undefined;
39
+ /** When true, only loads models already present on local disk and prevents external network fetching. */
16
40
  localFilesOnly?: boolean | undefined;
17
- modelName?: string | undefined;
41
+ /**
42
+ * Hugging Face ONNX model identifier.
43
+ * Use a preset (e.g. `SMLModelPresets.MULTILINGUAL`) or pass any custom HuggingFace model string (e.g. `'my-org/my-custom-model'`).
44
+ * Defaults to `'Xenova/all-MiniLM-L6-v2'`.
45
+ */
46
+ modelName?: string | SMLModelPreset | undefined;
47
+ /** Maximum number of precomputed query/document embeddings retained in RAM LRU cache. Defaults to 1000. */
18
48
  cacheSize?: number | undefined;
49
+ /** Model quantization data type: 'q8' (default), 'fp32', 'fp16', or 'q4'. */
19
50
  dtype?: 'q8' | 'fp32' | 'fp16' | 'q4' | undefined;
51
+ /** Legacy flag for quantization: false forces 'fp32'. */
20
52
  quantized?: boolean | undefined;
53
+ /** Number of consecutive load failures before tripping the circuit breaker OPEN. Defaults to 3. */
21
54
  circuitBreakerThreshold?: number | undefined;
55
+ /** Cooldown period in milliseconds before re-testing model recovery. Defaults to 15000 (15s). */
22
56
  circuitBreakerCooldownMs?: number | undefined;
23
57
  }
24
58
  export declare class SMLEngine {
59
+ private static initLockChain;
60
+ private static acquireInitLock;
25
61
  private readonly modelName;
26
62
  private readonly cacheDir;
27
63
  private readonly localFilesOnly;
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export * from './interfaces/cache.interface.js';
8
8
  export * from './interfaces/llm.interface.js';
9
9
  export * from './core/security/security.types.js';
10
10
  export { RAGEngine } from './core/engine.js';
11
- export { SMLEngine, type SMLEngineConfig, type EmbeddingExtractor, CircuitBreakerOpenError } from './core/sml-engine.js';
11
+ export { SMLEngine, SMLModelPresets, type SMLModelPreset, type SMLEngineConfig, type EmbeddingExtractor, CircuitBreakerOpenError } from './core/sml-engine.js';
12
12
  export { ToolRegistry } from './core/tool-registry.js';
13
13
  export { CacheManager } from './core/cache-manager.js';
14
14
  export { PromptBuilder, type PromptContext } from './core/prompt-builder.js';
@@ -31,15 +31,15 @@ export { RedisCacheAdapter, type IRedisClientLike, type RedisCacheOptions } from
31
31
  export { createRagMiddleware } from './api/middleware.js';
32
32
  export { createApiRoutes, type ApiRouteOptions } from './api/routes.js';
33
33
  export { createAuthToken, verifyAuthToken, createAuthMiddleware, requireRoles, type AuthTokenPayload, type AuthMiddlewareOptions } from './api/auth.js';
34
- export { OpenAIAdapter } from './adapters/llm/openai.adapter.js';
35
- export { GeminiAdapter } from './adapters/llm/gemini.adapter.js';
36
- export { OpenRouterAdapter } from './adapters/llm/openrouter.adapter.js';
34
+ export { OpenAIAdapter, type OpenAIConfig } from './adapters/llm/openai.adapter.js';
35
+ export { GeminiAdapter, type GeminiConfig } from './adapters/llm/gemini.adapter.js';
36
+ export { OpenRouterAdapter, type OpenRouterConfig } from './adapters/llm/openrouter.adapter.js';
37
37
  export { CustomLLMAdapter, type CustomLLMConfig } from './adapters/llm/custom.adapter.js';
38
38
  export { OllamaAdapter, type OllamaConfig } from './adapters/llm/ollama.adapter.js';
39
39
  export { FallbackLLMProvider, type FallbackProviderOptions } from './adapters/llm/fallback.adapter.js';
40
40
  export { TieredLLMProvider, type TieredLLMConfig } from './adapters/llm/tiered.adapter.js';
41
41
  export { MemoryVectorAdapter } from './adapters/vector/memory-vector.adapter.js';
42
- export { StaticRulesAdapter } from './adapters/rules/static-rules.adapter.js';
42
+ export { StaticRulesAdapter, type RuleInput } from './adapters/rules/static-rules.adapter.js';
43
43
  export { UrlFaqAdapter } from './adapters/faq/url-faq.adapter.js';
44
44
  export { LocalFaqAdapter, type LocalFaqAdapterOptions } from './adapters/faq/local-faq.adapter.js';
45
45
  export { RedisConfirmationNonceStore, MemoryConfirmationNonceStore, type ConfirmationNonceStore } from './core/security/nonce-store.js';