@denizsvnc/ai-rag-engine 0.0.0-stage → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/LICENSE +21 -0
  3. package/README.md +167 -2
  4. package/dist/adapters/cache/index.d.ts +1 -0
  5. package/dist/adapters/cache/redis-cache.adapter.d.ts +49 -0
  6. package/dist/adapters/faq/local-faq.adapter.d.ts +29 -0
  7. package/dist/adapters/faq/url-faq.adapter.d.ts +14 -0
  8. package/dist/adapters/llm/custom.adapter.d.ts +42 -0
  9. package/dist/adapters/llm/fallback.adapter.d.ts +10 -0
  10. package/dist/adapters/llm/gemini.adapter.d.ts +9 -0
  11. package/dist/adapters/llm/ollama.adapter.d.ts +30 -0
  12. package/dist/adapters/llm/openai.adapter.d.ts +10 -0
  13. package/dist/adapters/llm/openrouter.adapter.d.ts +6 -0
  14. package/dist/adapters/llm/tiered.adapter.d.ts +22 -0
  15. package/dist/adapters/rules/static-rules.adapter.d.ts +6 -0
  16. package/dist/adapters/vector/memory-vector.adapter.d.ts +33 -0
  17. package/dist/adapters/vector/postgres-vector.adapter.d.ts +51 -0
  18. package/dist/api/auth.d.ts +47 -0
  19. package/dist/api/middleware.d.ts +3 -0
  20. package/dist/api/rate-limit.d.ts +8 -0
  21. package/dist/api/routes.d.ts +9 -0
  22. package/dist/api/server.d.ts +1 -0
  23. package/dist/api/server.js +4433 -0
  24. package/dist/config/default.d.ts +22 -0
  25. package/dist/config/ingestion-runtime.d.ts +11 -0
  26. package/dist/core/cache-manager.d.ts +29 -0
  27. package/dist/core/engine.d.ts +75 -0
  28. package/dist/core/ingestion/ingestion-worker.d.ts +19 -0
  29. package/dist/core/ingestion/postgres-ingestion-store.d.ts +56 -0
  30. package/dist/core/ingestion/queued-ingestion.service.d.ts +35 -0
  31. package/dist/core/metrics/prometheus-exporter.d.ts +12 -0
  32. package/dist/core/metrics/rag-evaluator.d.ts +63 -0
  33. package/dist/core/metrics/token-tracker.d.ts +69 -0
  34. package/dist/core/prompt-builder.d.ts +20 -0
  35. package/dist/core/queue/bullmq-queue.d.ts +39 -0
  36. package/dist/core/queue/in-memory-queue.d.ts +24 -0
  37. package/dist/core/queue/job-queue.interface.d.ts +22 -0
  38. package/dist/core/queue/queue-factory.d.ts +12 -0
  39. package/dist/core/security/confirmation.d.ts +64 -0
  40. package/dist/core/security/injection-detector.d.ts +25 -0
  41. package/dist/core/security/nonce-store.d.ts +21 -0
  42. package/dist/core/security/pii-guard.d.ts +38 -0
  43. package/dist/core/security/sanitizer.d.ts +23 -0
  44. package/dist/core/security/secrets.d.ts +2 -0
  45. package/dist/core/security/security-guard.d.ts +18 -0
  46. package/dist/core/security/security.types.d.ts +38 -0
  47. package/dist/core/sml-engine.d.ts +65 -0
  48. package/dist/core/tool-registry.d.ts +17 -0
  49. package/dist/core/vector/bm25.d.ts +44 -0
  50. package/dist/core/vector/hybrid-search.d.ts +15 -0
  51. package/dist/index.d.ts +51 -0
  52. package/dist/index.js +4509 -0
  53. package/dist/interfaces/cache.interface.d.ts +8 -0
  54. package/dist/interfaces/engine-config.interface.d.ts +73 -0
  55. package/dist/interfaces/faq.interface.d.ts +17 -0
  56. package/dist/interfaces/ingestion.interface.d.ts +14 -0
  57. package/dist/interfaces/llm.interface.d.ts +22 -0
  58. package/dist/interfaces/query-context.interface.d.ts +33 -0
  59. package/dist/interfaces/rules.interface.d.ts +3 -0
  60. package/dist/interfaces/tool.interface.d.ts +50 -0
  61. package/dist/interfaces/vector.interface.d.ts +15 -0
  62. package/dist/scripts/migrate-vector.d.ts +1 -0
  63. package/dist/scripts/migrate-vector.js +627 -0
  64. package/dist/services/document-ingestion.service.d.ts +116 -0
  65. package/dist/utils/http.d.ts +2 -0
  66. package/dist/utils/math.d.ts +3 -0
  67. package/dist/worker.d.ts +1 -0
  68. package/dist/worker.js +1787 -0
  69. package/docs/RELEASING.md +55 -0
  70. package/docs/USAGE.md +154 -0
  71. package/package.json +95 -4
@@ -0,0 +1,116 @@
1
+ import type { IIngestionBackend } from '../interfaces/ingestion.interface.js';
2
+ import type { IVectorStoreAdapter } from '../interfaces/vector.interface.js';
3
+ import { SMLEngine } from '../core/sml-engine.js';
4
+ import { type PIIPolicy } from '../core/security/pii-guard.js';
5
+ import type { IJobQueue, Job, JobStatus } from '../core/queue/job-queue.interface.js';
6
+ export interface DocumentUploadPayload {
7
+ documentId?: string | undefined;
8
+ idempotencyKey?: string | undefined;
9
+ encoding?: 'utf8' | 'base64' | undefined;
10
+ filename: string;
11
+ content: string | Buffer | NodeJS.ReadableStream;
12
+ mimeType?: string | undefined;
13
+ tenantId?: string | undefined;
14
+ userId?: string | undefined;
15
+ }
16
+ export interface StreamIngestionOptions {
17
+ mimeType?: string | undefined;
18
+ tenantId?: string | undefined;
19
+ userId?: string | undefined;
20
+ onProgress?: ((chunksCount: number) => void) | undefined;
21
+ }
22
+ export interface IngestionJobResult {
23
+ filename: string;
24
+ chunksCount: number;
25
+ piiEntitiesMasked: number;
26
+ documentIds: string[];
27
+ processedAt: string;
28
+ }
29
+ export interface DocumentIngestionConfig {
30
+ backend?: IIngestionBackend | undefined;
31
+ vectorStore?: IVectorStoreAdapter | undefined;
32
+ smlEngine?: SMLEngine | undefined;
33
+ jobQueue?: IJobQueue | undefined;
34
+ chunkSize?: number | undefined;
35
+ chunkOverlap?: number | undefined;
36
+ piiPolicy?: PIIPolicy | undefined;
37
+ }
38
+ export declare class DocumentIngestionService {
39
+ private workerReady;
40
+ private backend?;
41
+ private vectorStore?;
42
+ private smlEngine?;
43
+ private jobQueue;
44
+ private chunkSize;
45
+ private chunkOverlap;
46
+ private piiPolicy?;
47
+ constructor(config?: DocumentIngestionConfig);
48
+ /**
49
+ * Inspects magic bytes and file extension to block dangerous executables and scripts.
50
+ */
51
+ static validateFileSafety(filename: string, buffer: Buffer): {
52
+ safe: boolean;
53
+ reason?: string;
54
+ };
55
+ /**
56
+ * Inspects magic bytes from an active stream non-destructively by peeking the initial 4KB chunk.
57
+ * Prevents loading multi-gigabyte files into memory just to check safety headers.
58
+ */
59
+ static validateStreamSafety(filename: string, stream: NodeJS.ReadableStream): Promise<{
60
+ safe: boolean;
61
+ reason?: string | undefined;
62
+ safeStream: NodeJS.ReadableStream;
63
+ }>;
64
+ /**
65
+ * Enterprise Lexical Document Text Extractor.
66
+ * Decodes and normalizes textual content across PDF streams, Markdown, CSV, JSON, and plaintext files.
67
+ *
68
+ * PDF Specification Compliance:
69
+ * - Parses text execution state matrices within BT (Begin Text) ... ET (End Text) blocks.
70
+ * - Evaluates 'Tj', '\'', and '"' text-showing operators with PDF octal and hexadecimal escape decoding.
71
+ * - Parses 'TJ' array kerning sequences, preserving natural word spacing between glyph segments.
72
+ * - Evaluates positional newline operators ('T*', 'Td', 'TD', 'Tm') to maintain structural paragraph integrity.
73
+ * - Performs binary artifact suppression and multi-lingual UTF-8 normalization (Turkish, European, and CJK diacritics).
74
+ */
75
+ static extractText(filename: string, buffer: Buffer): string;
76
+ /**
77
+ * Enterprise High-Efficiency PDF Lexical Extractor.
78
+ * Parses PDF content streams without heavy external C++/WASM dependencies.
79
+ */
80
+ static extractPdfText(rawContent: string): string;
81
+ static chunkText(text: string, chunkSize?: number, overlap?: number): string[];
82
+ /**
83
+ * Streaming chunk generator.
84
+ * Ingests chunks of text or buffers incrementally with natural backpressure,
85
+ * maintaining a constant O(1) memory footprint regardless of file size.
86
+ */
87
+ static chunkStream(textStream: AsyncIterable<string | Buffer>, chunkSize?: number, overlap?: number): AsyncGenerator<string, void, unknown>;
88
+ /**
89
+ * Directly streams and chunks large documents without intermediate memory bloat.
90
+ * Sanitizes PII and inserts documents into the vector store with automatic backpressure.
91
+ */
92
+ ingestStreamDirect(filename: string, stream: NodeJS.ReadableStream, options?: StreamIngestionOptions): Promise<IngestionJobResult>;
93
+ /**
94
+ * Submits a stream for asynchronous background queue processing.
95
+ * Uses backpressure-regulated disk spooling to temporary storage, preventing V8 heap exhaustion.
96
+ */
97
+ submitStream(filename: string, stream: NodeJS.ReadableStream, options?: StreamIngestionOptions): Promise<{
98
+ jobId: string;
99
+ status: JobStatus;
100
+ }>;
101
+ /**
102
+ * Submits a document for background asynchronous ingestion.
103
+ * Supports String, Buffer, or ReadableStream payloads.
104
+ */
105
+ submitDocument(payload: DocumentUploadPayload): Promise<{
106
+ jobId: string;
107
+ status: JobStatus;
108
+ }>;
109
+ /**
110
+ * Retrieves the status and progress of an ingestion job.
111
+ */
112
+ getJobStatus(jobId: string, tenantId?: string): Promise<Job | null>;
113
+ retryJob(jobId: string, tenantId: string): Promise<void>;
114
+ private initWorker;
115
+ private toBuffer;
116
+ }
@@ -0,0 +1,2 @@
1
+ /** Prevent provider calls from holding an HTTP request indefinitely. */
2
+ export declare function providerTimeoutSignal(): AbortSignal;
@@ -0,0 +1,3 @@
1
+ export declare function dotProduct(vecA: number[], vecB: number[]): number;
2
+ export declare function magnitude(vec: number[]): number;
3
+ export declare function cosineSimilarity(vecA: number[], vecB: number[]): number;
@@ -0,0 +1 @@
1
+ import 'dotenv/config';