@hazeljs/rag 0.2.4 → 0.3.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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rag.error.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rag.error.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/errors/rag.error.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rag_error_1 = require("../../errors/rag.error");
4
+ describe('RAGError', () => {
5
+ describe('constructor', () => {
6
+ it('should create error with message and code', () => {
7
+ const error = new rag_error_1.RAGError('Test error', rag_error_1.RAGErrorCode.VECTOR_STORE_ERROR);
8
+ expect(error).toBeInstanceOf(Error);
9
+ expect(error).toBeInstanceOf(rag_error_1.RAGError);
10
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.VECTOR_STORE_ERROR);
11
+ expect(error.message).toBe('Test error');
12
+ expect(error.name).toBe('RAGError');
13
+ });
14
+ it('should include cause if provided', () => {
15
+ const cause = new Error('Original error');
16
+ const error = new rag_error_1.RAGError('Wrapper error', rag_error_1.RAGErrorCode.EMBEDDING_ERROR, cause);
17
+ expect(error.cause).toBe(cause);
18
+ });
19
+ });
20
+ describe('static factory methods', () => {
21
+ it('should create vectorStoreError', () => {
22
+ const error = rag_error_1.RAGError.vectorStoreError('Connection failed');
23
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.VECTOR_STORE_ERROR);
24
+ expect(error.message).toBe('Connection failed');
25
+ });
26
+ it('should create embeddingError', () => {
27
+ const error = rag_error_1.RAGError.embeddingError('API key invalid');
28
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.EMBEDDING_ERROR);
29
+ expect(error.message).toBe('API key invalid');
30
+ });
31
+ it('should create loaderError', () => {
32
+ const error = rag_error_1.RAGError.loaderError('./test.pdf');
33
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.LOADER_ERROR);
34
+ expect(error.message).toContain('./test.pdf');
35
+ });
36
+ it('should create splitterError', () => {
37
+ const error = rag_error_1.RAGError.splitterError('Invalid chunk size');
38
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.SPLITTER_ERROR);
39
+ expect(error.message).toBe('Invalid chunk size');
40
+ });
41
+ it('should create generationError', () => {
42
+ const error = rag_error_1.RAGError.generationError('No LLM configured');
43
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.LLM_GENERATION_ERROR);
44
+ expect(error.message).toContain('No LLM configured');
45
+ });
46
+ it('should create indexError', () => {
47
+ const error = rag_error_1.RAGError.indexError('Indexing failed');
48
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.INDEX_ERROR);
49
+ expect(error.message).toBe('Indexing failed');
50
+ });
51
+ it('should create retrievalError', () => {
52
+ const error = rag_error_1.RAGError.retrievalError('Search failed');
53
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.RETRIEVAL_ERROR);
54
+ expect(error.message).toBe('Search failed');
55
+ });
56
+ it('should create unsupportedFormat error', () => {
57
+ const error = rag_error_1.RAGError.unsupportedFormat('.xyz');
58
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.UNSUPPORTED_FORMAT);
59
+ expect(error.message).toContain('.xyz');
60
+ });
61
+ it('should create missingDependency error', () => {
62
+ const error = rag_error_1.RAGError.missingDependency('pdf-parse', 'PDF loading');
63
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.MISSING_DEPENDENCY);
64
+ expect(error.message).toContain('pdf-parse');
65
+ expect(error.message).toContain('PDF loading');
66
+ });
67
+ it('should create configurationError', () => {
68
+ const error = rag_error_1.RAGError.configurationError('Invalid config');
69
+ expect(error.code).toBe(rag_error_1.RAGErrorCode.CONFIGURATION_ERROR);
70
+ expect(error.message).toBe('Invalid config');
71
+ });
72
+ });
73
+ describe('error handling', () => {
74
+ it('should be catchable as Error', () => {
75
+ try {
76
+ throw rag_error_1.RAGError.vectorStoreError('Test');
77
+ }
78
+ catch (error) {
79
+ expect(error).toBeInstanceOf(Error);
80
+ expect(error).toBeInstanceOf(rag_error_1.RAGError);
81
+ }
82
+ });
83
+ it('should preserve stack trace', () => {
84
+ const error = rag_error_1.RAGError.embeddingError('Test');
85
+ expect(error.stack).toBeDefined();
86
+ expect(error.stack).toContain('RAGError');
87
+ });
88
+ it('should handle cause in factory methods', () => {
89
+ const cause = new Error('Root cause');
90
+ const error = rag_error_1.RAGError.vectorStoreError('Connection failed', cause);
91
+ expect(error.cause).toBe(cause);
92
+ });
93
+ });
94
+ });
95
+ //# sourceMappingURL=rag.error.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rag.error.test.js","sourceRoot":"","sources":["../../../src/__tests__/errors/rag.error.test.ts"],"names":[],"mappings":";;AAAA,sDAAgE;AAEhE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,KAAK,GAAG,IAAI,oBAAQ,CAAC,YAAY,EAAE,wBAAY,CAAC,kBAAkB,CAAC,CAAC;YAE1E,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,oBAAQ,CAAC,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,wBAAY,CAAC,kBAAkB,CAAC,CAAC;YACzD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACzC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;YAC1C,MAAM,KAAK,GAAG,IAAI,KA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gB,CAAC,MAAM,CAAC,CAAC;YAC1C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;gBACpC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,oBAAQ,CAAC,CAAC;YACzC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;YACrC,MAAM,KAAK,GAAG,oBAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC9C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAClC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;YAChD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;YACtC,MAAM,KAAK,GAAG,oBAAQ,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;YAEpE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=debug.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils/debug.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const debug_1 = require("../../utils/debug");
4
+ describe('debug utility', () => {
5
+ let originalEnv;
6
+ let consoleErrorSpy;
7
+ let log;
8
+ beforeEach(() => {
9
+ originalEnv = process.env.HAZELJS_DEBUG;
10
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
11
+ log = (0, debug_1.debug)('rag');
12
+ });
13
+ afterEach(() => {
14
+ if (originalEnv !== undefined) {
15
+ process.env.HAZELJS_DEBUG = originalEnv;
16
+ }
17
+ else {
18
+ delete process.env.HAZELJS_DEBUG;
19
+ }
20
+ consoleErrorSpy.mockRestore();
21
+ (0, debug_1.setDebugEnabled)(false);
22
+ });
23
+ describe('environment variable detection', () => {
24
+ it('should enable debug when HAZELJS_DEBUG=true', () => {
25
+ (0, debug_1.setDebugEnabled)(true);
26
+ log('test message');
27
+ expect(consoleErrorSpy).toHaveBeenCalled();
28
+ });
29
+ it('should enable debug when HAZELJS_DEBUG=1', () => {
30
+ process.env.HAZELJS_DEBUG = '1';
31
+ (0, debug_1.setDebugEnabled)(true);
32
+ log('test message');
33
+ expect(consoleErrorSpy).toHaveBeenCalled();
34
+ });
35
+ it('should not log when debug is disabled', () => {
36
+ (0, debug_1.setDebugEnabled)(false);
37
+ log('test message');
38
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
39
+ });
40
+ });
41
+ describe('setDebugEnabled', () => {
42
+ it('should enable debug logging', () => {
43
+ (0, debug_1.setDebugEnabled)(true);
44
+ log('test message');
45
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('[hazeljs:rag]'));
46
+ });
47
+ it('should disable debug logging', () => {
48
+ (0, debug_1.setDebugEnabled)(false);
49
+ log('test message');
50
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
51
+ });
52
+ });
53
+ describe('debug function', () => {
54
+ beforeEach(() => {
55
+ (0, debug_1.setDebugEnabled)(true);
56
+ });
57
+ it('should log with timestamp and prefix', () => {
58
+ log('test message');
59
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringMatching(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z \[hazeljs:rag\] test message$/));
60
+ });
61
+ it('should handle string formatting with %s', () => {
62
+ log('user=%s action=%s', 'alice', 'login');
63
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('user=alice action=login'));
64
+ });
65
+ it('should handle number formatting with %d', () => {
66
+ log('count=%d total=%d', 5, 100);
67
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('count=5 total=100'));
68
+ });
69
+ it('should handle JSON formatting with %j', () => {
70
+ log('data=%j', { key: 'value' });
71
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('data={"key":"value"}'));
72
+ });
73
+ it('should handle remaining arguments', () => {
74
+ log('message', 'extra', 123);
75
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('message extra 123'));
76
+ });
77
+ it('should create scoped loggers', () => {
78
+ const aiLog = (0, debug_1.debug)('ai');
79
+ const ragLog = (0, debug_1.debug)('rag');
80
+ aiLog('ai message');
81
+ ragLog('rag message');
82
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('[hazeljs:ai]'));
83
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('[hazeljs:rag]'));
84
+ });
85
+ it('should not log when disabled', () => {
86
+ (0, debug_1.setDebugEnabled)(false);
87
+ log('should not appear');
88
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
89
+ });
90
+ });
91
+ describe('performance', () => {
92
+ it('should skip logging when disabled', () => {
93
+ (0, debug_1.setDebugEnabled)(false);
94
+ log('message with %s', 'formatting');
95
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
96
+ });
97
+ });
98
+ });
99
+ //# sourceMappingURL=debug.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.test.js","sourceRoot":"","sources":["../../../src/__tests__/utils/debug.test.ts"],"names":[],"mappings":";;AAAA,6CAA2D;AAE3D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,WAA+B,CAAC;IACpC,IAAI,eAAiC,CAAC;IACtC,IAAI,GAA6B,CAAC;IAElC,UAAU,CA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AK,CAAC,CAAC;YACvB,GAAG,CAAC,mBAAmB,CAAC,CAAC;YAEzB,MAAM,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;YAEvB,GAAG,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;YAErC,MAAM,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Structured RAG errors for robust handling and observability.
3
+ *
4
+ * Mirrors the `AgentError` pattern from `@hazeljs/agent` for consistency.
5
+ */
6
+ export declare enum RAGErrorCode {
7
+ VECTOR_STORE_ERROR = "RAG_VECTOR_STORE_ERROR",
8
+ EMBEDDING_ERROR = "RAG_EMBEDDING_ERROR",
9
+ LOADER_ERROR = "RAG_LOADER_ERROR",
10
+ SPLITTER_ERROR = "RAG_SPLITTER_ERROR",
11
+ LLM_GENERATION_ERROR = "RAG_LLM_GENERATION_ERROR",
12
+ INDEX_ERROR = "RAG_INDEX_ERROR",
13
+ RETRIEVAL_ERROR = "RAG_RETRIEVAL_ERROR",
14
+ UNSUPPORTED_FORMAT = "RAG_UNSUPPORTED_FORMAT",
15
+ MISSING_DEPENDENCY = "RAG_MISSING_DEPENDENCY",
16
+ CONFIGURATION_ERROR = "RAG_CONFIGURATION_ERROR"
17
+ }
18
+ export declare class RAGError extends Error {
19
+ readonly code: RAGErrorCode;
20
+ readonly cause?: Error;
21
+ constructor(message: string, code: RAGErrorCode, cause?: Error);
22
+ static vectorStoreError(message: string, cause?: Error): RAGError;
23
+ static embeddingError(message: string, cause?: Error): RAGError;
24
+ static loaderError(source: string, cause?: Error): RAGError;
25
+ static splitterError(message: string, cause?: Error): RAGError;
26
+ static generationError(message: string, cause?: Error): RAGError;
27
+ static indexError(message: string, cause?: Error): RAGError;
28
+ static retrievalError(message: string, cause?: Error): RAGError;
29
+ static unsupportedFormat(extension: string): RAGError;
30
+ static missingDependency(packageName: string, feature: string): RAGError;
31
+ static configurationError(message: string): RAGError;
32
+ }
33
+ //# sourceMappingURL=rag.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rag.error.d.ts","sourceRoot":"","sources":["../../src/errors/rag.error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oBAAY,YAAY;IACtB,kBAAkB,2BAA2B;IAC7C,eAAe,wBAAwB;IACvC,YAAY,qBAAqB;IACjC,cAAc,uBAAuB;IACrC,oBAAoB,6BAA6B;IACjD,WAAW,oBAAoB;IAC/B,eAAe,wBAAwB;IACvC,kBAAkB,2BAA2B;IAC7C,kBAAkB,2BAA2B;IAC7C,mBAAmB,4BAA4B;CAChD;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,KAAK;IAQ9D,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAIjE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAI/D,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAQ3D,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAI9D,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAQhE,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAI3D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ;IAI/D,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ;IAQrD,MAAM,CAAC,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ;IAQxE,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;CAGrD"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Structured RAG errors for robust handling and observability.
4
+ *
5
+ * Mirrors the `AgentError` pattern from `@hazeljs/agent` for consistency.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.RAGError = exports.RAGErrorCode = void 0;
9
+ var RAGErrorCode;
10
+ (function (RAGErrorCode) {
11
+ RAGErrorCode["VECTOR_STORE_ERROR"] = "RAG_VECTOR_STORE_ERROR";
12
+ RAGErrorCode["EMBEDDING_ERROR"] = "RAG_EMBEDDING_ERROR";
13
+ RAGErrorCode["LOADER_ERROR"] = "RAG_LOADER_ERROR";
14
+ RAGErrorCode["SPLITTER_ERROR"] = "RAG_SPLITTER_ERROR";
15
+ RAGErrorCode["LLM_GENERATION_ERROR"] = "RAG_LLM_GENERATION_ERROR";
16
+ RAGErrorCode["INDEX_ERROR"] = "RAG_INDEX_ERROR";
17
+ RAGErrorCode["RETRIEVAL_ERROR"] = "RAG_RETRIEVAL_ERROR";
18
+ RAGErrorCode["UNSUPPORTED_FORMAT"] = "RAG_UNSUPPORTED_FORMAT";
19
+ RAGErrorCode["MISSING_DEPENDENCY"] = "RAG_MISSING_DEPENDENCY";
20
+ RAGErrorCode["CONFIGURATION_ERROR"] = "RAG_CONFIGURATION_ERROR";
21
+ })(RAGErrorCode || (exports.RAGErrorCode = RAGErrorCode = {}));
22
+ class RAGError extends Error {
23
+ constructor(message, code, cause) {
24
+ super(message);
25
+ this.name = 'RAGError';
26
+ this.code = code;
27
+ this.cause = cause;
28
+ Object.setPrototypeOf(this, RAGError.prototype);
29
+ }
30
+ static vectorStoreError(message, cause) {
31
+ return new RAGError(message, RAGErrorCode.VECTOR_STORE_ERROR, cause);
32
+ }
33
+ static embeddingError(message, cause) {
34
+ return new RAGError(message, RAGErrorCode.EMBEDDING_ERROR, cause);
35
+ }
36
+ static loaderError(source, cause) {
37
+ return new RAGError(`Failed to load documents from "${source}". Check that the file exists and is readable.`, RAGErrorCode.LOADER_ERROR, cause);
38
+ }
39
+ static splitterError(message, cause) {
40
+ return new RAGError(message, RAGErrorCode.SPLITTER_ERROR, cause);
41
+ }
42
+ static generationError(message, cause) {
43
+ return new RAGError(`LLM generation failed: ${message}. Ensure an llmFunction is configured.`, RAGErrorCode.LLM_GENERATION_ERROR, cause);
44
+ }
45
+ static indexError(message, cause) {
46
+ return new RAGError(message, RAGErrorCode.INDEX_ERROR, cause);
47
+ }
48
+ static retrievalError(message, cause) {
49
+ return new RAGError(message, RAGErrorCode.RETRIEVAL_ERROR, cause);
50
+ }
51
+ static unsupportedFormat(extension) {
52
+ return new RAGError(`Unsupported file format "${extension}". ` +
53
+ `Supported: .txt, .log, .json, .csv, .md, .mdx, .html, .htm, .pdf, .docx`, RAGErrorCode.UNSUPPORTED_FORMAT);
54
+ }
55
+ static missingDependency(packageName, feature) {
56
+ return new RAGError(`The "${feature}" feature requires the "${packageName}" package. ` +
57
+ `Install it with: npm install ${packageName}`, RAGErrorCode.MISSING_DEPENDENCY);
58
+ }
59
+ static configurationError(message) {
60
+ return new RAGError(message, RAGErrorCode.CONFIGURATION_ERROR);
61
+ }
62
+ }
63
+ exports.RAGError = RAGError;
64
+ //# sourceMappingURL=rag.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rag.error.js","sourceRoot":"","sources":["../../src/errors/rag.error.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,IAAY,YAWX;AAXD,WAAY,YAAY;IACtB,6DAA6C,CAAA;IAC7C,uDAAuC,CAAA;IACvC,iDAAiC,CAAA;IACjC,qDAAqC,CAAA;IACrC,iEAAiD,CAAA;IACjD,+CAA+B,CAAA;IAC/B,uDAAuC,CAAA;IACvC,6DAA6C,CAAA;IAC7C,6DAA6C,CAAA;IAC7C,+DAA+C,CAAA;AACjD,CAAC,EAXW,YAAY,4BAAZ,YAAY,QAWvB;AAED,MAAa,QAAS,SAAQ,KAAK;IAIjC,YAAY,OAAe,EAAE,IAAkB,EAAE,KAAa;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,OAAe,EAAE,KAAa;QACpD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAe,EAAE,KAAa;QAClD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAc,EAAE,KAAa;QAC9C,OAAO,IAAI,QAAQ,CACjB,kCAAkC,MAAM,gDAAgD,EACxF,YAAY,CAAC,YAAY,EACzB,KAAK,CACN,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,OAAe,EAAE,KAAa;QACjD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,OAAe,EAAE,KAAa;QACnD,OAAO,IAAI,QAAQ,CACjB,0BAA0B,OAAO,wCAAwC,EACzE,YAAY,CAAC,oBAAoB,EACjC,KAAK,CACN,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,OAAe,EAAE,KAAa;QAC9C,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAe,EAAE,KAAa;QAClD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,SAAiB;QACxC,OAAO,IAAI,QAAQ,CACjB,4BAA4B,SAAS,KAAK;YACxC,yEAAyE,EAC3E,YAAY,CAAC,kBAAkB,CAChC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,WAAmB,EAAE,OAAe;QAC3D,OAAO,IAAI,QAAQ,CACjB,QAAQ,OAAO,2BAA2B,WAAW,aAAa;YAChE,gCAAgC,WAAW,EAAE,EAC/C,YAAY,CAAC,kBAAkB,CAChC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,OAAe;QACvC,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC;IACjE,CAAC;CACF;AAnED,4BAmEC"}
package/dist/index.d.ts CHANGED
@@ -26,4 +26,6 @@ export * from './memory';
26
26
  export * from './rag-pipeline-with-memory';
27
27
  export * from './agentic';
28
28
  export * from './graph';
29
+ export { RAGError, RAGErrorCode } from './errors/rag.error';
30
+ export { debug, setDebugEnabled } from './utils/debug';
29
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAG7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,wCAAwC,CAAC;AAGvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAG7C,cAAc,0CAA0C,CAAC;AAGzD,cAAc,WAAW,CAAC;AAG1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,UAAU,CAAC;AACzB,cAAc,4BAA4B,CAAC;AAG3C,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAG7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,wCAAwC,CAAC;AAGvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAG7C,cAAc,0CAA0C,CAAC;AAGzD,cAAc,WAAW,CAAC;AAG1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,UAAU,CAAC;AACzB,cAAc,4BAA4B,CAAC;AAG3C,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.setDebugEnabled = exports.debug = exports.RAGErrorCode = exports.RAGError = void 0;
21
22
  // Core types
22
23
  __exportStar(require("./types"), exports);
23
24
  // RAG Pipeline
@@ -55,4 +56,12 @@ __exportStar(require("./rag-pipeline-with-memory"), exports);
55
56
  __exportStar(require("./agentic"), exports);
56
57
  // GraphRAG - Knowledge graph-based retrieval (entity + community search)
57
58
  __exportStar(require("./graph"), exports);
59
+ // Errors
60
+ var rag_error_1 = require("./errors/rag.error");
61
+ Object.defineProperty(exports, "RAGError", { enumerable: true, get: function () { return rag_error_1.RAGError; } });
62
+ Object.defineProperty(exports, "RAGErrorCode", { enumerable: true, get: function () { return rag_error_1.RAGErrorCode; } });
63
+ // Debug utility
64
+ var debug_1 = require("./utils/debug");
65
+ Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
66
+ Object.defineProperty(exports, "setDebugEnabled", { enumerable: true, get: function () { return debug_1.setDebugEnabled; } });
58
67
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,aAAa;AACb,0CAAwB;AAExB,eAAe;AACf,iDAA+B;AAE/B,uBAAuB;AACvB,gDAA8B;AAC9B,+CAA6B;AAE7B,aAAa;AACb,6DAA2C;AAC3C,oEAAkD;AAClD,yEAAuD;AAEvD,aAAa;AACb,iEAA+C;AAC/C,iEAA+C;AAE/C,gBAAgB;AAChB,sEAAoD;AACpD,iEAA+C;AAC/C,+DAA6C;AAC7C,iEAA+C;AAC/C,+DAA6C;AAE7C,iBAAiB;AACjB,2EAAyD;AAEzD,mBAAmB;AACnB,4CAA0B;AAE1B,uBAAuB;AACvB,mDAAiC;AACjC,4DAA0C;AAC1C,0DAAwC;AAExC,QAAQ;AACR,qDAAmC;AAEnC,SAAS;AACT,2CAAyB;AACzB,6DAA2C;AAE3C,2DAA2D;AAC3D,4CAA0B;AAE1B,yEAAyE;AACzE,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,aAAa;AACb,0CAAwB;AAExB,eAAe;AACf,iDAA+B;AAE/B,uBAAuB;AACvB,gDAA8B;AAC9B,+CAA6B;AAE7B,aAAa;AACb,6DAA2C;AAC3C,oEAAkD;AAClD,yEAAuD;AAEvD,aAAa;AACb,iEAA+C;AAC/C,iEAA+C;AAE/C,gBAAgB;AAChB,sEAAoD;AACpD,iEAA+C;AAC/C,+DAA6C;AAC7C,iEAA+C;AAC/C,+DAA6C;AAE7C,iBAAiB;AACjB,2EAAyD;AAEzD,mBAAmB;AACnB,4CAA0B;AAE1B,uBAAuB;AACvB,mDAAiC;AACjC,4DAA0C;AAC1C,0DAAwC;AAExC,QAAQ;AACR,qDAAmC;AAEnC,SAAS;AACT,2CAAyB;AACzB,6DAA2C;AAE3C,2DAA2D;AAC3D,4CAA0B;AAE1B,yEAAyE;AACzE,0CAAwB;AAExB,SAAS;AACT,gDAA4D;AAAnD,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAE/B,gBAAgB;AAChB,uCAAuD;AAA9C,8FAAA,KAAK,OAAA;AAAE,wGAAA,eAAe,OAAA"}
@@ -4,10 +4,47 @@
4
4
  */
5
5
  import { RAGConfig, RAGQueryOptions, RAGResponse, Document, SearchResult, RetrievalStrategy } from './types';
6
6
  export type LLMFunction = (prompt: string) => Promise<string>;
7
+ /**
8
+ * Shorthand configuration for `RAGPipeline.from()`.
9
+ *
10
+ * Only `provider` (or `apiKey`) is required — everything else has sensible defaults.
11
+ */
12
+ export interface RAGPipelineQuickConfig {
13
+ /** Embedding provider name. Defaults to `'openai'`. */
14
+ provider?: 'openai' | 'cohere';
15
+ /** API key for the embedding provider. Falls back to `OPENAI_API_KEY` / `COHERE_API_KEY` env vars. */
16
+ apiKey?: string;
17
+ /** Embedding model name (provider-specific). */
18
+ embeddingModel?: string;
19
+ /** Vector store to use. Defaults to in-memory. */
20
+ vectorStore?: 'memory';
21
+ /** Number of results to return. Default: 5. */
22
+ topK?: number;
23
+ /** Chunk size for text splitting. Default: 1000. */
24
+ chunkSize?: number;
25
+ /** Chunk overlap for text splitting. Default: 200. */
26
+ chunkOverlap?: number;
27
+ /** LLM function for answer generation. */
28
+ llm?: LLMFunction;
29
+ }
7
30
  export declare class RAGPipeline {
8
31
  private config;
9
32
  private llmFunction?;
33
+ private bm25;
34
+ private bm25Indexed;
10
35
  constructor(config: RAGConfig, llmFunction?: LLMFunction);
36
+ /**
37
+ * Create a RAGPipeline with sensible defaults from minimal configuration.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const pipeline = RAGPipeline.from({ provider: 'openai', topK: 5, llm: myLLM });
42
+ * await pipeline.initialize();
43
+ * await pipeline.addDocuments(docs);
44
+ * const result = await pipeline.query('What is X?');
45
+ * ```
46
+ */
47
+ static from(quick?: RAGPipelineQuickConfig): RAGPipeline;
11
48
  /**
12
49
  * Initialize the RAG pipeline
13
50
  */
@@ -30,9 +67,8 @@ export declare class RAGPipeline {
30
67
  */
31
68
  private retrieveWithMMR;
32
69
  /**
33
- * Hybrid retrieval (combines keyword and semantic search)
34
- * For now, just returns semantic search results
35
- * TODO: Implement keyword search integration
70
+ * Hybrid retrieval combines BM25 keyword search with vector similarity.
71
+ * Uses weighted score fusion (default 0.7 vector, 0.3 keyword).
36
72
  */
37
73
  private retrieveHybrid;
38
74
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rag-pipeline.d.ts","sourceRoot":"","sources":["../src/rag-pipeline.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9D,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAc;gBAEtB,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW;IAKxD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;OAEG;IACG,YAAY,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAW5D;;OAEG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IA8B/E;;OAEG;IACG,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,EAC7B,QAAQ,GAAE,iBAAgD,GACzD,OAAO,CAAC,YAAY,EAAE,CAAC;IAgB1B;;;OAGG;YACW,eAAe;IA6D7B;;;;OAIG;YACW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;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,GAAE,sBAA2B,GAAG,WAAW;IAyD5D;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;OAEG;IACG,YAAY,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0B5D;;OAEG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IA8B/E;;OAEG;IACG,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,EAC7B,QAAQ,GAAE,iBAAgD,GACzD,OAAO,CAAC,YAAY,EAAE,CAAC;IAgB1B;;;OAGG;YACW,eAAe;IA6D7B;;;OAGG;YACW,cAAc;IA4D5B;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;OAEG;YACW,cAAc;IAU5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -6,10 +6,73 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.RAGPipeline = void 0;
8
8
  const types_1 = require("./types");
9
+ const bm25_1 = require("./retrieval/bm25");
10
+ const openai_embeddings_1 = require("./embeddings/openai-embeddings");
11
+ const cohere_embeddings_1 = require("./embeddings/cohere-embeddings");
12
+ const memory_vector_store_1 = require("./vector-stores/memory-vector-store");
13
+ const recursive_text_splitter_1 = require("./text-splitters/recursive-text-splitter");
9
14
  class RAGPipeline {
10
15
  constructor(config, llmFunction) {
16
+ this.bm25Indexed = false;
11
17
  this.config = config;
12
18
  this.llmFunction = llmFunction;
19
+ this.bm25 = new bm25_1.BM25();
20
+ }
21
+ /**
22
+ * Create a RAGPipeline with sensible defaults from minimal configuration.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const pipeline = RAGPipeline.from({ provider: 'openai', topK: 5, llm: myLLM });
27
+ * await pipeline.initialize();
28
+ * await pipeline.addDocuments(docs);
29
+ * const result = await pipeline.query('What is X?');
30
+ * ```
31
+ */
32
+ static from(quick = {}) {
33
+ const provider = quick.provider ?? 'openai';
34
+ // Resolve embedding provider
35
+ let embeddingProvider;
36
+ switch (provider) {
37
+ case 'cohere': {
38
+ const apiKey = quick.apiKey ?? process.env.COHERE_API_KEY;
39
+ if (!apiKey) {
40
+ throw new Error('RAGPipeline.from(): Missing API key for Cohere. ' +
41
+ 'Pass `apiKey` or set the COHERE_API_KEY environment variable.');
42
+ }
43
+ embeddingProvider = new cohere_embeddings_1.CohereEmbeddings({
44
+ apiKey,
45
+ model: quick.embeddingModel,
46
+ });
47
+ break;
48
+ }
49
+ case 'openai':
50
+ default: {
51
+ const apiKey = quick.apiKey ?? process.env.OPENAI_API_KEY;
52
+ if (!apiKey) {
53
+ throw new Error('RAGPipeline.from(): Missing API key for OpenAI. ' +
54
+ 'Pass `apiKey` or set the OPENAI_API_KEY environment variable.');
55
+ }
56
+ embeddingProvider = new openai_embeddings_1.OpenAIEmbeddings({
57
+ apiKey,
58
+ model: quick.embeddingModel,
59
+ });
60
+ break;
61
+ }
62
+ }
63
+ // Resolve vector store (currently only memory; extensible later)
64
+ const vectorStore = new memory_vector_store_1.MemoryVectorStore(embeddingProvider);
65
+ // Resolve text splitter
66
+ const textSplitter = new recursive_text_splitter_1.RecursiveTextSplitter({
67
+ chunkSize: quick.chunkSize ?? 1000,
68
+ chunkOverlap: quick.chunkOverlap ?? 200,
69
+ });
70
+ return new RAGPipeline({
71
+ vectorStore,
72
+ embeddingProvider,
73
+ textSplitter,
74
+ topK: quick.topK ?? 5,
75
+ }, quick.llm);
13
76
  }
14
77
  /**
15
78
  * Initialize the RAG pipeline
@@ -26,7 +89,20 @@ class RAGPipeline {
26
89
  if (this.config.textSplitter) {
27
90
  processedDocs = this.config.textSplitter.splitDocuments(documents);
28
91
  }
29
- return this.config.vectorStore.addDocuments(processedDocs);
92
+ const ids = await this.config.vectorStore.addDocuments(processedDocs);
93
+ // Index in BM25 for hybrid search
94
+ const bm25Docs = processedDocs.map((doc, i) => ({
95
+ id: doc.id || ids[i],
96
+ content: doc.content,
97
+ tokens: doc.content
98
+ .toLowerCase()
99
+ .replace(/[^\w\s]/g, ' ')
100
+ .split(/\s+/)
101
+ .filter((t) => t.length > 0),
102
+ }));
103
+ this.bm25.addDocuments(bm25Docs);
104
+ this.bm25Indexed = true;
105
+ return ids;
30
106
  }
31
107
  /**
32
108
  * Query the RAG system
@@ -120,14 +196,56 @@ class RAGPipeline {
120
196
  return selected;
121
197
  }
122
198
  /**
123
- * Hybrid retrieval (combines keyword and semantic search)
124
- * For now, just returns semantic search results
125
- * TODO: Implement keyword search integration
199
+ * Hybrid retrieval combines BM25 keyword search with vector similarity.
200
+ * Uses weighted score fusion (default 0.7 vector, 0.3 keyword).
126
201
  */
127
202
  async retrieveHybrid(query, options = {}) {
128
- // For now, fallback to similarity search
129
- // In production, this would combine BM25 or other keyword search with vector search
130
- return this.config.vectorStore.search(query, options);
203
+ const topK = options.topK || this.config.topK || 5;
204
+ // Always run vector search
205
+ const vectorResults = await this.config.vectorStore.search(query, {
206
+ ...options,
207
+ topK: topK * 2,
208
+ });
209
+ // If BM25 hasn't been indexed yet, fall back to vector-only
210
+ if (!this.bm25Indexed) {
211
+ return vectorResults.slice(0, topK);
212
+ }
213
+ // BM25 keyword search
214
+ const keywordResults = this.bm25.search(query, topK * 2);
215
+ // Normalize scores to [0, 1]
216
+ const normalize = (items) => {
217
+ if (items.length === 0)
218
+ return new Map();
219
+ const scores = items.map((r) => r.score);
220
+ const min = Math.min(...scores);
221
+ const max = Math.max(...scores);
222
+ const range = max - min || 1;
223
+ return new Map(items.map((r) => [r.id, (r.score - min) / range]));
224
+ };
225
+ const vectorScores = normalize(vectorResults.map((r) => ({ id: r.id, score: r.score })));
226
+ const keywordScores = normalize(keywordResults);
227
+ const vectorWeight = 0.7;
228
+ const keywordWeight = 0.3;
229
+ // Fuse scores
230
+ const allIds = new Set([...vectorScores.keys(), ...keywordScores.keys()]);
231
+ const fused = [];
232
+ for (const id of allIds) {
233
+ const vs = vectorScores.get(id) || 0;
234
+ const ks = keywordScores.get(id) || 0;
235
+ fused.push({ id, score: vectorWeight * vs + keywordWeight * ks });
236
+ }
237
+ fused.sort((a, b) => b.score - a.score);
238
+ // Map back to full SearchResult objects
239
+ const resultMap = new Map(vectorResults.map((r) => [r.id, r]));
240
+ return fused
241
+ .slice(0, topK)
242
+ .map((f) => {
243
+ const original = resultMap.get(f.id);
244
+ if (original)
245
+ return { ...original, score: f.score };
246
+ return null;
247
+ })
248
+ .filter((r) => r !== null);
131
249
  }
132
250
  /**
133
251
  * Build context string from search results
@@ -175,6 +293,8 @@ class RAGPipeline {
175
293
  */
176
294
  async clear() {
177
295
  await this.config.vectorStore.clear();
296
+ this.bm25.clear();
297
+ this.bm25Indexed = false;
178
298
  }
179
299
  }
180
300
  exports.RAGPipeline = RAGPipeline;