@danielsimonjr/memory-mcp 11.0.1 → 11.1.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 (172) hide show
  1. package/LICENSE +22 -22
  2. package/dist/core/EntityManager.d.ts +10 -15
  3. package/dist/core/EntityManager.d.ts.map +1 -1
  4. package/dist/core/EntityManager.js +21 -54
  5. package/dist/core/GraphStorage.d.ts +0 -51
  6. package/dist/core/GraphStorage.d.ts.map +1 -1
  7. package/dist/core/GraphStorage.js +2 -79
  8. package/dist/core/GraphTraversal.d.ts +2 -7
  9. package/dist/core/GraphTraversal.d.ts.map +1 -1
  10. package/dist/core/GraphTraversal.js +2 -19
  11. package/dist/core/ManagerContext.d.ts +0 -4
  12. package/dist/core/ManagerContext.d.ts.map +1 -1
  13. package/dist/core/ManagerContext.js +2 -12
  14. package/dist/core/RelationManager.d.ts.map +1 -1
  15. package/dist/core/RelationManager.js +4 -5
  16. package/dist/core/SQLiteStorage.d.ts.map +1 -1
  17. package/dist/core/SQLiteStorage.js +2 -3
  18. package/dist/core/TransactionManager.d.ts +2 -207
  19. package/dist/core/TransactionManager.d.ts.map +1 -1
  20. package/dist/core/TransactionManager.js +6 -482
  21. package/dist/core/index.d.ts +1 -2
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +1 -3
  24. package/dist/features/ArchiveManager.d.ts +2 -14
  25. package/dist/features/ArchiveManager.d.ts.map +1 -1
  26. package/dist/features/ArchiveManager.js +3 -44
  27. package/dist/features/CompressionManager.d.ts +4 -14
  28. package/dist/features/CompressionManager.d.ts.map +1 -1
  29. package/dist/features/CompressionManager.js +9 -74
  30. package/dist/features/IOManager.d.ts +2 -6
  31. package/dist/features/IOManager.d.ts.map +1 -1
  32. package/dist/features/IOManager.js +10 -105
  33. package/dist/features/StreamingExporter.d.ts +4 -27
  34. package/dist/features/StreamingExporter.d.ts.map +1 -1
  35. package/dist/features/StreamingExporter.js +4 -65
  36. package/dist/features/index.d.ts +0 -2
  37. package/dist/features/index.d.ts.map +1 -1
  38. package/dist/features/index.js +0 -3
  39. package/dist/search/EmbeddingService.d.ts +9 -108
  40. package/dist/search/EmbeddingService.d.ts.map +1 -1
  41. package/dist/search/EmbeddingService.js +15 -187
  42. package/dist/search/FuzzySearch.js +1 -1
  43. package/dist/search/SavedSearchManager.d.ts.map +1 -1
  44. package/dist/search/SavedSearchManager.js +2 -3
  45. package/dist/search/SearchManager.d.ts +1 -42
  46. package/dist/search/SearchManager.d.ts.map +1 -1
  47. package/dist/search/SearchManager.js +0 -115
  48. package/dist/search/SemanticSearch.d.ts +1 -4
  49. package/dist/search/SemanticSearch.d.ts.map +1 -1
  50. package/dist/search/SemanticSearch.js +2 -12
  51. package/dist/search/TFIDFIndexManager.d.ts +0 -88
  52. package/dist/search/TFIDFIndexManager.d.ts.map +1 -1
  53. package/dist/search/TFIDFIndexManager.js +0 -217
  54. package/dist/search/index.d.ts +1 -18
  55. package/dist/search/index.d.ts.map +1 -1
  56. package/dist/search/index.js +1 -32
  57. package/dist/server/MCPServer.d.ts.map +1 -1
  58. package/dist/server/MCPServer.js +4 -1
  59. package/dist/server/responseCompressor.js +5 -5
  60. package/dist/server/toolDefinitions.d.ts.map +1 -1
  61. package/dist/server/toolDefinitions.js +5 -1
  62. package/dist/server/toolHandlers.d.ts +9 -5
  63. package/dist/server/toolHandlers.d.ts.map +1 -1
  64. package/dist/server/toolHandlers.js +23 -8
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/types.d.ts +2 -579
  68. package/dist/types/types.d.ts.map +1 -1
  69. package/dist/utils/compressedCache.d.ts +0 -29
  70. package/dist/utils/compressedCache.d.ts.map +1 -1
  71. package/dist/utils/compressedCache.js +0 -39
  72. package/dist/utils/entityUtils.d.ts +1 -59
  73. package/dist/utils/entityUtils.d.ts.map +1 -1
  74. package/dist/utils/entityUtils.js +3 -113
  75. package/dist/utils/errors.d.ts +0 -18
  76. package/dist/utils/errors.d.ts.map +1 -1
  77. package/dist/utils/errors.js +0 -24
  78. package/dist/utils/index.d.ts +2 -6
  79. package/dist/utils/index.d.ts.map +1 -1
  80. package/dist/utils/index.js +2 -14
  81. package/dist/utils/logger.d.ts +0 -7
  82. package/dist/utils/logger.d.ts.map +1 -1
  83. package/dist/utils/logger.js +2 -9
  84. package/dist/utils/parallelUtils.d.ts +1 -5
  85. package/dist/utils/parallelUtils.d.ts.map +1 -1
  86. package/dist/utils/parallelUtils.js +1 -23
  87. package/dist/utils/schemas.d.ts +16 -16
  88. package/dist/utils/schemas.d.ts.map +1 -1
  89. package/dist/utils/schemas.js +12 -12
  90. package/dist/utils/taskScheduler.d.ts +0 -4
  91. package/dist/utils/taskScheduler.d.ts.map +1 -1
  92. package/dist/utils/taskScheduler.js +1 -21
  93. package/dist/workers/WorkerPool.d.ts +81 -0
  94. package/dist/workers/WorkerPool.d.ts.map +1 -0
  95. package/dist/workers/WorkerPool.js +121 -0
  96. package/dist/workers/index.d.ts +1 -1
  97. package/dist/workers/index.d.ts.map +1 -1
  98. package/dist/workers/levenshteinWorker.js +1 -1
  99. package/package.json +1 -4
  100. package/dist/__tests__/file-path.test.js +0 -119
  101. package/dist/__tests__/knowledge-graph.test.js +0 -318
  102. package/dist/core/GraphEventEmitter.d.ts +0 -202
  103. package/dist/core/GraphEventEmitter.d.ts.map +0 -1
  104. package/dist/core/GraphEventEmitter.js +0 -346
  105. package/dist/features/KeywordExtractor.d.ts +0 -61
  106. package/dist/features/KeywordExtractor.d.ts.map +0 -1
  107. package/dist/features/KeywordExtractor.js +0 -126
  108. package/dist/features/ObservationNormalizer.d.ts +0 -90
  109. package/dist/features/ObservationNormalizer.d.ts.map +0 -1
  110. package/dist/features/ObservationNormalizer.js +0 -193
  111. package/dist/memory.jsonl +0 -1
  112. package/dist/search/BM25Search.d.ts +0 -148
  113. package/dist/search/BM25Search.d.ts.map +0 -1
  114. package/dist/search/BM25Search.js +0 -339
  115. package/dist/search/EarlyTerminationManager.d.ts +0 -140
  116. package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
  117. package/dist/search/EarlyTerminationManager.js +0 -279
  118. package/dist/search/EmbeddingCache.d.ts +0 -175
  119. package/dist/search/EmbeddingCache.d.ts.map +0 -1
  120. package/dist/search/EmbeddingCache.js +0 -246
  121. package/dist/search/HybridScorer.d.ts +0 -181
  122. package/dist/search/HybridScorer.d.ts.map +0 -1
  123. package/dist/search/HybridScorer.js +0 -257
  124. package/dist/search/HybridSearchManager.d.ts +0 -80
  125. package/dist/search/HybridSearchManager.d.ts.map +0 -1
  126. package/dist/search/HybridSearchManager.js +0 -187
  127. package/dist/search/IncrementalIndexer.d.ts +0 -201
  128. package/dist/search/IncrementalIndexer.d.ts.map +0 -1
  129. package/dist/search/IncrementalIndexer.js +0 -342
  130. package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
  131. package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
  132. package/dist/search/OptimizedInvertedIndex.js +0 -358
  133. package/dist/search/ParallelSearchExecutor.d.ts +0 -172
  134. package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
  135. package/dist/search/ParallelSearchExecutor.js +0 -309
  136. package/dist/search/QuantizedVectorStore.d.ts +0 -171
  137. package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
  138. package/dist/search/QuantizedVectorStore.js +0 -307
  139. package/dist/search/QueryAnalyzer.d.ts +0 -76
  140. package/dist/search/QueryAnalyzer.d.ts.map +0 -1
  141. package/dist/search/QueryAnalyzer.js +0 -227
  142. package/dist/search/QueryCostEstimator.d.ts +0 -244
  143. package/dist/search/QueryCostEstimator.d.ts.map +0 -1
  144. package/dist/search/QueryCostEstimator.js +0 -652
  145. package/dist/search/QueryPlanCache.d.ts +0 -220
  146. package/dist/search/QueryPlanCache.d.ts.map +0 -1
  147. package/dist/search/QueryPlanCache.js +0 -379
  148. package/dist/search/QueryPlanner.d.ts +0 -58
  149. package/dist/search/QueryPlanner.d.ts.map +0 -1
  150. package/dist/search/QueryPlanner.js +0 -137
  151. package/dist/search/ReflectionManager.d.ts +0 -120
  152. package/dist/search/ReflectionManager.d.ts.map +0 -1
  153. package/dist/search/ReflectionManager.js +0 -231
  154. package/dist/search/SymbolicSearch.d.ts +0 -61
  155. package/dist/search/SymbolicSearch.d.ts.map +0 -1
  156. package/dist/search/SymbolicSearch.js +0 -163
  157. package/dist/search/TFIDFEventSync.d.ts +0 -85
  158. package/dist/search/TFIDFEventSync.d.ts.map +0 -1
  159. package/dist/search/TFIDFEventSync.js +0 -133
  160. package/dist/utils/BatchProcessor.d.ts +0 -271
  161. package/dist/utils/BatchProcessor.d.ts.map +0 -1
  162. package/dist/utils/BatchProcessor.js +0 -376
  163. package/dist/utils/MemoryMonitor.d.ts +0 -176
  164. package/dist/utils/MemoryMonitor.d.ts.map +0 -1
  165. package/dist/utils/MemoryMonitor.js +0 -305
  166. package/dist/utils/WorkerPoolManager.d.ts +0 -233
  167. package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
  168. package/dist/utils/WorkerPoolManager.js +0 -420
  169. package/dist/utils/operationUtils.d.ts +0 -124
  170. package/dist/utils/operationUtils.d.ts.map +0 -1
  171. package/dist/utils/operationUtils.js +0 -175
  172. package/dist/vitest.config.js +0 -13
@@ -1,346 +0,0 @@
1
- /**
2
- * Graph Event Emitter
3
- *
4
- * Phase 10 Sprint 2: Provides event-based notifications for graph changes.
5
- * Enables loose coupling between graph operations and dependent systems
6
- * like search indexes, analytics, and external integrations.
7
- *
8
- * @module core/GraphEventEmitter
9
- */
10
- /**
11
- * Phase 10 Sprint 2: Event emitter for graph change notifications.
12
- *
13
- * Provides a type-safe event system for subscribing to and emitting
14
- * graph change events. Supports wildcard listeners for all events.
15
- *
16
- * @example
17
- * ```typescript
18
- * const emitter = new GraphEventEmitter();
19
- *
20
- * // Listen to specific event types
21
- * emitter.on('entity:created', (event) => {
22
- * console.log(`Entity ${event.entity.name} created`);
23
- * });
24
- *
25
- * // Listen to all events
26
- * emitter.onAny((event) => {
27
- * console.log(`Event: ${event.type}`);
28
- * });
29
- *
30
- * // Emit an event
31
- * emitter.emitEntityCreated(entity);
32
- *
33
- * // Remove listener
34
- * const unsubscribe = emitter.on('entity:deleted', handler);
35
- * unsubscribe();
36
- * ```
37
- */
38
- export class GraphEventEmitter {
39
- /**
40
- * Map of event types to their registered listeners.
41
- */
42
- listeners = new Map();
43
- /**
44
- * Listeners that receive all events regardless of type.
45
- */
46
- wildcardListeners = new Set();
47
- /**
48
- * Whether to suppress errors from listeners (default: true).
49
- * When true, listener errors are logged but don't stop event propagation.
50
- */
51
- suppressListenerErrors = true;
52
- /**
53
- * Create a new GraphEventEmitter instance.
54
- *
55
- * @param options - Optional configuration
56
- */
57
- constructor(options) {
58
- if (options?.suppressListenerErrors !== undefined) {
59
- this.suppressListenerErrors = options.suppressListenerErrors;
60
- }
61
- }
62
- // ==================== Subscription Methods ====================
63
- /**
64
- * Subscribe to a specific event type.
65
- *
66
- * @template K - The event type key
67
- * @param eventType - The event type to listen for
68
- * @param listener - Callback function to invoke when event occurs
69
- * @returns Unsubscribe function to remove the listener
70
- *
71
- * @example
72
- * ```typescript
73
- * const unsubscribe = emitter.on('entity:created', (event) => {
74
- * console.log(`Created: ${event.entity.name}`);
75
- * });
76
- *
77
- * // Later: unsubscribe();
78
- * ```
79
- */
80
- on(eventType, listener) {
81
- if (!this.listeners.has(eventType)) {
82
- this.listeners.set(eventType, new Set());
83
- }
84
- this.listeners.get(eventType).add(listener);
85
- // Return unsubscribe function
86
- return () => {
87
- this.off(eventType, listener);
88
- };
89
- }
90
- /**
91
- * Unsubscribe from a specific event type.
92
- *
93
- * @template K - The event type key
94
- * @param eventType - The event type to unsubscribe from
95
- * @param listener - The listener function to remove
96
- */
97
- off(eventType, listener) {
98
- const listeners = this.listeners.get(eventType);
99
- if (listeners) {
100
- listeners.delete(listener);
101
- }
102
- }
103
- /**
104
- * Subscribe to all event types.
105
- *
106
- * @param listener - Callback function to invoke for any event
107
- * @returns Unsubscribe function to remove the listener
108
- *
109
- * @example
110
- * ```typescript
111
- * emitter.onAny((event) => {
112
- * console.log(`Event: ${event.type} at ${event.timestamp}`);
113
- * });
114
- * ```
115
- */
116
- onAny(listener) {
117
- this.wildcardListeners.add(listener);
118
- return () => {
119
- this.offAny(listener);
120
- };
121
- }
122
- /**
123
- * Unsubscribe from all events.
124
- *
125
- * @param listener - The listener function to remove
126
- */
127
- offAny(listener) {
128
- this.wildcardListeners.delete(listener);
129
- }
130
- /**
131
- * Subscribe to an event type, but only receive the first occurrence.
132
- *
133
- * @template K - The event type key
134
- * @param eventType - The event type to listen for once
135
- * @param listener - Callback function to invoke once
136
- * @returns Unsubscribe function to cancel before event occurs
137
- */
138
- once(eventType, listener) {
139
- const wrappedListener = ((event) => {
140
- this.off(eventType, wrappedListener);
141
- listener(event);
142
- });
143
- return this.on(eventType, wrappedListener);
144
- }
145
- /**
146
- * Remove all listeners for all event types.
147
- */
148
- removeAllListeners() {
149
- this.listeners.clear();
150
- this.wildcardListeners.clear();
151
- }
152
- /**
153
- * Get the count of listeners for a specific event type.
154
- *
155
- * @param eventType - The event type to count listeners for
156
- * @returns Number of listeners registered
157
- */
158
- listenerCount(eventType) {
159
- if (eventType) {
160
- return (this.listeners.get(eventType)?.size ?? 0) + this.wildcardListeners.size;
161
- }
162
- // Count all listeners
163
- let count = this.wildcardListeners.size;
164
- for (const listeners of this.listeners.values()) {
165
- count += listeners.size;
166
- }
167
- return count;
168
- }
169
- // ==================== Emit Methods ====================
170
- /**
171
- * Emit an event to all registered listeners.
172
- *
173
- * @param event - The event to emit
174
- */
175
- emit(event) {
176
- // Notify type-specific listeners
177
- const typeListeners = this.listeners.get(event.type);
178
- if (typeListeners) {
179
- for (const listener of typeListeners) {
180
- this.invokeListener(listener, event);
181
- }
182
- }
183
- // Notify wildcard listeners
184
- for (const listener of this.wildcardListeners) {
185
- this.invokeListener(listener, event);
186
- }
187
- }
188
- /**
189
- * Emit an entity:created event.
190
- *
191
- * @param entity - The entity that was created
192
- */
193
- emitEntityCreated(entity) {
194
- const event = {
195
- type: 'entity:created',
196
- timestamp: new Date().toISOString(),
197
- entity,
198
- };
199
- this.emit(event);
200
- }
201
- /**
202
- * Emit an entity:updated event.
203
- *
204
- * @param entityName - Name of the updated entity
205
- * @param changes - The changes that were applied
206
- * @param previousValues - Optional previous values before update
207
- */
208
- emitEntityUpdated(entityName, changes, previousValues) {
209
- const event = {
210
- type: 'entity:updated',
211
- timestamp: new Date().toISOString(),
212
- entityName,
213
- changes,
214
- previousValues,
215
- };
216
- this.emit(event);
217
- }
218
- /**
219
- * Emit an entity:deleted event.
220
- *
221
- * @param entityName - Name of the deleted entity
222
- * @param entity - Optional entity data before deletion
223
- */
224
- emitEntityDeleted(entityName, entity) {
225
- const event = {
226
- type: 'entity:deleted',
227
- timestamp: new Date().toISOString(),
228
- entityName,
229
- entity,
230
- };
231
- this.emit(event);
232
- }
233
- /**
234
- * Emit a relation:created event.
235
- *
236
- * @param relation - The relation that was created
237
- */
238
- emitRelationCreated(relation) {
239
- const event = {
240
- type: 'relation:created',
241
- timestamp: new Date().toISOString(),
242
- relation,
243
- };
244
- this.emit(event);
245
- }
246
- /**
247
- * Emit a relation:deleted event.
248
- *
249
- * @param from - Source entity name
250
- * @param to - Target entity name
251
- * @param relationType - Type of the deleted relation
252
- */
253
- emitRelationDeleted(from, to, relationType) {
254
- const event = {
255
- type: 'relation:deleted',
256
- timestamp: new Date().toISOString(),
257
- from,
258
- to,
259
- relationType,
260
- };
261
- this.emit(event);
262
- }
263
- /**
264
- * Emit an observation:added event.
265
- *
266
- * @param entityName - Name of the entity
267
- * @param observations - Observations that were added
268
- */
269
- emitObservationAdded(entityName, observations) {
270
- if (observations.length === 0)
271
- return;
272
- const event = {
273
- type: 'observation:added',
274
- timestamp: new Date().toISOString(),
275
- entityName,
276
- observations,
277
- };
278
- this.emit(event);
279
- }
280
- /**
281
- * Emit an observation:deleted event.
282
- *
283
- * @param entityName - Name of the entity
284
- * @param observations - Observations that were deleted
285
- */
286
- emitObservationDeleted(entityName, observations) {
287
- if (observations.length === 0)
288
- return;
289
- const event = {
290
- type: 'observation:deleted',
291
- timestamp: new Date().toISOString(),
292
- entityName,
293
- observations,
294
- };
295
- this.emit(event);
296
- }
297
- /**
298
- * Emit a graph:saved event.
299
- *
300
- * @param entityCount - Number of entities in the saved graph
301
- * @param relationCount - Number of relations in the saved graph
302
- */
303
- emitGraphSaved(entityCount, relationCount) {
304
- const event = {
305
- type: 'graph:saved',
306
- timestamp: new Date().toISOString(),
307
- entityCount,
308
- relationCount,
309
- };
310
- this.emit(event);
311
- }
312
- /**
313
- * Emit a graph:loaded event.
314
- *
315
- * @param entityCount - Number of entities in the loaded graph
316
- * @param relationCount - Number of relations in the loaded graph
317
- */
318
- emitGraphLoaded(entityCount, relationCount) {
319
- const event = {
320
- type: 'graph:loaded',
321
- timestamp: new Date().toISOString(),
322
- entityCount,
323
- relationCount,
324
- };
325
- this.emit(event);
326
- }
327
- // ==================== Helper Methods ====================
328
- /**
329
- * Safely invoke a listener, optionally catching errors.
330
- * @private
331
- */
332
- invokeListener(listener, event) {
333
- if (this.suppressListenerErrors) {
334
- try {
335
- listener(event);
336
- }
337
- catch (error) {
338
- // Log but don't propagate errors from listeners
339
- console.error(`GraphEventEmitter: Listener error for ${event.type}:`, error);
340
- }
341
- }
342
- else {
343
- listener(event);
344
- }
345
- }
346
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Keyword Extractor
3
- *
4
- * Phase 11: Extracts and scores keywords from text
5
- * for lexical search enhancement.
6
- *
7
- * @module features/KeywordExtractor
8
- */
9
- /**
10
- * A keyword with importance score.
11
- */
12
- export interface ScoredKeyword {
13
- keyword: string;
14
- score: number;
15
- positions: number[];
16
- }
17
- /**
18
- * Keyword Extractor extracts and scores keywords from text.
19
- *
20
- * Features:
21
- * - Position-based scoring (earlier = more important)
22
- * - Domain-specific keyword boosting
23
- * - Length-based scoring (longer words often more specific)
24
- * - Stopword filtering
25
- *
26
- * @example
27
- * ```typescript
28
- * const extractor = new KeywordExtractor();
29
- * const keywords = extractor.extract('The software project was completed on time');
30
- * // Returns scored keywords sorted by importance
31
- * ```
32
- */
33
- export declare class KeywordExtractor {
34
- private stopwords;
35
- private domainBoosts;
36
- constructor();
37
- /**
38
- * Extract keywords with scores from text.
39
- */
40
- extract(text: string): ScoredKeyword[];
41
- private tokenize;
42
- private isKeyword;
43
- private calculateScore;
44
- /**
45
- * Extract top N keywords.
46
- */
47
- extractTop(text: string, n: number): string[];
48
- /**
49
- * Add custom domain boost for a keyword.
50
- */
51
- addDomainBoost(keyword: string, boost: number): void;
52
- /**
53
- * Remove a domain boost.
54
- */
55
- removeDomainBoost(keyword: string): boolean;
56
- /**
57
- * Get all domain boosts.
58
- */
59
- getDomainBoosts(): Map<string, number>;
60
- }
61
- //# sourceMappingURL=KeywordExtractor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeywordExtractor.d.ts","sourceRoot":"","sources":["../../src/features/KeywordExtractor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,YAAY,CAAsB;;IA2B1C;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE;IAyBtC,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAM7C;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpD;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI3C;;OAEG;IACH,eAAe,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAGvC"}
@@ -1,126 +0,0 @@
1
- /**
2
- * Keyword Extractor
3
- *
4
- * Phase 11: Extracts and scores keywords from text
5
- * for lexical search enhancement.
6
- *
7
- * @module features/KeywordExtractor
8
- */
9
- /**
10
- * Keyword Extractor extracts and scores keywords from text.
11
- *
12
- * Features:
13
- * - Position-based scoring (earlier = more important)
14
- * - Domain-specific keyword boosting
15
- * - Length-based scoring (longer words often more specific)
16
- * - Stopword filtering
17
- *
18
- * @example
19
- * ```typescript
20
- * const extractor = new KeywordExtractor();
21
- * const keywords = extractor.extract('The software project was completed on time');
22
- * // Returns scored keywords sorted by importance
23
- * ```
24
- */
25
- export class KeywordExtractor {
26
- stopwords;
27
- domainBoosts;
28
- constructor() {
29
- this.stopwords = new Set([
30
- 'a', 'an', 'the', 'is', 'are', 'was', 'were', 'be', 'been',
31
- 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would',
32
- 'could', 'should', 'can', 'to', 'of', 'in', 'for', 'on',
33
- 'with', 'at', 'by', 'from', 'as', 'and', 'or', 'but',
34
- ]);
35
- this.domainBoosts = new Map([
36
- ['project', 1.5],
37
- ['task', 1.5],
38
- ['meeting', 1.3],
39
- ['deadline', 1.4],
40
- ['completed', 1.2],
41
- ['started', 1.2],
42
- ['person', 1.3],
43
- ['company', 1.3],
44
- ['team', 1.3],
45
- ['release', 1.4],
46
- ['feature', 1.3],
47
- ['bug', 1.2],
48
- ['issue', 1.2],
49
- ['milestone', 1.4],
50
- ]);
51
- }
52
- /**
53
- * Extract keywords with scores from text.
54
- */
55
- extract(text) {
56
- const words = this.tokenize(text);
57
- const keywordMap = new Map();
58
- for (let i = 0; i < words.length; i++) {
59
- const word = words[i].toLowerCase();
60
- if (this.isKeyword(word)) {
61
- const existing = keywordMap.get(word);
62
- if (existing) {
63
- existing.positions.push(i);
64
- existing.score += this.calculateScore(word, i, words.length);
65
- }
66
- else {
67
- keywordMap.set(word, {
68
- keyword: word,
69
- score: this.calculateScore(word, i, words.length),
70
- positions: [i],
71
- });
72
- }
73
- }
74
- }
75
- return Array.from(keywordMap.values())
76
- .sort((a, b) => b.score - a.score);
77
- }
78
- tokenize(text) {
79
- return text
80
- .replace(/[^a-zA-Z0-9\s]/g, ' ')
81
- .split(/\s+/)
82
- .filter(w => w.length > 0);
83
- }
84
- isKeyword(word) {
85
- return word.length > 2 && !this.stopwords.has(word);
86
- }
87
- calculateScore(word, position, totalWords) {
88
- let score = 1.0;
89
- // Position boost (earlier = more important)
90
- const positionFactor = 1 - (position / totalWords) * 0.3;
91
- score *= positionFactor;
92
- // Domain boost
93
- const boost = this.domainBoosts.get(word) ?? 1.0;
94
- score *= boost;
95
- // Length boost (longer words often more specific)
96
- if (word.length > 6)
97
- score *= 1.1;
98
- return score;
99
- }
100
- /**
101
- * Extract top N keywords.
102
- */
103
- extractTop(text, n) {
104
- return this.extract(text)
105
- .slice(0, n)
106
- .map(k => k.keyword);
107
- }
108
- /**
109
- * Add custom domain boost for a keyword.
110
- */
111
- addDomainBoost(keyword, boost) {
112
- this.domainBoosts.set(keyword.toLowerCase(), boost);
113
- }
114
- /**
115
- * Remove a domain boost.
116
- */
117
- removeDomainBoost(keyword) {
118
- return this.domainBoosts.delete(keyword.toLowerCase());
119
- }
120
- /**
121
- * Get all domain boosts.
122
- */
123
- getDomainBoosts() {
124
- return new Map(this.domainBoosts);
125
- }
126
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * Observation Normalizer
3
- *
4
- * Phase 11: Transforms observations to be self-contained facts
5
- * through coreference resolution and temporal anchoring.
6
- *
7
- * @module features/ObservationNormalizer
8
- */
9
- import type { Entity } from '../types/index.js';
10
- /**
11
- * Options for observation normalization.
12
- */
13
- export interface NormalizationOptions {
14
- /** Resolve pronouns to entity names */
15
- resolveCoreferences?: boolean;
16
- /** Convert relative dates to absolute dates */
17
- anchorTimestamps?: boolean;
18
- /** Extract and tag keywords */
19
- extractKeywords?: boolean;
20
- /** Reference date for relative date conversion (default: now) */
21
- referenceDate?: Date;
22
- }
23
- /**
24
- * Result of normalizing an observation.
25
- */
26
- export interface NormalizationResult {
27
- original: string;
28
- normalized: string;
29
- changes: string[];
30
- keywords?: string[];
31
- }
32
- /**
33
- * Observation Normalizer transforms observations to self-contained facts.
34
- *
35
- * Applies transformations:
36
- * 1. Coreference resolution: 'He works' -> 'Alice works'
37
- * 2. Temporal anchoring: 'yesterday' -> '2026-01-07'
38
- * 3. Keyword extraction: Identifies important terms
39
- *
40
- * @example
41
- * ```typescript
42
- * const normalizer = new ObservationNormalizer();
43
- * const result = normalizer.normalize(
44
- * 'He started the project yesterday',
45
- * { name: 'Bob', entityType: 'person', observations: [] }
46
- * );
47
- * // result.normalized = 'Bob started the project on 2026-01-07'
48
- * ```
49
- */
50
- export declare class ObservationNormalizer {
51
- private pronounPatterns;
52
- private relativeTimePatterns;
53
- /**
54
- * Normalize an observation for an entity.
55
- */
56
- normalize(observation: string, entity: Entity, options?: NormalizationOptions): NormalizationResult;
57
- /**
58
- * Resolve pronouns to entity name.
59
- */
60
- resolveCoreferences(text: string, entity: Entity): {
61
- text: string;
62
- changed: boolean;
63
- };
64
- private guessMasculine;
65
- private guessFeminine;
66
- /**
67
- * Convert relative timestamps to absolute dates.
68
- */
69
- anchorTimestamps(text: string, referenceDate: Date): {
70
- text: string;
71
- changed: boolean;
72
- replacements: string[];
73
- };
74
- private addDays;
75
- private addMonths;
76
- private formatDate;
77
- private formatMonth;
78
- /**
79
- * Extract important keywords from text.
80
- */
81
- extractKeywords(text: string): string[];
82
- /**
83
- * Normalize all observations for an entity.
84
- */
85
- normalizeEntity(entity: Entity, options?: NormalizationOptions): {
86
- entity: Entity;
87
- results: NormalizationResult[];
88
- };
89
- }
90
- //# sourceMappingURL=ObservationNormalizer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObservationNormalizer.d.ts","sourceRoot":"","sources":["../../src/features/ObservationNormalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uCAAuC;IACvC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iEAAiE;IACjE,aAAa,CAAC,EAAE,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,eAAe,CAIrB;IAEF,OAAO,CAAC,oBAAoB,CAU1B;IAEF;;OAEG;IACH,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,mBAAmB;IAuCtB;;OAEG;IACH,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE;IAsCrC,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAKrB;;OAEG;IACH,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,IAAI,GAClB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE;IAoB7D,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAwBvC;;OAEG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,EAAE,CAAA;KAAE;CAatD"}