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

Method _split_long_message

methods/lightmem_agent.py:600–677  ·  view source on GitHub ↗

Split a long message into smaller chunks that fit within BERT token limits. LightMem uses BERT with max_position_embeddings=512, so we need to ensure individual user messages don't exceed this limit. BERT tokenizer (multilingual) produces ~1.5-2x more tokens for Ch

(self, content: str, max_tokens: int = 250)

Source from the content-addressed store, hash-verified

598 return "user_only"
599 elif dataset in ("medmemorybench", "longmemeval"):
600 return "hybrid"
601 return config_value
602
603 def _build_lightmem_config(self) -> Dict[str, Any]:
604 """Build LightMem configuration dictionary matching official add_locomo.py."""
605 config = {
606 # Pre-processing
607 "pre_compress": self.pre_compress,
608 "topic_segment": self.topic_segment,
609 "precomp_topic_shared": self.precomp_topic_shared,
610 "messages_use": self._effective_messages_use,
611
612 # Index and retrieval strategy
613 "index_strategy": self.index_strategy,
614 "retrieve_strategy": self.retrieve_strategy,
615 "update": self.update_mode,
616 "extraction_mode": self.extraction_mode,
617
618 # Metadata and summary
619 "metadata_generate": True,
620 "text_summary": True,
621
622 # Memory Manager (LLM) - will be replaced with our tracked manager
623 "memory_manager": {
624 "model_name": "openai",
625 "configs": {
626 "model": self.model,
627 "api_key": self._api_key,
628 "openai_base_url": self._base_url,
629 "temperature": self.lightmem_temperature,
630 "max_tokens": self.lightmem_max_tokens,
631 "top_p": self.lightmem_top_p,
632 }
633 },
634 }
635
636 # Pre-compressor configuration (matching official add_locomo.py)
637 if self.pre_compress and self.pre_compressor_model_path:
638 config["pre_compressor"] = {
639 "model_name": "llmlingua-2",
640 "configs": {
641 "llmlingua_config": {
642 "model_name": self.pre_compressor_model_path,
643 "use_llmlingua2": True,
644 },
645 "compress_config": {
646 "instruction": "",
647 "rate": self.compress_rate,
648 "target_token": -1,
649 },
650 }
651 }
652
653 # Topic segmenter configuration
654 if self.topic_segment:
655 if self.pre_compress and self.precomp_topic_shared:
656 # When precomp_topic_shared=True, segmenter reuses the compressor's model
657 config["topic_segmenter"] = {

Callers 1

Calls 2

count_tokensMethod · 0.45

Tested by

no test coverage detected