@robthepcguy/rag-vault 1.0.1 → 1.1.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.
- package/README.md +441 -421
- package/dist/errors/index.d.ts +2 -6
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +8 -16
- package/dist/errors/index.js.map +1 -1
- package/dist/explainability/index.d.ts +2 -0
- package/dist/explainability/index.d.ts.map +1 -0
- package/dist/explainability/index.js +8 -0
- package/dist/explainability/index.js.map +1 -0
- package/dist/explainability/keywords.d.ts +18 -0
- package/dist/explainability/keywords.d.ts.map +1 -0
- package/dist/explainability/keywords.js +237 -0
- package/dist/explainability/keywords.js.map +1 -0
- package/dist/flywheel/feedback.d.ts +105 -0
- package/dist/flywheel/feedback.d.ts.map +1 -0
- package/dist/flywheel/feedback.js +219 -0
- package/dist/flywheel/feedback.js.map +1 -0
- package/dist/flywheel/index.d.ts +2 -0
- package/dist/flywheel/index.d.ts.map +1 -0
- package/dist/flywheel/index.js +9 -0
- package/dist/flywheel/index.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +40 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +113 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/raw-data-utils.d.ts.map +1 -1
- package/dist/server/raw-data-utils.js.map +1 -1
- package/dist/utils/config.d.ts +15 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +84 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/math.d.ts +0 -7
- package/dist/utils/math.d.ts.map +1 -1
- package/dist/utils/math.js +0 -14
- package/dist/utils/math.js.map +1 -1
- package/dist/vectordb/index.d.ts +57 -2
- package/dist/vectordb/index.d.ts.map +1 -1
- package/dist/vectordb/index.js +255 -33
- package/dist/vectordb/index.js.map +1 -1
- package/dist/web/api-routes.d.ts.map +1 -1
- package/dist/web/api-routes.js +120 -7
- package/dist/web/api-routes.js.map +1 -1
- package/dist/web/config-routes.d.ts.map +1 -1
- package/dist/web/config-routes.js +84 -2
- package/dist/web/config-routes.js.map +1 -1
- package/dist/web/database-manager.d.ts +119 -1
- package/dist/web/database-manager.d.ts.map +1 -1
- package/dist/web/database-manager.js +339 -51
- package/dist/web/database-manager.js.map +1 -1
- package/dist/web/http-server.d.ts.map +1 -1
- package/dist/web/http-server.js +12 -2
- package/dist/web/http-server.js.map +1 -1
- package/dist/web/index.js +4 -1
- package/dist/web/index.js.map +1 -1
- package/dist/web/middleware/error-handler.d.ts +0 -16
- package/dist/web/middleware/error-handler.d.ts.map +1 -1
- package/dist/web/middleware/error-handler.js +0 -18
- package/dist/web/middleware/error-handler.js.map +1 -1
- package/dist/web/middleware/request-logger.d.ts +2 -1
- package/dist/web/middleware/request-logger.d.ts.map +1 -1
- package/package.json +129 -136
- package/skills/rag-vault/SKILL.md +111 -111
- package/web-ui/dist/assets/index-BcRp9-z9.js +120 -0
- package/web-ui/dist/assets/index-ej8i4PGl.css +1 -0
- package/web-ui/dist/index.html +2 -2
- package/dist/utils/logger.d.ts +0 -36
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -64
- package/dist/utils/logger.js.map +0 -1
- package/web-ui/dist/assets/index-0kBxUnZc.css +0 -1
- package/web-ui/dist/assets/index-CaUT0xZD.js +0 -59
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error codes for type-safe error handling
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
declare const ErrorCodes: {
|
|
5
5
|
readonly RAG_ERROR: "RAG_ERROR";
|
|
6
6
|
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
7
7
|
readonly DATABASE_ERROR: "DATABASE_ERROR";
|
|
@@ -65,9 +65,5 @@ export declare class EmbeddingError extends RAGError {
|
|
|
65
65
|
* Get error message with optional stack trace (based on environment)
|
|
66
66
|
*/
|
|
67
67
|
export declare function getErrorMessage(error: Error): string;
|
|
68
|
-
|
|
69
|
-
* Check if an error is a RAGError instance
|
|
70
|
-
* @internal - available for internal use but may be useful for consumers
|
|
71
|
-
*/
|
|
72
|
-
export declare function isRAGError(error: unknown): error is RAGError;
|
|
68
|
+
export {};
|
|
73
69
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,QAAA,MAAM,UAAU;;;;;;;;;;;;;CAsBN,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAMpE;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,SAAS,CAAA;IAC/B,SAAgB,UAAU,EAAE,MAAM,CAAA;IAClC,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBAG1D,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,SAAS,CAAA;QAChB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC,KAAK,CAAC,EAAE,KAAK,CAAA;KACT;IASR,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAMD;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,KAAK;CAe9E;AAMD;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAE,SAAqC;CAaxF;AAMD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAa3C;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,QAAQ;gBACxC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAa3C;AAMD;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAa3C;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAKpD"}
|
package/dist/errors/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Centralized error classes for RAG operations
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EmbeddingError = exports.ParserFileOperationError = exports.ParserValidationError = exports.DatabaseError = exports.ValidationError = exports.RAGError =
|
|
4
|
+
exports.EmbeddingError = exports.ParserFileOperationError = exports.ParserValidationError = exports.DatabaseError = exports.ValidationError = exports.RAGError = void 0;
|
|
5
5
|
exports.getErrorMessage = getErrorMessage;
|
|
6
|
-
exports.isRAGError = isRAGError;
|
|
7
6
|
// ============================================
|
|
8
7
|
// Error Codes
|
|
9
8
|
// ============================================
|
|
10
9
|
/**
|
|
11
10
|
* Error codes for type-safe error handling
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
const ErrorCodes = {
|
|
14
13
|
// General
|
|
15
14
|
RAG_ERROR: 'RAG_ERROR',
|
|
16
15
|
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
@@ -39,7 +38,7 @@ class RAGError extends Error {
|
|
|
39
38
|
constructor(message, options = {}) {
|
|
40
39
|
super(message, options.cause ? { cause: options.cause } : undefined);
|
|
41
40
|
this.name = 'RAGError';
|
|
42
|
-
this.code = options.code ||
|
|
41
|
+
this.code = options.code || ErrorCodes.RAG_ERROR;
|
|
43
42
|
this.statusCode = options.statusCode || 500;
|
|
44
43
|
this.details = options.details;
|
|
45
44
|
}
|
|
@@ -63,7 +62,7 @@ exports.RAGError = RAGError;
|
|
|
63
62
|
class ValidationError extends RAGError {
|
|
64
63
|
constructor(message, details, cause) {
|
|
65
64
|
const opts = {
|
|
66
|
-
code:
|
|
65
|
+
code: ErrorCodes.VALIDATION_ERROR,
|
|
67
66
|
statusCode: 400,
|
|
68
67
|
};
|
|
69
68
|
if (details !== undefined)
|
|
@@ -82,7 +81,7 @@ exports.ValidationError = ValidationError;
|
|
|
82
81
|
* Database operation error
|
|
83
82
|
*/
|
|
84
83
|
class DatabaseError extends RAGError {
|
|
85
|
-
constructor(message, cause, code =
|
|
84
|
+
constructor(message, cause, code = ErrorCodes.DATABASE_ERROR) {
|
|
86
85
|
const opts = {
|
|
87
86
|
code,
|
|
88
87
|
statusCode: 500,
|
|
@@ -103,7 +102,7 @@ exports.DatabaseError = DatabaseError;
|
|
|
103
102
|
class ParserValidationError extends RAGError {
|
|
104
103
|
constructor(message, cause) {
|
|
105
104
|
const opts = {
|
|
106
|
-
code:
|
|
105
|
+
code: ErrorCodes.PARSER_VALIDATION_ERROR,
|
|
107
106
|
statusCode: 400,
|
|
108
107
|
};
|
|
109
108
|
if (cause !== undefined)
|
|
@@ -119,7 +118,7 @@ exports.ParserValidationError = ParserValidationError;
|
|
|
119
118
|
class ParserFileOperationError extends RAGError {
|
|
120
119
|
constructor(message, cause) {
|
|
121
120
|
const opts = {
|
|
122
|
-
code:
|
|
121
|
+
code: ErrorCodes.PARSER_FILE_OPERATION_ERROR,
|
|
123
122
|
statusCode: 500,
|
|
124
123
|
};
|
|
125
124
|
if (cause !== undefined)
|
|
@@ -138,7 +137,7 @@ exports.ParserFileOperationError = ParserFileOperationError;
|
|
|
138
137
|
class EmbeddingError extends RAGError {
|
|
139
138
|
constructor(message, cause) {
|
|
140
139
|
const opts = {
|
|
141
|
-
code:
|
|
140
|
+
code: ErrorCodes.EMBEDDING_ERROR,
|
|
142
141
|
statusCode: 500,
|
|
143
142
|
};
|
|
144
143
|
if (cause !== undefined)
|
|
@@ -160,11 +159,4 @@ function getErrorMessage(error) {
|
|
|
160
159
|
}
|
|
161
160
|
return error.stack || error.message;
|
|
162
161
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Check if an error is a RAGError instance
|
|
165
|
-
* @internal - available for internal use but may be useful for consumers
|
|
166
|
-
*/
|
|
167
|
-
function isRAGError(error) {
|
|
168
|
-
return error instanceof RAGError;
|
|
169
|
-
}
|
|
170
162
|
//# sourceMappingURL=index.js.map
|
package/dist/errors/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;AAkM/C,0CAKC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;AAkM/C,0CAKC;AArMD,+CAA+C;AAC/C,cAAc;AACd,+CAA+C;AAE/C;;GAEG;AACH,MAAM,UAAU,GAAG;IACjB,UAAU;IACV,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,kBAAkB;IAEpC,WAAW;IACX,cAAc,EAAE,gBAAgB;IAChC,yBAAyB,EAAE,2BAA2B;IACtD,oBAAoB,EAAE,sBAAsB;IAE5C,SAAS;IACT,uBAAuB,EAAE,yBAAyB;IAClD,2BAA2B,EAAE,6BAA6B;IAC1D,yBAAyB,EAAE,2BAA2B;IAEtD,YAAY;IACZ,eAAe,EAAE,iBAAiB;IAClC,qBAAqB,EAAE,uBAAuB;IAE9C,OAAO;IACP,aAAa,EAAE,eAAe;IAC9B,YAAY,EA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C,CAAC;CACF;AAdD,4DAcC;AAED,+CAA+C;AAC/C,mBAAmB;AACnB,+CAA+C;AAE/C;;GAEG;AACH,MAAa,cAAe,SAAQ,QAAQ;IAC1C,YAAY,OAAe,EAAE,KAAa;QACxC,MAAM,IAAI,GAIN;YACF,IAAI,EAAE,UAAU,CAAC,eAAe;YAChC,UAAU,EAAE,GAAG;SAChB,CAAA;QACD,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAC3C,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AAdD,wCAcC;AAED,+CAA+C;AAC/C,YAAY;AACZ,+CAA+C;AAE/C;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAY;IAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC,OAAO,CAAA;IACtB,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/explainability/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Explainability module for chunk similarity
|
|
3
|
+
// Provides keyword/phrase extraction and relationship reasoning
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.explainChunkSimilarity = void 0;
|
|
6
|
+
var keywords_js_1 = require("./keywords.js");
|
|
7
|
+
Object.defineProperty(exports, "explainChunkSimilarity", { enumerable: true, get: function () { return keywords_js_1.explainChunkSimilarity; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/explainability/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;AAC7C,gEAAgE;;;AAEhE,6CAAsD;AAA7C,qHAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reason label based on similarity characteristics
|
|
3
|
+
*/
|
|
4
|
+
type ReasonLabel = 'same_doc' | 'very_similar' | 'related_topic' | 'loosely_related';
|
|
5
|
+
/**
|
|
6
|
+
* Explanation for why two chunks are related
|
|
7
|
+
*/
|
|
8
|
+
interface ChunkExplanation {
|
|
9
|
+
sharedKeywords: string[];
|
|
10
|
+
sharedPhrases: string[];
|
|
11
|
+
reasonLabel: ReasonLabel;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate explanation for chunk relationship
|
|
15
|
+
*/
|
|
16
|
+
export declare function explainChunkSimilarity(sourceText: string, targetText: string, isSameDocument: boolean, similarityScore: number): ChunkExplanation;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=keywords.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/explainability/keywords.ts"],"names":[],"mappings":"AAqNA;;GAEG;AACH,KAAK,WAAW,GAAG,UAAU,GAAG,cAAc,GAAG,eAAe,GAAG,iBAAiB,CAAA;AAsCpF;;GAEG;AACH,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,WAAW,EAAE,WAAW,CAAA;CACzB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,OAAO,EACvB,eAAe,EAAE,MAAM,GACtB,gBAAgB,CAMlB"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Explainability utilities for chunk similarity
|
|
3
|
+
// Provides keyword/phrase extraction without LLM dependencies
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.explainChunkSimilarity = explainChunkSimilarity;
|
|
6
|
+
// Common English stopwords to filter out
|
|
7
|
+
const STOPWORDS = new Set([
|
|
8
|
+
'a',
|
|
9
|
+
'an',
|
|
10
|
+
'and',
|
|
11
|
+
'are',
|
|
12
|
+
'as',
|
|
13
|
+
'at',
|
|
14
|
+
'be',
|
|
15
|
+
'by',
|
|
16
|
+
'for',
|
|
17
|
+
'from',
|
|
18
|
+
'has',
|
|
19
|
+
'have',
|
|
20
|
+
'he',
|
|
21
|
+
'in',
|
|
22
|
+
'is',
|
|
23
|
+
'it',
|
|
24
|
+
'its',
|
|
25
|
+
'of',
|
|
26
|
+
'on',
|
|
27
|
+
'or',
|
|
28
|
+
'that',
|
|
29
|
+
'the',
|
|
30
|
+
'to',
|
|
31
|
+
'was',
|
|
32
|
+
'were',
|
|
33
|
+
'will',
|
|
34
|
+
'with',
|
|
35
|
+
'this',
|
|
36
|
+
'but',
|
|
37
|
+
'they',
|
|
38
|
+
'had',
|
|
39
|
+
'what',
|
|
40
|
+
'when',
|
|
41
|
+
'where',
|
|
42
|
+
'who',
|
|
43
|
+
'which',
|
|
44
|
+
'can',
|
|
45
|
+
'could',
|
|
46
|
+
'would',
|
|
47
|
+
'should',
|
|
48
|
+
'their',
|
|
49
|
+
'there',
|
|
50
|
+
'been',
|
|
51
|
+
'being',
|
|
52
|
+
'do',
|
|
53
|
+
'does',
|
|
54
|
+
'did',
|
|
55
|
+
'doing',
|
|
56
|
+
'these',
|
|
57
|
+
'those',
|
|
58
|
+
'then',
|
|
59
|
+
'than',
|
|
60
|
+
'so',
|
|
61
|
+
'if',
|
|
62
|
+
'not',
|
|
63
|
+
'no',
|
|
64
|
+
'nor',
|
|
65
|
+
'only',
|
|
66
|
+
'own',
|
|
67
|
+
'same',
|
|
68
|
+
'such',
|
|
69
|
+
'too',
|
|
70
|
+
'very',
|
|
71
|
+
'just',
|
|
72
|
+
'also',
|
|
73
|
+
'any',
|
|
74
|
+
'each',
|
|
75
|
+
'few',
|
|
76
|
+
'more',
|
|
77
|
+
'most',
|
|
78
|
+
'other',
|
|
79
|
+
'some',
|
|
80
|
+
'all',
|
|
81
|
+
'both',
|
|
82
|
+
'into',
|
|
83
|
+
'out',
|
|
84
|
+
'up',
|
|
85
|
+
'down',
|
|
86
|
+
'about',
|
|
87
|
+
'after',
|
|
88
|
+
'before',
|
|
89
|
+
'over',
|
|
90
|
+
'under',
|
|
91
|
+
'again',
|
|
92
|
+
'further',
|
|
93
|
+
'once',
|
|
94
|
+
'here',
|
|
95
|
+
'why',
|
|
96
|
+
'how',
|
|
97
|
+
'our',
|
|
98
|
+
'your',
|
|
99
|
+
'my',
|
|
100
|
+
'his',
|
|
101
|
+
'her',
|
|
102
|
+
'am',
|
|
103
|
+
'him',
|
|
104
|
+
'me',
|
|
105
|
+
'we',
|
|
106
|
+
'you',
|
|
107
|
+
'she',
|
|
108
|
+
'us',
|
|
109
|
+
'them',
|
|
110
|
+
]);
|
|
111
|
+
/**
|
|
112
|
+
* Tokenize text into words, filtering out stopwords and short words
|
|
113
|
+
*/
|
|
114
|
+
function tokenize(text, minLength = 3) {
|
|
115
|
+
return text
|
|
116
|
+
.toLowerCase()
|
|
117
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
118
|
+
.split(/\s+/)
|
|
119
|
+
.filter((word) => word.length >= minLength && !STOPWORDS.has(word));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Extract word frequency map from text
|
|
123
|
+
*/
|
|
124
|
+
function getWordFrequency(text) {
|
|
125
|
+
const words = tokenize(text);
|
|
126
|
+
const freq = new Map();
|
|
127
|
+
for (const word of words) {
|
|
128
|
+
freq.set(word, (freq.get(word) || 0) + 1);
|
|
129
|
+
}
|
|
130
|
+
return freq;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Generate n-grams from text
|
|
134
|
+
*/
|
|
135
|
+
function getNgrams(text, n) {
|
|
136
|
+
const words = tokenize(text, 2);
|
|
137
|
+
const ngrams = [];
|
|
138
|
+
for (let i = 0; i <= words.length - n; i++) {
|
|
139
|
+
ngrams.push(words.slice(i, i + n).join(' '));
|
|
140
|
+
}
|
|
141
|
+
return ngrams;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get n-gram frequency map
|
|
145
|
+
*/
|
|
146
|
+
function getNgramFrequency(text, n) {
|
|
147
|
+
const ngrams = getNgrams(text, n);
|
|
148
|
+
const freq = new Map();
|
|
149
|
+
for (const ngram of ngrams) {
|
|
150
|
+
freq.set(ngram, (freq.get(ngram) || 0) + 1);
|
|
151
|
+
}
|
|
152
|
+
return freq;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Find shared keywords between two texts
|
|
156
|
+
* Returns keywords sorted by combined frequency
|
|
157
|
+
*/
|
|
158
|
+
function findSharedKeywords(text1, text2, maxCount = 5) {
|
|
159
|
+
const freq1 = getWordFrequency(text1);
|
|
160
|
+
const freq2 = getWordFrequency(text2);
|
|
161
|
+
const shared = [];
|
|
162
|
+
for (const [word, count1] of freq1.entries()) {
|
|
163
|
+
const count2 = freq2.get(word);
|
|
164
|
+
if (count2) {
|
|
165
|
+
// Score by combined frequency
|
|
166
|
+
shared.push({ word, score: count1 + count2 });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Sort by score descending, then alphabetically
|
|
170
|
+
shared.sort((a, b) => b.score - a.score || a.word.localeCompare(b.word));
|
|
171
|
+
return shared.slice(0, maxCount).map((s) => s.word);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Find shared phrases (bigrams and trigrams) between two texts
|
|
175
|
+
* Returns phrases sorted by combined frequency
|
|
176
|
+
*/
|
|
177
|
+
function findSharedPhrases(text1, text2, maxCount = 3) {
|
|
178
|
+
const phrases = [];
|
|
179
|
+
// Check bigrams
|
|
180
|
+
const bigrams1 = getNgramFrequency(text1, 2);
|
|
181
|
+
const bigrams2 = getNgramFrequency(text2, 2);
|
|
182
|
+
for (const [phrase, count1] of bigrams1.entries()) {
|
|
183
|
+
const count2 = bigrams2.get(phrase);
|
|
184
|
+
if (count2) {
|
|
185
|
+
phrases.push({ phrase, score: (count1 + count2) * 2 }); // Weight bigrams
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Check trigrams (higher weight)
|
|
189
|
+
const trigrams1 = getNgramFrequency(text1, 3);
|
|
190
|
+
const trigrams2 = getNgramFrequency(text2, 3);
|
|
191
|
+
for (const [phrase, count1] of trigrams1.entries()) {
|
|
192
|
+
const count2 = trigrams2.get(phrase);
|
|
193
|
+
if (count2) {
|
|
194
|
+
phrases.push({ phrase, score: (count1 + count2) * 3 }); // Weight trigrams higher
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Sort by score descending
|
|
198
|
+
phrases.sort((a, b) => b.score - a.score);
|
|
199
|
+
return phrases.slice(0, maxCount).map((p) => p.phrase);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Determine relationship reason based on heuristics
|
|
203
|
+
* - High lexical overlap → "very_similar"
|
|
204
|
+
* - Low lexical overlap + context → "related_topic"
|
|
205
|
+
* - Same document → "same_doc"
|
|
206
|
+
*/
|
|
207
|
+
function determineReasonLabel(text1, text2, isSameDocument, similarityScore) {
|
|
208
|
+
if (isSameDocument) {
|
|
209
|
+
return 'same_doc';
|
|
210
|
+
}
|
|
211
|
+
// Calculate lexical overlap ratio
|
|
212
|
+
const words1 = new Set(tokenize(text1));
|
|
213
|
+
const words2 = new Set(tokenize(text2));
|
|
214
|
+
const intersection = [...words1].filter((w) => words2.has(w)).length;
|
|
215
|
+
const union = new Set([...words1, ...words2]).size;
|
|
216
|
+
const jaccard = union > 0 ? intersection / union : 0;
|
|
217
|
+
// High similarity score (low distance) with high lexical overlap
|
|
218
|
+
if (similarityScore < 0.3 && jaccard > 0.3) {
|
|
219
|
+
return 'very_similar';
|
|
220
|
+
}
|
|
221
|
+
// Moderate similarity with some lexical overlap
|
|
222
|
+
if (similarityScore < 0.5 || jaccard > 0.15) {
|
|
223
|
+
return 'related_topic';
|
|
224
|
+
}
|
|
225
|
+
return 'loosely_related';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Generate explanation for chunk relationship
|
|
229
|
+
*/
|
|
230
|
+
function explainChunkSimilarity(sourceText, targetText, isSameDocument, similarityScore) {
|
|
231
|
+
return {
|
|
232
|
+
sharedKeywords: findSharedKeywords(sourceText, targetText),
|
|
233
|
+
sharedPhrases: findSharedPhrases(sourceText, targetText),
|
|
234
|
+
reasonLabel: determineReasonLabel(sourceText, targetText, isSameDocument, similarityScore),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=keywords.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.js","sourceRoot":"","sources":["../../src/explainability/keywords.ts"],"names":[],"mappings":";AAAA,gDAAgD;AAChD,8DAA8D;;AAyQ9D,wDAWC;AAlRD,yCAAyC;AACzC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,IAAI;IACJ,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,KAAK;IACL,OAAO;IACP,KAAK;IACL,OAAO;IACP,OAAO;IACP,QAAQ;IACR,OA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AM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IACpE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;IAClD,MAAM,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAEpD,iEAAiE;IACjE,IAAI,eAAe,GAAG,GAAG,IAAI,OAAO,GAAG,GAAG,EAAE,CAAC;QAC3C,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,gDAAgD;IAChD,IAAI,eAAe,GAAG,GAAG,IAAI,OAAO,GAAG,IAAI,EAAE,CAAC;QAC5C,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AAWD;;GAEG;AACH,SAAgB,sBAAsB,CACpC,UAAkB,EAClB,UAAkB,EAClB,cAAuB,EACvB,eAAuB;IAEvB,OAAO;QACL,cAAc,EAAE,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC;QAC1D,aAAa,EAAE,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC;QACxD,WAAW,EAAE,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,CAAC;KAC3F,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of user feedback events
|
|
3
|
+
*/
|
|
4
|
+
export type FeedbackEventType = 'pin' | 'unpin' | 'dismiss_inferred' | 'click_related';
|
|
5
|
+
/**
|
|
6
|
+
* Reference to a chunk (using fingerprint for resilience)
|
|
7
|
+
*/
|
|
8
|
+
export interface ChunkRef {
|
|
9
|
+
filePath: string;
|
|
10
|
+
chunkIndex: number;
|
|
11
|
+
fingerprint?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A feedback event from user interaction
|
|
15
|
+
*/
|
|
16
|
+
interface FeedbackEvent {
|
|
17
|
+
type: FeedbackEventType;
|
|
18
|
+
source: ChunkRef;
|
|
19
|
+
target: ChunkRef;
|
|
20
|
+
timestamp: Date;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Search result with score
|
|
24
|
+
*/
|
|
25
|
+
interface ScoredResult {
|
|
26
|
+
filePath: string;
|
|
27
|
+
chunkIndex: number;
|
|
28
|
+
fingerprint?: string;
|
|
29
|
+
score: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Flywheel configuration
|
|
33
|
+
*/
|
|
34
|
+
interface FlywheelConfig {
|
|
35
|
+
/** Boost multiplier for pinned targets (default: 1.3) */
|
|
36
|
+
pinBoost: number;
|
|
37
|
+
/** Boost multiplier for co-pinned patterns (default: 1.15) */
|
|
38
|
+
coPinBoost: number;
|
|
39
|
+
/** Penalty multiplier for dismissed suggestions (default: 0.5) */
|
|
40
|
+
dismissPenalty: number;
|
|
41
|
+
/** Maximum age for feedback events in ms (default: 30 days) */
|
|
42
|
+
maxEventAge: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* FeedbackStore: In-memory store for feedback events
|
|
46
|
+
* Can be persisted to disk for long-term learning
|
|
47
|
+
*/
|
|
48
|
+
export declare class FeedbackStore {
|
|
49
|
+
private events;
|
|
50
|
+
private config;
|
|
51
|
+
private pinnedPairs;
|
|
52
|
+
private dismissedPairs;
|
|
53
|
+
private coPinnedWith;
|
|
54
|
+
constructor(config?: Partial<FlywheelConfig>);
|
|
55
|
+
/**
|
|
56
|
+
* Record a feedback event
|
|
57
|
+
*/
|
|
58
|
+
recordEvent(event: FeedbackEvent): void;
|
|
59
|
+
/**
|
|
60
|
+
* Update index structures based on event
|
|
61
|
+
*/
|
|
62
|
+
private updateIndices;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a source-target pair is pinned
|
|
65
|
+
*/
|
|
66
|
+
isPinned(source: ChunkRef, target: ChunkRef): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Check if a source-target pair was dismissed
|
|
69
|
+
*/
|
|
70
|
+
wasDismissed(source: ChunkRef, target: ChunkRef): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Check if target matches a co-pinned pattern with source
|
|
73
|
+
*/
|
|
74
|
+
matchesCoPinnedPattern(source: ChunkRef, target: ChunkRef): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Re-rank results based on feedback
|
|
77
|
+
*/
|
|
78
|
+
rerankResults<T extends ScoredResult>(results: T[], source: ChunkRef): T[];
|
|
79
|
+
/**
|
|
80
|
+
* Clean up old events
|
|
81
|
+
*/
|
|
82
|
+
pruneOldEvents(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Export events for persistence
|
|
85
|
+
*/
|
|
86
|
+
exportEvents(): FeedbackEvent[];
|
|
87
|
+
/**
|
|
88
|
+
* Import events (e.g., from disk)
|
|
89
|
+
*/
|
|
90
|
+
importEvents(events: FeedbackEvent[]): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get statistics about feedback store
|
|
93
|
+
*/
|
|
94
|
+
getStats(): {
|
|
95
|
+
eventCount: number;
|
|
96
|
+
pinnedPairs: number;
|
|
97
|
+
dismissedPairs: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get or create the global feedback store
|
|
102
|
+
*/
|
|
103
|
+
export declare function getFeedbackStore(): FeedbackStore;
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../src/flywheel/feedback.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,OAAO,GAAG,kBAAkB,GAAG,eAAe,CAAA;AAEtF;;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