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

Method __init__

methods/lightmem_agent.py:339–422  ·  view source on GitHub ↗
(
        self,
        model: str = "gpt-4o-mini",
        temperature: float = 1.0,
        max_tokens: int = 2000,
        provider: str = "openai",
        api_key: Optional[str] = None,
        base_url: Optional[str] = None,
        # LightMem specific parameters
        retrieve_num: int = 5,
        pre_compress: bool = False,
        topic_segment: bool = True,
        index_strategy: str = "embedding",
        retrieve_strategy: str = "embedding",
        update_mode: str = "offline",
        extraction_mode: str = "flat",
        messages_use: str = "user_only",
        # Embedding configuration
        embedding_provider: str = "local",
        embedding_model: str = "BAAI/bge-small-zh-v1.5",
        embedding_model_path: Optional[str] = None,
        embedding_dim: Optional[int] = None,
        embedding_api_key: Optional[str] = None,
        embedding_base_url: Optional[str] = None,
        # Memory manager LLM settings
        lightmem_temperature: float = 0.1,
        lightmem_max_tokens: int = 2000,
        lightmem_top_p: float = 0.1,
        # Token limits
        max_context_tokens: int = 120000,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

337
338 def concatenate_messages(segment: List[Dict], messages_use: str) -> str:
339 """Concatenate messages based on usage strategy."""
340 role_filter = {
341 "user_only": {"user"},
342 "assistant_only": {"assistant"},
343 "hybrid": {"user", "assistant"}
344 }
345
346 if messages_use not in role_filter:
347 raise ValueError(f"Invalid messages_use value: {messages_use}")
348
349 allowed_roles = role_filter[messages_use]
350 message_lines = []
351
352 for mes in segment:
353 if mes.get("role") in allowed_roles:
354 sequence_id = mes.get("sequence_number", 0)
355 role = mes["role"]
356 content = mes.get("content", "")
357 speaker_name = mes.get("speaker_name", "")
358 time_stamp = mes.get("time_stamp", "")
359 weekday = mes.get("weekday", "")
360
361 time_prefix = ""
362 if time_stamp and weekday:
363 time_prefix = f"[{time_stamp}, {weekday}] "
364
365 if speaker_name:
366 message_lines.append(f"{time_prefix}{sequence_id // 2}.{speaker_name}: {content}")
367 else:
368 message_lines.append(f"{time_prefix}{sequence_id // 2}.{role}: {content}")
369
370 return "\n".join(message_lines)
371
372 max_workers = min(len(extract_list), 5)
373
374 def process_segment_wrapper(args):
375 api_call_idx, api_call_segments = args
376 try:
377 user_prompt_parts: List[str] = []
378
379 global_topic_ids: List[int] = []
380 if topic_id_mapping and api_call_idx < len(topic_id_mapping):
381 global_topic_ids = topic_id_mapping[api_call_idx]
382
383 for topic_idx, topic_segment in enumerate(api_call_segments):
384 if topic_idx < len(global_topic_ids):
385 global_topic_id = global_topic_ids[topic_idx]
386 else:
387 global_topic_id = topic_idx + 1
388
389 topic_text = concatenate_messages(topic_segment, messages_use)
390 user_prompt_parts.append(f"--- Topic {global_topic_id} ---\n{topic_text}")
391
392 user_prompt = "\n".join(user_prompt_parts)
393
394 metadata_messages = [
395 {"role": "system", "content": system_prompt},
396 {"role": "user", "content": user_prompt},

Callers

nothing calls this directly

Calls 3

_setup_lightmem_pathMethod · 0.95
create_llm_clientFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected