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

Method memorize

methods/memrl_agent.py:587–723  ·  view source on GitHub ↗

Store text into MemRL memory using official build strategy. This method: 1. Splits input text into manageable chunks 2. Uses MemRL's build_memory for each chunk (following official implementation) 3. Tracks progress and provides detailed logging 4. Records al

(self, text: str, **kwargs)

Source from the content-addressed store, hash-verified

585 return chunks
586
587 def memorize(self, text: str, **kwargs) -> MemoryBuildResult:
588 """Store text into MemRL memory using official build strategy.
589
590 This method:
591 1. Splits input text into manageable chunks
592 2. Uses MemRL's build_memory for each chunk (following official implementation)
593 3. Tracks progress and provides detailed logging
594 4. Records all token usage through the tracked LLM provider
595 """
596 start_time = time.time()
597
598 # Split text into chunks for processing
599 chunks = self._split_text_into_chunks(
600 text,
601 max_tokens=self.memorize_chunk_tokens,
602 overlap_tokens=self.memorize_chunk_overlap_tokens,
603 )
604
605 if not chunks:
606 return MemoryBuildResult(
607 success=False,
608 method="memrl",
609 action="memorize",
610 input_content=text,
611 stored_content="",
612 memory_entries=[],
613 chunk_count=0,
614 extra={"error": "No chunks to process"},
615 )
616
617 # Start progress tracking
618 self._build_progress.start(len(chunks))
619 logger.info(f"[MemRL Memory Build] Starting memorization of {len(chunks)} chunks...")
620
621 memory_entries: List[Dict[str, Any]] = []
622 all_memory_ids: List[str] = []
623 build_details: List[Dict[str, Any]] = []
624
625 for i, chunk in enumerate(chunks):
626 chunk_start = time.time()
627
628 try:
629 # Use MemRL's official build_memory method
630 # Pass the full chunk as both task_description and trajectory
631 # (following official implementation without artificial truncation)
632 memory_id = self._memory_service.build_memory(
633 task_description=chunk, # Full chunk as task description
634 trajectory=chunk, # Full chunk as trajectory
635 metadata={
636 "source_benchmark": "medmemorybench",
637 "chunk_index": i,
638 "total_chunks": len(chunks),
639 # Don't assume success - let MemRL handle Q-value initialization
640 }
641 )
642
643 chunk_time = time.time() - chunk_start
644

Callers

nothing calls this directly

Calls 9

MemoryBuildResultClass · 0.85
build_memoryMethod · 0.80
record_chunkMethod · 0.80
infoMethod · 0.65
errorMethod · 0.65
startMethod · 0.45
get_summaryMethod · 0.45
get_statsMethod · 0.45

Tested by

no test coverage detected