misc / SimpleMem /config.py
NingsenWang's picture
Upload SimpleMem project snapshot
a54fd97 verified
"""
Runtime configuration for the classic text-only SimpleMem pipeline.
This file is intentionally environment-driven so benchmark runs can inject
credentials without storing secrets in the repository.
"""
from __future__ import annotations
import os
def _get_bool(name: str, default: bool) -> bool:
value = os.getenv(name)
if value is None:
return default
return value.strip().lower() in {"1", "true", "yes", "on"}
def _get_int(name: str, default: int | None) -> int | None:
value = os.getenv(name)
if value is None or value == "":
return default
return int(value)
def _get_optional_str(name: str, default: str | None) -> str | None:
value = os.getenv(name)
if value is None or value == "":
return default
return value
# ============================================================================
# LLM Configuration
# ============================================================================
DASHSCOPE_API_KEY = _get_optional_str("DASHSCOPE_API_KEY", None)
OPENAI_API_KEY = _get_optional_str("OPENAI_API_KEY", DASHSCOPE_API_KEY)
OPENAI_BASE_URL = _get_optional_str(
"OPENAI_BASE_URL",
"https://dashscope.aliyuncs.com/compatible-mode/v1",
)
LLM_MODEL = _get_optional_str("LLM_MODEL", "qwen3-max-2026-01-23")
# ============================================================================
# Embedding Configuration
# ============================================================================
EMBEDDING_MODEL = _get_optional_str("EMBEDDING_MODEL", "text-embedding-v4")
EMBEDDING_DIMENSION = _get_int("EMBEDDING_DIMENSION", None)
EMBEDDING_BATCH_SIZE = _get_int("EMBEDDING_BATCH_SIZE", 8)
# ============================================================================
# Advanced LLM Features
# ============================================================================
ENABLE_THINKING = _get_bool("ENABLE_THINKING", False)
USE_STREAMING = _get_bool("USE_STREAMING", False)
USE_JSON_FORMAT = _get_bool("USE_JSON_FORMAT", True)
LLM_MAX_RETRIES = _get_int("LLM_MAX_RETRIES", 5) or 5
EMBEDDING_MAX_RETRIES = _get_int("EMBEDDING_MAX_RETRIES", 5) or 5
# ============================================================================
# Memory Building Parameters
# ============================================================================
WINDOW_SIZE = _get_int("WINDOW_SIZE", 40) or 40
OVERLAP_SIZE = _get_int("OVERLAP_SIZE", 2) or 0
FAIL_ON_EXTRACTION_ERROR = _get_bool("FAIL_ON_EXTRACTION_ERROR", False)
# ============================================================================
# Retrieval Parameters
# ============================================================================
SEMANTIC_TOP_K = _get_int("SEMANTIC_TOP_K", 25) or 25
KEYWORD_TOP_K = _get_int("KEYWORD_TOP_K", 5) or 5
STRUCTURED_TOP_K = _get_int("STRUCTURED_TOP_K", 5) or 5
# ============================================================================
# Database Configuration
# ============================================================================
LANCEDB_PATH = _get_optional_str("LANCEDB_PATH", "./lancedb_data")
MEMORY_TABLE_NAME = _get_optional_str("MEMORY_TABLE_NAME", "memory_entries")
# ============================================================================
# Parallel / Planning Configuration
# ============================================================================
ENABLE_PARALLEL_PROCESSING = _get_bool("ENABLE_PARALLEL_PROCESSING", False)
MAX_PARALLEL_WORKERS = _get_int("MAX_PARALLEL_WORKERS", 4) or 4
ENABLE_PARALLEL_RETRIEVAL = _get_bool("ENABLE_PARALLEL_RETRIEVAL", False)
MAX_RETRIEVAL_WORKERS = _get_int("MAX_RETRIEVAL_WORKERS", 4) or 4
ENABLE_PLANNING = _get_bool("ENABLE_PLANNING", True)
ENABLE_REFLECTION = _get_bool("ENABLE_REFLECTION", False)
MAX_REFLECTION_ROUNDS = _get_int("MAX_REFLECTION_ROUNDS", 1) or 1
# ============================================================================
# Judge Configuration
# ============================================================================
JUDGE_API_KEY = _get_optional_str("JUDGE_API_KEY", OPENAI_API_KEY)
JUDGE_BASE_URL = _get_optional_str("JUDGE_BASE_URL", OPENAI_BASE_URL)
JUDGE_MODEL = _get_optional_str("JUDGE_MODEL", LLM_MODEL)
JUDGE_ENABLE_THINKING = _get_bool("JUDGE_ENABLE_THINKING", False)
JUDGE_USE_STREAMING = _get_bool("JUDGE_USE_STREAMING", False)
JUDGE_TEMPERATURE = float(os.getenv("JUDGE_TEMPERATURE", "0.3"))