@hazeljs/rag 0.2.0-beta.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 (174) hide show
  1. package/README.md +379 -0
  2. package/dist/agentic/agentic-rag.service.d.ts +49 -0
  3. package/dist/agentic/agentic-rag.service.d.ts.map +1 -0
  4. package/dist/agentic/agentic-rag.service.js +149 -0
  5. package/dist/agentic/agentic-rag.service.js.map +1 -0
  6. package/dist/agentic/decorators/active-learning.decorator.d.ts +19 -0
  7. package/dist/agentic/decorators/active-learning.decorator.d.ts.map +1 -0
  8. package/dist/agentic/decorators/active-learning.decorator.js +98 -0
  9. package/dist/agentic/decorators/active-learning.decorator.js.map +1 -0
  10. package/dist/agentic/decorators/adaptive-retrieval.decorator.d.ts +16 -0
  11. package/dist/agentic/decorators/adaptive-retrieval.decorator.d.ts.map +1 -0
  12. package/dist/agentic/decorators/adaptive-retrieval.decorator.js +114 -0
  13. package/dist/agentic/decorators/adaptive-retrieval.decorator.js.map +1 -0
  14. package/dist/agentic/decorators/cached.decorator.d.ts +18 -0
  15. package/dist/agentic/decorators/cached.decorator.d.ts.map +1 -0
  16. package/dist/agentic/decorators/cached.decorator.js +93 -0
  17. package/dist/agentic/decorators/cached.decorator.js.map +1 -0
  18. package/dist/agentic/decorators/context-aware.decorator.d.ts +16 -0
  19. package/dist/agentic/decorators/context-aware.decorator.d.ts.map +1 -0
  20. package/dist/agentic/decorators/context-aware.decorator.js +169 -0
  21. package/dist/agentic/decorators/context-aware.decorator.js.map +1 -0
  22. package/dist/agentic/decorators/corrective-rag.decorator.d.ts +15 -0
  23. package/dist/agentic/decorators/corrective-rag.decorator.d.ts.map +1 -0
  24. package/dist/agentic/decorators/corrective-rag.decorator.js +146 -0
  25. package/dist/agentic/decorators/corrective-rag.decorator.js.map +1 -0
  26. package/dist/agentic/decorators/hyde.decorator.d.ts +14 -0
  27. package/dist/agentic/decorators/hyde.decorator.d.ts.map +1 -0
  28. package/dist/agentic/decorators/hyde.decorator.js +90 -0
  29. package/dist/agentic/decorators/hyde.decorator.js.map +1 -0
  30. package/dist/agentic/decorators/index.d.ts +16 -0
  31. package/dist/agentic/decorators/index.d.ts.map +1 -0
  32. package/dist/agentic/decorators/index.js +32 -0
  33. package/dist/agentic/decorators/index.js.map +1 -0
  34. package/dist/agentic/decorators/multi-hop.decorator.d.ts +14 -0
  35. package/dist/agentic/decorators/multi-hop.decorator.d.ts.map +1 -0
  36. package/dist/agentic/decorators/multi-hop.decorator.js +120 -0
  37. package/dist/agentic/decorators/multi-hop.decorator.js.map +1 -0
  38. package/dist/agentic/decorators/query-planner.decorator.d.ts +19 -0
  39. package/dist/agentic/decorators/query-planner.decorator.d.ts.map +1 -0
  40. package/dist/agentic/decorators/query-planner.decorator.js +227 -0
  41. package/dist/agentic/decorators/query-planner.decorator.js.map +1 -0
  42. package/dist/agentic/decorators/query-rewriter.decorator.d.ts +15 -0
  43. package/dist/agentic/decorators/query-rewriter.decorator.d.ts.map +1 -0
  44. package/dist/agentic/decorators/query-rewriter.decorator.js +140 -0
  45. package/dist/agentic/decorators/query-rewriter.decorator.js.map +1 -0
  46. package/dist/agentic/decorators/self-reflective.decorator.d.ts +18 -0
  47. package/dist/agentic/decorators/self-reflective.decorator.d.ts.map +1 -0
  48. package/dist/agentic/decorators/self-reflective.decorator.js +210 -0
  49. package/dist/agentic/decorators/self-reflective.decorator.js.map +1 -0
  50. package/dist/agentic/decorators/source-verification.decorator.d.ts +15 -0
  51. package/dist/agentic/decorators/source-verification.decorator.d.ts.map +1 -0
  52. package/dist/agentic/decorators/source-verification.decorator.js +121 -0
  53. package/dist/agentic/decorators/source-verification.decorator.js.map +1 -0
  54. package/dist/agentic/index.d.ts +9 -0
  55. package/dist/agentic/index.d.ts.map +1 -0
  56. package/dist/agentic/index.js +25 -0
  57. package/dist/agentic/index.js.map +1 -0
  58. package/dist/agentic/types.d.ts +209 -0
  59. package/dist/agentic/types.d.ts.map +1 -0
  60. package/dist/agentic/types.js +7 -0
  61. package/dist/agentic/types.js.map +1 -0
  62. package/dist/decorators/embeddable.decorator.d.ts +31 -0
  63. package/dist/decorators/embeddable.decorator.d.ts.map +1 -0
  64. package/dist/decorators/embeddable.decorator.js +44 -0
  65. package/dist/decorators/embeddable.decorator.js.map +1 -0
  66. package/dist/decorators/rag.decorator.d.ts +58 -0
  67. package/dist/decorators/rag.decorator.d.ts.map +1 -0
  68. package/dist/decorators/rag.decorator.js +78 -0
  69. package/dist/decorators/rag.decorator.js.map +1 -0
  70. package/dist/decorators/semantic-search.decorator.d.ts +69 -0
  71. package/dist/decorators/semantic-search.decorator.d.ts.map +1 -0
  72. package/dist/decorators/semantic-search.decorator.js +116 -0
  73. package/dist/decorators/semantic-search.decorator.js.map +1 -0
  74. package/dist/embeddings/cohere-embeddings.d.ts +33 -0
  75. package/dist/embeddings/cohere-embeddings.d.ts.map +1 -0
  76. package/dist/embeddings/cohere-embeddings.js +91 -0
  77. package/dist/embeddings/cohere-embeddings.js.map +1 -0
  78. package/dist/embeddings/openai-embeddings.d.ts +21 -0
  79. package/dist/embeddings/openai-embeddings.d.ts.map +1 -0
  80. package/dist/embeddings/openai-embeddings.js +53 -0
  81. package/dist/embeddings/openai-embeddings.js.map +1 -0
  82. package/dist/index.d.ts +27 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +54 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/memory/index.d.ts +11 -0
  87. package/dist/memory/index.d.ts.map +1 -0
  88. package/dist/memory/index.js +31 -0
  89. package/dist/memory/index.js.map +1 -0
  90. package/dist/memory/memory-manager.d.ts +96 -0
  91. package/dist/memory/memory-manager.d.ts.map +1 -0
  92. package/dist/memory/memory-manager.js +369 -0
  93. package/dist/memory/memory-manager.js.map +1 -0
  94. package/dist/memory/memory-store.interface.d.ts +73 -0
  95. package/dist/memory/memory-store.interface.d.ts.map +1 -0
  96. package/dist/memory/memory-store.interface.js +6 -0
  97. package/dist/memory/memory-store.interface.js.map +1 -0
  98. package/dist/memory/stores/buffer-memory.d.ts +47 -0
  99. package/dist/memory/stores/buffer-memory.d.ts.map +1 -0
  100. package/dist/memory/stores/buffer-memory.js +280 -0
  101. package/dist/memory/stores/buffer-memory.js.map +1 -0
  102. package/dist/memory/stores/hybrid-memory.d.ts +49 -0
  103. package/dist/memory/stores/hybrid-memory.d.ts.map +1 -0
  104. package/dist/memory/stores/hybrid-memory.js +194 -0
  105. package/dist/memory/stores/hybrid-memory.js.map +1 -0
  106. package/dist/memory/stores/vector-memory.d.ts +48 -0
  107. package/dist/memory/stores/vector-memory.d.ts.map +1 -0
  108. package/dist/memory/stores/vector-memory.js +312 -0
  109. package/dist/memory/stores/vector-memory.js.map +1 -0
  110. package/dist/memory/types.d.ts +119 -0
  111. package/dist/memory/types.d.ts.map +1 -0
  112. package/dist/memory/types.js +18 -0
  113. package/dist/memory/types.js.map +1 -0
  114. package/dist/rag-pipeline-with-memory.d.ts +68 -0
  115. package/dist/rag-pipeline-with-memory.d.ts.map +1 -0
  116. package/dist/rag-pipeline-with-memory.js +186 -0
  117. package/dist/rag-pipeline-with-memory.js.map +1 -0
  118. package/dist/rag-pipeline.d.ts +59 -0
  119. package/dist/rag-pipeline.d.ts.map +1 -0
  120. package/dist/rag-pipeline.js +181 -0
  121. package/dist/rag-pipeline.js.map +1 -0
  122. package/dist/rag.module.d.ts +26 -0
  123. package/dist/rag.module.d.ts.map +1 -0
  124. package/dist/rag.module.js +40 -0
  125. package/dist/rag.module.js.map +1 -0
  126. package/dist/rag.service.d.ts +95 -0
  127. package/dist/rag.service.d.ts.map +1 -0
  128. package/dist/rag.service.js +174 -0
  129. package/dist/rag.service.js.map +1 -0
  130. package/dist/retrieval/bm25.d.ts +57 -0
  131. package/dist/retrieval/bm25.d.ts.map +1 -0
  132. package/dist/retrieval/bm25.js +106 -0
  133. package/dist/retrieval/bm25.js.map +1 -0
  134. package/dist/retrieval/hybrid-search.d.ts +48 -0
  135. package/dist/retrieval/hybrid-search.d.ts.map +1 -0
  136. package/dist/retrieval/hybrid-search.js +123 -0
  137. package/dist/retrieval/hybrid-search.js.map +1 -0
  138. package/dist/retrieval/multi-query.d.ts +38 -0
  139. package/dist/retrieval/multi-query.d.ts.map +1 -0
  140. package/dist/retrieval/multi-query.js +135 -0
  141. package/dist/retrieval/multi-query.js.map +1 -0
  142. package/dist/text-splitters/recursive-text-splitter.d.ts +21 -0
  143. package/dist/text-splitters/recursive-text-splitter.d.ts.map +1 -0
  144. package/dist/text-splitters/recursive-text-splitter.js +95 -0
  145. package/dist/text-splitters/recursive-text-splitter.js.map +1 -0
  146. package/dist/types/index.d.ts +144 -0
  147. package/dist/types/index.d.ts.map +1 -0
  148. package/dist/types/index.js +16 -0
  149. package/dist/types/index.js.map +1 -0
  150. package/dist/utils/similarity.d.ts +16 -0
  151. package/dist/utils/similarity.d.ts.map +1 -0
  152. package/dist/utils/similarity.js +58 -0
  153. package/dist/utils/similarity.js.map +1 -0
  154. package/dist/vector-stores/chroma.store.d.ts +42 -0
  155. package/dist/vector-stores/chroma.store.d.ts.map +1 -0
  156. package/dist/vector-stores/chroma.store.js +242 -0
  157. package/dist/vector-stores/chroma.store.js.map +1 -0
  158. package/dist/vector-stores/memory-vector-store.d.ts +20 -0
  159. package/dist/vector-stores/memory-vector-store.d.ts.map +1 -0
  160. package/dist/vector-stores/memory-vector-store.js +94 -0
  161. package/dist/vector-stores/memory-vector-store.js.map +1 -0
  162. package/dist/vector-stores/pinecone.store.d.ts +34 -0
  163. package/dist/vector-stores/pinecone.store.d.ts.map +1 -0
  164. package/dist/vector-stores/pinecone.store.js +146 -0
  165. package/dist/vector-stores/pinecone.store.js.map +1 -0
  166. package/dist/vector-stores/qdrant.store.d.ts +31 -0
  167. package/dist/vector-stores/qdrant.store.d.ts.map +1 -0
  168. package/dist/vector-stores/qdrant.store.js +173 -0
  169. package/dist/vector-stores/qdrant.store.js.map +1 -0
  170. package/dist/vector-stores/weaviate.store.d.ts +37 -0
  171. package/dist/vector-stores/weaviate.store.d.ts.map +1 -0
  172. package/dist/vector-stores/weaviate.store.js +226 -0
  173. package/dist/vector-stores/weaviate.store.js.map +1 -0
  174. package/package.json +87 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-manager.d.ts","sourceRoot":"","sources":["../../src/memory/memory-manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EACL,MAAM,EAEN,YAAY,EACZ,OAAO,EACP,MAAM,EACN,WAAW,EACX,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAe;gBAEjB,KAAK,EAAE,WAAW,EAAE,MAAM,GAAE,YAAiB;IAcnD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBvF;;OAEG;IACG,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAenF;;OAEG;IACG,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ/D;;OAEG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAczD;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBpE;;OAEG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBrD;;OAEG;IACG,YAAY,CAAC,IAAI,E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AEG;YACW,kBAAkB;CAiBjC"}
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ /**
3
+ * Memory Manager - High-level interface for managing different types of memory
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MemoryManager = void 0;
7
+ const types_1 = require("./types");
8
+ const crypto_1 = require("crypto");
9
+ /**
10
+ * Central manager for all memory operations
11
+ * Provides high-level APIs for conversation, entity, fact, and working memory
12
+ */
13
+ class MemoryManager {
14
+ constructor(store, config = {}) {
15
+ this.store = store;
16
+ this.config = {
17
+ maxConversationLength: config.maxConversationLength || 20,
18
+ summarizeAfter: config.summarizeAfter || 50,
19
+ entityExtraction: config.entityExtraction ?? true,
20
+ importanceScoring: config.importanceScoring ?? true,
21
+ memoryDecay: config.memoryDecay ?? false,
22
+ decayRate: config.decayRate || 0.1,
23
+ maxWorkingMemorySize: config.maxWorkingMemorySize || 10,
24
+ ...config,
25
+ };
26
+ }
27
+ async initialize() {
28
+ await this.store.initialize();
29
+ }
30
+ // ==================== Conversation Memory ====================
31
+ /**
32
+ * Add a message to conversation history
33
+ */
34
+ async addMessage(message, sessionId, userId) {
35
+ const memory = {
36
+ id: (0, crypto_1.randomUUID)(),
37
+ type: types_1.MemoryType.CONVERSATION,
38
+ content: `${message.role}: ${message.content}`,
39
+ metadata: {
40
+ timestamp: message.timestamp || new Date(),
41
+ sessionId,
42
+ userId,
43
+ role: message.role,
44
+ importance: this.calculateImportance(message.content),
45
+ ...message.metadata,
46
+ },
47
+ };
48
+ const id = await this.store.save(memory);
49
+ // Check if we need to summarize
50
+ await this.checkAndSummarize(sessionId);
51
+ return id;
52
+ }
53
+ /**
54
+ * Get conversation history for a session
55
+ */
56
+ async getConversationHistory(sessionId, limit) {
57
+ const memories = await this.store.retrieve({
58
+ sessionId,
59
+ types: [types_1.MemoryType.CONVERSATION],
60
+ limit: limit || this.config.maxConversationLength,
61
+ });
62
+ return memories.map((m) => ({
63
+ role: m.metadata.role,
64
+ content: m.content.replace(/^(user|assistant|system): /, ''),
65
+ timestamp: m.metadata.timestamp,
66
+ metadata: m.metadata,
67
+ }));
68
+ }
69
+ /**
70
+ * Summarize conversation history
71
+ */
72
+ async summarizeConversation(sessionId) {
73
+ return this.store.summarize({
74
+ sessionId,
75
+ maxLength: 1000,
76
+ strategy: 'extractive',
77
+ });
78
+ }
79
+ /**
80
+ * Clear conversation history for a session
81
+ */
82
+ async clearConversation(sessionId) {
83
+ const memories = await this.store.retrieve({
84
+ sessionId,
85
+ types: [types_1.MemoryType.CONVERSATION],
86
+ });
87
+ const ids = memories.map((m) => m.id);
88
+ if (ids.length > 0) {
89
+ await this.store.deleteBatch(ids);
90
+ }
91
+ }
92
+ // ==================== Entity Memory ====================
93
+ /**
94
+ * Track an entity mentioned in conversation
95
+ */
96
+ async trackEntity(entity, sessionId) {
97
+ const memory = {
98
+ id: (0, crypto_1.randomUUID)(),
99
+ type: types_1.MemoryType.ENTITY,
100
+ content: JSON.stringify(entity),
101
+ metadata: {
102
+ timestamp: new Date(),
103
+ sessionId,
104
+ entityName: entity.name,
105
+ entityType: entity.type,
106
+ entities: [entity.name],
107
+ importance: 0.8,
108
+ },
109
+ };
110
+ await this.store.save(memory);
111
+ }
112
+ /**
113
+ * Get entity by name
114
+ */
115
+ async getEntity(name) {
116
+ const memories = await this.store.retrieve({
117
+ entities: [name],
118
+ types: [types_1.MemoryType.ENTITY],
119
+ limit: 1,
120
+ });
121
+ if (memories.length === 0)
122
+ return null;
123
+ try {
124
+ return JSON.parse(memories[0].content);
125
+ }
126
+ catch {
127
+ return null;
128
+ }
129
+ }
130
+ /**
131
+ * Update entity information
132
+ */
133
+ async updateEntity(name, updates) {
134
+ const existing = await this.getEntity(name);
135
+ if (!existing) {
136
+ throw new Error(`Entity ${name} not found`);
137
+ }
138
+ const updated = {
139
+ ...existing,
140
+ ...updates,
141
+ lastSeen: new Date(),
142
+ mentions: existing.mentions + 1,
143
+ };
144
+ const memories = await this.store.retrieve({
145
+ entities: [name],
146
+ types: [types_1.MemoryType.ENTITY],
147
+ limit: 1,
148
+ });
149
+ if (memories.length > 0) {
150
+ await this.store.update(memories[0].id, {
151
+ content: JSON.stringify(updated),
152
+ metadata: {
153
+ ...memories[0].metadata,
154
+ timestamp: new Date(),
155
+ },
156
+ });
157
+ }
158
+ }
159
+ /**
160
+ * Get all tracked entities
161
+ */
162
+ async getAllEntities(sessionId) {
163
+ const memories = await this.store.retrieve({
164
+ sessionId,
165
+ types: [types_1.MemoryType.ENTITY],
166
+ limit: 1000,
167
+ });
168
+ return memories
169
+ .map((m) => {
170
+ try {
171
+ return JSON.parse(m.content);
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ })
177
+ .filter((e) => e !== null);
178
+ }
179
+ // ==================== Semantic Memory (Facts) ====================
180
+ /**
181
+ * Store a fact or piece of knowledge
182
+ */
183
+ async storeFact(fact, metadata) {
184
+ const memory = {
185
+ id: (0, crypto_1.randomUUID)(),
186
+ type: types_1.MemoryType.FACT,
187
+ content: fact,
188
+ metadata: {
189
+ timestamp: new Date(),
190
+ importance: this.calculateImportance(fact),
191
+ ...metadata,
192
+ },
193
+ };
194
+ return this.store.save(memory);
195
+ }
196
+ /**
197
+ * Recall facts related to a query
198
+ */
199
+ async recallFacts(query, options) {
200
+ const memories = await this.store.search(query, {
201
+ types: [types_1.MemoryType.FACT],
202
+ topK: options?.topK || 5,
203
+ ...options,
204
+ });
205
+ return memories.map((m) => m.content);
206
+ }
207
+ /**
208
+ * Update a fact
209
+ */
210
+ async updateFact(id, newContent) {
211
+ await this.store.update(id, {
212
+ content: newContent,
213
+ metadata: {
214
+ timestamp: new Date(),
215
+ updated: true,
216
+ },
217
+ });
218
+ }
219
+ // ==================== Working Memory ====================
220
+ /**
221
+ * Set a value in working memory (temporary context)
222
+ */
223
+ async setContext(key, value, sessionId) {
224
+ // Check if context already exists
225
+ const existing = await this.store.retrieve({
226
+ sessionId,
227
+ types: [types_1.MemoryType.WORKING],
228
+ limit: 1000,
229
+ });
230
+ const existingContext = existing.find((m) => m.metadata.contextKey === key);
231
+ if (existingContext) {
232
+ // Update existing
233
+ await this.store.update(existingContext.id, {
234
+ content: JSON.stringify(value),
235
+ metadata: {
236
+ ...existingContext.metadata,
237
+ timestamp: new Date(),
238
+ },
239
+ });
240
+ }
241
+ else {
242
+ // Create new
243
+ const memory = {
244
+ id: (0, crypto_1.randomUUID)(),
245
+ type: types_1.MemoryType.WORKING,
246
+ content: JSON.stringify(value),
247
+ metadata: {
248
+ timestamp: new Date(),
249
+ sessionId,
250
+ contextKey: key,
251
+ importance: 0.5,
252
+ },
253
+ };
254
+ await this.store.save(memory);
255
+ }
256
+ // Enforce max working memory size
257
+ await this.pruneWorkingMemory(sessionId);
258
+ }
259
+ /**
260
+ * Get a value from working memory
261
+ */
262
+ async getContext(key, sessionId) {
263
+ const memories = await this.store.retrieve({
264
+ sessionId,
265
+ types: [types_1.MemoryType.WORKING],
266
+ limit: 1000,
267
+ });
268
+ const memory = memories.find((m) => m.metadata.contextKey === key);
269
+ if (!memory)
270
+ return null;
271
+ try {
272
+ return JSON.parse(memory.content);
273
+ }
274
+ catch {
275
+ return memory.content;
276
+ }
277
+ }
278
+ /**
279
+ * Clear working memory for a session
280
+ */
281
+ async clearContext(sessionId) {
282
+ const memories = await this.store.retrieve({
283
+ sessionId,
284
+ types: [types_1.MemoryType.WORKING],
285
+ });
286
+ const ids = memories.map((m) => m.id);
287
+ if (ids.length > 0) {
288
+ await this.store.deleteBatch(ids);
289
+ }
290
+ }
291
+ // ==================== Memory Retrieval ====================
292
+ /**
293
+ * Get relevant memories for a query
294
+ */
295
+ async relevantMemories(query, options) {
296
+ return this.store.search(query, options);
297
+ }
298
+ /**
299
+ * Get memories by query parameters
300
+ */
301
+ async getMemories(query) {
302
+ return this.store.retrieve(query);
303
+ }
304
+ /**
305
+ * Get memory statistics
306
+ */
307
+ async getStats(sessionId) {
308
+ return this.store.getStats(sessionId);
309
+ }
310
+ // ==================== Private Helper Methods ====================
311
+ /**
312
+ * Calculate importance score for content
313
+ */
314
+ calculateImportance(content) {
315
+ if (!this.config.importanceScoring)
316
+ return 0.5;
317
+ // Simple heuristic: longer content and questions are more important
318
+ let score = 0.5;
319
+ if (content.length > 100)
320
+ score += 0.2;
321
+ if (content.includes('?'))
322
+ score += 0.1;
323
+ if (content.includes('important') || content.includes('remember'))
324
+ score += 0.2;
325
+ return Math.min(score, 1.0);
326
+ }
327
+ /**
328
+ * Check if conversation needs summarization
329
+ */
330
+ async checkAndSummarize(sessionId) {
331
+ if (!this.config.summarizeAfter)
332
+ return;
333
+ const memories = await this.store.retrieve({
334
+ sessionId,
335
+ types: [types_1.MemoryType.CONVERSATION],
336
+ limit: 1000,
337
+ });
338
+ if (memories.length >= this.config.summarizeAfter) {
339
+ // Summarize oldest messages
340
+ const toSummarize = memories.slice(this.config.maxConversationLength);
341
+ if (toSummarize.length > 0) {
342
+ await this.store.consolidate(toSummarize);
343
+ // Delete original messages
344
+ const ids = toSummarize.map((m) => m.id);
345
+ await this.store.deleteBatch(ids);
346
+ }
347
+ }
348
+ }
349
+ /**
350
+ * Prune working memory to max size
351
+ */
352
+ async pruneWorkingMemory(sessionId) {
353
+ const memories = await this.store.retrieve({
354
+ sessionId,
355
+ types: [types_1.MemoryType.WORKING],
356
+ limit: 1000,
357
+ });
358
+ if (memories.length > this.config.maxWorkingMemorySize) {
359
+ // Remove oldest
360
+ const toRemove = memories
361
+ .sort((a, b) => a.metadata.timestamp.getTime() - b.metadata.timestamp.getTime())
362
+ .slice(0, memories.length - this.config.maxWorkingMemorySize);
363
+ const ids = toRemove.map((m) => m.id);
364
+ await this.store.deleteBatch(ids);
365
+ }
366
+ }
367
+ }
368
+ exports.MemoryManager = MemoryManager;
369
+ //# sourceMappingURL=memory-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-manager.js","sourceRoot":"","sources":["../../src/memory/memory-manager.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,mCAQiB;AACjB,mCAAoC;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
3
+ */
4
+ import { Memory, MemoryQuery, MemorySearchOptions, SummarizeOptions, MemoryStats } from './types';
5
+ /**
6
+ * Interface for memory storage backends
7
+ */
8
+ export interface MemoryStore {
9
+ /**
10
+ * Initialize the memory store
11
+ */
12
+ initialize(): Promise<void>;
13
+ /**
14
+ * Save a memory
15
+ */
16
+ save(memory: Memory): Promise<string>;
17
+ /**
18
+ * Save multiple memories
19
+ */
20
+ saveBatch(memories: Memory[]): Promise<string[]>;
21
+ /**
22
+ * Retrieve memories by query
23
+ */
24
+ retrieve(query: MemoryQuery): Promise<Memory[]>;
25
+ /**
26
+ * Search memories semantically
27
+ */
28
+ search(query: string, options: MemorySearchOptions): Promise<Memory[]>;
29
+ /**
30
+ * Get a specific memory by ID
31
+ */
32
+ get(id: string): Promise<Memory | null>;
33
+ /**
34
+ * Update a memory
35
+ */
36
+ update(id: string, updates: Partial<Memory>): Promise<void>;
37
+ /**
38
+ * Delete a memory
39
+ */
40
+ delete(id: string): Promise<void>;
41
+ /**
42
+ * Delete multiple memories
43
+ */
44
+ deleteBatch(ids: string[]): Promise<void>;
45
+ /**
46
+ * Clear all memories for a session
47
+ */
48
+ clearSession(sessionId: string): Promise<void>;
49
+ /**
50
+ * Clear all memories
51
+ */
52
+ clear(): Promise<void>;
53
+ /**
54
+ * Summarize memories
55
+ */
56
+ summarize(options: SummarizeOptions): Promise<string>;
57
+ /**
58
+ * Consolidate similar memories
59
+ */
60
+ consolidate(memories: Memory[]): Promise<Memory>;
61
+ /**
62
+ * Get memory statistics
63
+ */
64
+ getStats(sessionId?: string): Promise<MemoryStats>;
65
+ /**
66
+ * Prune old or low-importance memories
67
+ */
68
+ prune(options?: {
69
+ olderThan?: Date;
70
+ minImportance?: number;
71
+ }): Promise<number>;
72
+ }
73
+ //# sourceMappingURL=memory-store.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-store.interface.d.ts","sourceRoot":"","sources":["../../src/memory/memory-store.interface.ts"],"names":[],"mappings":"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C,CAAC;IAEtD;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEnD;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,IAAI,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChF"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Memory store interface
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=memory-store.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-store.interface.js","sourceRoot":"","sources":["../../src/memory/memory-store.interface.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Buffer Memory Store - Simple FIFO buffer for recent memories
3
+ */
4
+ import { MemoryStore } from '../memory-store.interface';
5
+ import { Memory, MemoryQuery, MemorySearchOptions, SummarizeOptions, MemoryStats } from '../types';
6
+ export interface BufferMemoryConfig {
7
+ maxSize?: number;
8
+ ttl?: number;
9
+ }
10
+ /**
11
+ * In-memory buffer that keeps the most recent memories
12
+ * Uses FIFO (First In, First Out) strategy
13
+ */
14
+ export declare class BufferMemory implements MemoryStore {
15
+ private memories;
16
+ private sessionBuffers;
17
+ private maxSize;
18
+ private ttl?;
19
+ constructor(config?: BufferMemoryConfig);
20
+ initialize(): Promise<void>;
21
+ save(memory: Memory): Promise<string>;
22
+ saveBatch(memories: Memory[]): Promise<string[]>;
23
+ retrieve(query: MemoryQuery): Promise<Memory[]>;
24
+ search(query: string, options: MemorySearchOptions): Promise<Memory[]>;
25
+ get(id: string): Promise<Memory | null>;
26
+ update(id: string, updates: Partial<Memory>): Promise<void>;
27
+ delete(id: string): Promise<void>;
28
+ deleteBatch(ids: string[]): Promise<void>;
29
+ clearSession(sessionId: string): Promise<void>;
30
+ clear(): Promise<void>;
31
+ summarize(options: SummarizeOptions): Promise<string>;
32
+ consolidate(memories: Memory[]): Promise<Memory>;
33
+ getStats(sessionId?: string): Promise<MemoryStats>;
34
+ prune(options?: {
35
+ olderThan?: Date;
36
+ minImportance?: number;
37
+ }): Promise<number>;
38
+ /**
39
+ * Clean expired memories
40
+ */
41
+ private cleanExpired;
42
+ /**
43
+ * Calculate simple text similarity score
44
+ */
45
+ private calculateTextScore;
46
+ }
47
+ //# sourceMappingURL=buffer-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-memory.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/buffer-memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,MAAM,EACN,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,qBAAa,YAAa,YAAW,WAAW;IAC9C,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,GAAG,CAAC,CAAS;gBAET,MAAM,GAAE,kBAAuB;IAKrC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkCrC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAShD,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,M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