MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / memorize

Method memorize

methods/amem_agent.py:249–300  ·  view source on GitHub ↗

Store text into A-Mem memory system. This method follows the official A-Mem implementation: 1. Split text into chunks if needed 2. Pass each chunk directly to add_note() for analysis and evolution 3. No additional preprocessing is applied

(self, text: str, **kwargs)

Source from the content-addressed store, hash-verified

247 return truncated + "\n... [truncated]"
248
249 def memorize(self, text: str, **kwargs) -> MemoryBuildResult:
250 """Store text into A-Mem memory system.
251
252 This method follows the official A-Mem implementation:
253 1. Split text into chunks if needed
254 2. Pass each chunk directly to add_note() for analysis and evolution
255 3. No additional preprocessing is applied
256 """
257 context_id = self._get_context_id()
258 memory_system = self._get_memory_system(context_id)
259
260 # Split text into chunks to avoid context length exceeded
261 chunks = self._split_text_into_chunks(text, self.amem_chunk_size_tokens)
262 logger.debug("Split input into %d chunks (chunk_size=%d tokens)", len(chunks), self.amem_chunk_size_tokens)
263
264 note_ids = []
265 memory_entries = []
266
267 for i, chunk in enumerate(chunks):
268 # Directly pass chunk to A-Mem add_note (following official implementation)
269 # A-Mem internally performs: content analysis, metadata extraction, evolution
270 note_id = memory_system.add_note(content=chunk)
271 note_ids.append(str(note_id))
272 self._memory_chunks.append(chunk)
273
274 memory_entries.append({
275 "event": "ADD",
276 "memory": chunk[:400],
277 "id": str(note_id),
278 "chunk_index": i,
279 })
280 logger.debug("Added chunk %d/%d to A-Mem, note_id=%s", i + 1, len(chunks), note_id)
281
282 self._is_initialized = True
283
284 return MemoryBuildResult(
285 success=True,
286 method="amem",
287 action="add_note",
288 input_content=text,
289 stored_content=text,
290 memory_entries=memory_entries,
291 all_passages=list(memory_entries),
292 chunk_count=len(self._memory_chunks),
293 extra={
294 "context_id": context_id,
295 "retrieve_num": self.retrieve_num,
296 "chunks_created": len(chunks),
297 "note_ids": note_ids,
298 "inserted_count": len(note_ids),
299 },
300 )
301
302 def query(
303 self,

Callers

nothing calls this directly

Calls 7

_get_context_idMethod · 0.95
_get_memory_systemMethod · 0.95
MemoryBuildResultClass · 0.85
debugMethod · 0.65
listFunction · 0.50
add_noteMethod · 0.45

Tested by

no test coverage detected