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

Method __init__

methods/memrl_agent.py:259–377  ·  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,
        # MemRL specific parameters
        retrieve_num: int = 5,
        candidate_top_k: int = 12,
        similarity_threshold: float = 0.2,
        utility_mix_lambda: float = 0.6,
        learning_rate: float = 0.2,
        initial_q: float = 0.5,
        max_new_items_per_memorize: int = 8,
        max_experience_tokens: int = 700,
        memorize_chunk_tokens: int = 6000,
        memorize_chunk_overlap_tokens: int = 200,
        query_memory_item_tokens: int = 300,
        query_memory_context_tokens: int = 1800,
        max_concurrent_api_calls: int = 4,
        # Embedding configuration
        embedding_model: str = "all-MiniLM-L6-v2",
        embedding_provider: str = "local",
        embedding_model_path: Optional[str] = None,
        # Strategy configuration
        build_strategy: str = "proceduralization",
        retrieve_strategy: str = "query",
        update_strategy: str = "adjustment",
        # Q-learning configuration
        epsilon: float = 0.1,
        gamma: float = 0.0,
        q_init_pos: float = 0.5,
        q_init_neg: float = 0.0,
        success_reward: float = 1.0,
        failure_reward: float = -1.0,
        weight_sim: float = 0.5,
        weight_q: float = 0.5,
        **kwargs
    )

Source from the content-addressed store, hash-verified

257 user_id = (
258 f"memrl_{self._context_id}" if self._context_id is not None
259 else f"memrl_{os.getpid()}"
260 )
261
262 # Initialize MemoryService
263 init_kwargs = dict(
264 mos_config_path=mos_config_path,
265 llm_provider=self._tracked_llm,
266 embedding_provider=self._memrl_embedder,
267 strategy_config=strategy_config,
268 user_id=user_id,
269 num_workers=4,
270 enable_value_driven=True,
271 rl_config=rl_config,
272 add_similarity_threshold=0.92,
273 )
274 if self.embedding_dim:
275 init_kwargs["vector_dimension"] = self.embedding_dim
276 self._memory_service = MemoryService(**init_kwargs)
277
278 logger.info(
279 f"[MemRLAgent] Initialized: strategy={self.build_strategy}/{self.retrieve_strategy}, "
280 f"embedding={model_path}, user={user_id}"
281 )
282
283 def _create_mos_config(self) -> str:
284 """Create temporary MOS config JSON (following run_llb.py pattern)."""
285 embedder_config = {
286 "backend": "sentence_transformer",
287 "config": {
288 "model_name_or_path": self.embedding_model_path or self.embedding_model,
289 },
290 }
291
292 config = {
293 "user_manager": {
294 "backend": "sqlite",
295 "config": {"db_path": os.path.join(self._temp_dir, "users.db")},
296 },
297 "chat_model": {
298 "backend": "openai",
299 "config": {
300 "model_name_or_path": self.model,
301 "api_key": self._api_key,
302 "api_base": self._base_url or "https://api.openai.com/v1",
303 },
304 },
305 "mem_reader": {
306 "backend": "simple_struct",
307 "config": {
308 "llm": {
309 "backend": "openai",
310 "config": {
311 "model_name_or_path": self.model,
312 "api_key": self._api_key,
313 "api_base": self._base_url or "https://api.openai.com/v1",
314 },
315 },
316 "embedder": embedder_config,

Callers

nothing calls this directly

Calls 4

_init_memrlMethod · 0.95
create_llm_clientFunction · 0.90
MemoryBuildProgressClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected