@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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  This file follows Semantic Versioning.
4
4
 
5
+ ## 2.2.3 — 2026-11-10
6
+
7
+ ### Fixed
8
+
9
+ - **Transformers.js Concurrency Lock:** Implemented static Promise lock chain (`acquireInitLock`) in `SMLEngine` to serialize `init()` calls across independent instances and isolate mutable Transformers.js global `env`. Model inference remains fully concurrent.
10
+ - **LLM Adapter Constructor Flexibility:** Dual constructor signatures added to `GeminiAdapter`, `OpenAIAdapter`, and `OpenRouterAdapter` accepting both `{ apiKey, model, temperature }` configuration objects and positional parameters.
11
+ - **Document Chunking Bounds & Streaming UTF-8 Decoder:** Enforced `RangeError` on invalid chunk boundaries (`chunkSize > 0`, `overlap < chunkSize`). Added `StringDecoder('utf-8')` to prevent split multi-byte characters (e.g. Turkish `ş`, `ğ`) across stream chunks.
12
+ - **Native zlib PDF FlateDecode Ingestion:** Integrated Node's native `zlib.inflateSync` & `inflateRawSync` for zero-dependency decompression of vector PDF streams.
13
+ - **RAGEvaluator Heuristics & Polarity:** Ensured empty answers score 0.0; deduplicated retrieved IDs; added English & Turkish negation and polarity contradiction checks.
14
+
15
+ ### Added
16
+
17
+ - **Bun Runtime Compatibility:** Dedicated Bun test suite (`test/bun/bun-compat.test.ts`) and npm script `npm run test:bun` verifying ONNX embeddings, PII masking, vector math, and RAG execution under Bun v1.4.4+.
18
+ - **CI Workflow Hardening:** Added automated Bun compatibility verification job in GitHub Actions CI workflow.
19
+ - **Engineering & Security Audits:** Comprehensive audit documentation covering Baseline, Architecture, Security (OWASP Top 10 LLM), Invariants, Performance Benchmarks, RAG Evaluation, and Node/Bun Compatibility in `docs/audits/`.
20
+
21
+ ## 2.2.2 — 2026-11-10
22
+
23
+ ### Fixed
24
+
25
+ - **Document Ingestion:** Resolved infinite decaying chunk loop in `DocumentIngestionService.chunkText` when `endIndex >= text.length`.
26
+ - **Security & Prompt Injection:** Resolved regex boundary and preposition issues in `InjectionDetector` for English DAN jailbreak attacks (`in DAN mode`) and Turkish Unicode word boundaries (`ş, ç`).
27
+ - **LLM Failover Logging:** Replaced generic `Object failed` error message in `FallbackLLMProvider` with dynamic provider, model, or constructor resolution.
28
+ - **Rules Adapter:** Extended `StaticRulesAdapter` to accept structured rule objects (`{ id, rule }`) alongside plain string arrays via polymorphic `RuleInput`.
29
+ - **Performance & SML Sharing:** Prevented redundant ONNX model downloads and duplicate memory footprint by sharing `SMLEngine` instances across `RAGEngine`, `LocalFaqAdapter`, and `MemoryVectorAdapter`.
30
+
31
+ ### Added
32
+
33
+ - Exported `JobStatusValues` constants in `job-queue.interface.ts` to prevent casing mismatches.
34
+ - Exported `RuleInput` type in root exports.
35
+
5
36
  ## 2.2.1 — 2026-11-10
6
37
 
7
38
  ### Documentation
@@ -16,6 +16,8 @@ export declare class LocalFaqAdapter implements IFAQAdapter {
16
16
  private items;
17
17
  private isLoaded;
18
18
  constructor(options?: LocalFaqAdapterOptions);
19
+ setSMLEngine(engine: SMLEngine): void;
20
+ getSMLEngine(): SMLEngine;
19
21
  /**
20
22
  * Initializes the adapter by reading the JSON file and caching embeddings in RAM.
21
23
  */
@@ -6,5 +6,6 @@ export declare class FallbackLLMProvider implements ILLMProvider {
6
6
  private providers;
7
7
  private logFailover;
8
8
  constructor(providers: ILLMProvider[], options?: FallbackProviderOptions);
9
+ private getProviderName;
9
10
  generate(request: ILLMRequest): Promise<ILLMResponse>;
10
11
  }
@@ -1,8 +1,17 @@
1
1
  import type { ILLMProvider, ILLMRequest, ILLMResponse } from '../../interfaces/llm.interface.js';
2
+ export interface GeminiConfig {
3
+ /** Google Gemini API Key. Defaults to process.env.GEMINI_API_KEY. */
4
+ apiKey?: string | undefined;
5
+ /** Model identifier (e.g. 'gemini-2.0-flash', 'gemini-1.5-flash', 'gemini-1.5-pro'). Defaults to process.env.GEMINI_MODEL || 'gemini-2.0-flash'. */
6
+ model?: string | undefined;
7
+ /** Sampling temperature. Defaults to 0.1 for deterministic RAG answers. */
8
+ temperature?: number | undefined;
9
+ }
2
10
  export declare class GeminiAdapter implements ILLMProvider {
3
11
  private apiKey;
4
12
  private model;
5
- constructor(apiKey?: string, model?: string);
13
+ private temperature;
14
+ constructor(configOrApiKey?: string | GeminiConfig, model?: string);
6
15
  static createFast(apiKey?: string): GeminiAdapter;
7
16
  static createSmart(apiKey?: string): GeminiAdapter;
8
17
  generate(request: ILLMRequest): Promise<ILLMResponse>;
@@ -1,9 +1,20 @@
1
1
  import type { ILLMProvider, ILLMRequest, ILLMResponse } from '../../interfaces/llm.interface.js';
2
+ export interface OpenAIConfig {
3
+ /** OpenAI API Key. Defaults to process.env.OPENAI_API_KEY. */
4
+ apiKey?: string | undefined;
5
+ /** Model identifier (e.g. 'gpt-4o-mini', 'gpt-4o'). Defaults to process.env.OPENAI_MODEL || 'gpt-4o-mini'. */
6
+ model?: string | undefined;
7
+ /** Base API endpoint. Defaults to 'https://api.openai.com/v1/chat/completions'. */
8
+ endpoint?: string | undefined;
9
+ /** Sampling temperature. Defaults to 0.1 for deterministic RAG answers. */
10
+ temperature?: number | undefined;
11
+ }
2
12
  export declare class OpenAIAdapter implements ILLMProvider {
3
13
  protected apiKey: string;
4
14
  protected model: string;
5
15
  protected endpoint: string;
6
- constructor(apiKey?: string, model?: string, endpoint?: string);
16
+ protected temperature: number;
17
+ constructor(configOrApiKey?: string | OpenAIConfig, model?: string, endpoint?: string);
7
18
  static createFast(apiKey?: string): OpenAIAdapter;
8
19
  static createSmart(apiKey?: string): OpenAIAdapter;
9
20
  generate(request: ILLMRequest): Promise<ILLMResponse>;
@@ -1,6 +1,8 @@
1
- import { OpenAIAdapter } from './openai.adapter.js';
1
+ import { OpenAIAdapter, type OpenAIConfig } from './openai.adapter.js';
2
+ export interface OpenRouterConfig extends OpenAIConfig {
3
+ }
2
4
  export declare class OpenRouterAdapter extends OpenAIAdapter {
3
- constructor(apiKey?: string, model?: string, endpoint?: string);
5
+ constructor(configOrApiKey?: string | OpenRouterConfig, model?: string, endpoint?: string);
4
6
  static createFast(apiKey?: string): OpenRouterAdapter;
5
7
  static createSmart(apiKey?: string): OpenRouterAdapter;
6
8
  }
@@ -1,6 +1,11 @@
1
1
  import type { IRulesAdapter } from '../../interfaces/rules.interface.js';
2
+ export type RuleInput = string | {
3
+ id?: string;
4
+ rule: string;
5
+ [key: string]: any;
6
+ };
2
7
  export declare class StaticRulesAdapter implements IRulesAdapter {
3
8
  private rules;
4
- constructor(rules: string[]);
9
+ constructor(rules?: Array<RuleInput>);
5
10
  getActiveRules(tenantId?: string): Promise<string[]>;
6
11
  }
@@ -6,6 +6,8 @@ export declare class MemoryVectorAdapter implements IVectorStoreAdapter {
6
6
  private documents;
7
7
  private bm25Index;
8
8
  constructor(smlEngine?: SMLEngine);
9
+ setSMLEngine(engine: SMLEngine): void;
10
+ getSMLEngine(): SMLEngine;
9
11
  /**
10
12
  * Adds documents to memory, computes their embeddings, and indexes them in BM25.
11
13
  */