diff --git a/pytests/A_memorix_test/test_feedback_correction_chat_flow.py b/pytests/A_memorix_test/test_feedback_correction_chat_flow.py index 3d53c618..99714ca6 100644 --- a/pytests/A_memorix_test/test_feedback_correction_chat_flow.py +++ b/pytests/A_memorix_test/test_feedback_correction_chat_flow.py @@ -470,7 +470,7 @@ async def chat_feedback_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): handled_message_ids = getattr(self._runtime, "_test_query_message_ids", None) if handled_message_ids is None: handled_message_ids = set() - setattr(self._runtime, "_test_query_message_ids", handled_message_ids) + self._runtime._test_query_message_ids = handled_message_ids if latest_message.message_id not in handled_message_ids and ( "回忆" in latest_text or "再查" in latest_text diff --git a/src/A_memorix/core/embedding/manager.py b/src/A_memorix/core/embedding/manager.py index d161e23b..a65689ac 100644 --- a/src/A_memorix/core/embedding/manager.py +++ b/src/A_memorix/core/embedding/manager.py @@ -23,10 +23,7 @@ from src.common.logger import get_logger from .presets import ( EmbeddingModelConfig, get_custom_config, - validate_config_compatibility, - are_models_compatible, ) -from ..utils.quantization import QuantizationType logger = get_logger("A_Memorix.EmbeddingManager") diff --git a/src/A_memorix/core/embedding/presets.py b/src/A_memorix/core/embedding/presets.py index 54e6f8b4..88714b22 100644 --- a/src/A_memorix/core/embedding/presets.py +++ b/src/A_memorix/core/embedding/presets.py @@ -3,7 +3,7 @@ """ from dataclasses import dataclass -from typing import Optional, Dict, Any, Union +from typing import Optional, Union from pathlib import Path diff --git a/src/A_memorix/core/retrieval/dual_path.py b/src/A_memorix/core/retrieval/dual_path.py index 437f3dd7..ae701906 100644 --- a/src/A_memorix/core/retrieval/dual_path.py +++ b/src/A_memorix/core/retrieval/dual_path.py @@ -7,7 +7,7 @@ import asyncio import re from dataclasses import dataclass, field -from typing import Optional, List, Dict, Any, Tuple, Union +from typing import Optional, List, Dict, Any, Tuple from enum import Enum import numpy as np @@ -320,7 +320,7 @@ class DualPathRetriever: # 调试模式:打印结果原文 if self.config.debug: - logger.info(f"[DEBUG] 检索结果内容原文:") + logger.info("[DEBUG] 检索结果内容原文:") for i, res in enumerate(results): logger.info(f" {i+1}. [{res.result_type}] (Score: {res.score:.4f}) {res.content}") diff --git a/src/A_memorix/core/retrieval/pagerank.py b/src/A_memorix/core/retrieval/pagerank.py index c8ee48bb..36e456d8 100644 --- a/src/A_memorix/core/retrieval/pagerank.py +++ b/src/A_memorix/core/retrieval/pagerank.py @@ -4,9 +4,8 @@ Personalized PageRank实现 提供个性化的图节点排序功能。 """ -from typing import Dict, List, Optional, Tuple, Union, Any +from typing import Dict, List, Optional, Tuple, Any from dataclasses import dataclass -import numpy as np from src.common.logger import get_logger from ..storage import GraphStore @@ -49,7 +48,7 @@ class PageRankConfig: raise ValueError(f"min_iterations必须大于等于0: {self.min_iterations}") if self.min_iterations >= self.max_iter: - raise ValueError(f"min_iterations必须小于max_iter") + raise ValueError("min_iterations必须小于max_iter") class PersonalizedPageRank: diff --git a/src/A_memorix/core/retrieval/threshold.py b/src/A_memorix/core/retrieval/threshold.py index 87a0094b..fc342b52 100644 --- a/src/A_memorix/core/retrieval/threshold.py +++ b/src/A_memorix/core/retrieval/threshold.py @@ -56,7 +56,7 @@ class ThresholdConfig: raise ValueError(f"max_threshold必须在[0, 1]之间: {self.max_threshold}") if self.min_threshold >= self.max_threshold: - raise ValueError(f"min_threshold必须小于max_threshold") + raise ValueError("min_threshold必须小于max_threshold") if not 0 <= self.percentile <= 100: raise ValueError(f"percentile必须在[0, 100]之间: {self.percentile}") diff --git a/src/A_memorix/core/runtime/lifecycle_orchestrator.py b/src/A_memorix/core/runtime/lifecycle_orchestrator.py index a421b05a..64746205 100644 --- a/src/A_memorix/core/runtime/lifecycle_orchestrator.py +++ b/src/A_memorix/core/runtime/lifecycle_orchestrator.py @@ -3,7 +3,6 @@ from __future__ import annotations import asyncio -from pathlib import Path from typing import Any, Callable, Coroutine, cast from src.common.logger import get_logger diff --git a/src/A_memorix/core/runtime/sdk_memory_kernel.py b/src/A_memorix/core/runtime/sdk_memory_kernel.py index 12681e05..ed2a60ed 100644 --- a/src/A_memorix/core/runtime/sdk_memory_kernel.py +++ b/src/A_memorix/core/runtime/sdk_memory_kernel.py @@ -4,7 +4,6 @@ import asyncio import json import pickle import time -import uuid from dataclasses import dataclass from datetime import datetime, timedelta from pathlib import Path @@ -19,7 +18,7 @@ from src.services.llm_service import LLMServiceClient from ...paths import default_data_dir, resolve_repo_path from ..embedding import create_embedding_api_adapter -from ..retrieval import RetrievalResult, SparseBM25Config, SparseBM25Index, TemporalQueryOptions +from ..retrieval import RetrievalResult, SparseBM25Config, SparseBM25Index from ..storage import GraphStore, MetadataStore, QuantizationType, SparseMatrixFormat, VectorStore from ..utils.aggregate_query_service import AggregateQueryService from ..utils.episode_retrieval_service import EpisodeRetrievalService diff --git a/src/A_memorix/core/storage/graph_store.py b/src/A_memorix/core/storage/graph_store.py index e338ffc5..f036b6e4 100644 --- a/src/A_memorix/core/storage/graph_store.py +++ b/src/A_memorix/core/storage/graph_store.py @@ -9,7 +9,6 @@ from enum import Enum from pathlib import Path from typing import Optional, Union, Tuple, List, Dict, Set, Any from collections import defaultdict -import threading import asyncio import numpy as np @@ -42,7 +41,6 @@ except ImportError: import contextlib from src.common.logger import get_logger -from ..utils.hash import compute_hash from ..utils.io import atomic_write logger = get_logger("A_Memorix.GraphStore") diff --git a/src/A_memorix/core/storage/vector_store.py b/src/A_memorix/core/storage/vector_store.py index 787e625a..3590dba1 100644 --- a/src/A_memorix/core/storage/vector_store.py +++ b/src/A_memorix/core/storage/vector_store.py @@ -4,7 +4,6 @@ 基于Faiss的高效向量存储与检索,支持SQ8量化、Append-Only磁盘存储和内存映射。 """ -import os import pickle import hashlib import shutil @@ -191,7 +190,7 @@ class VectorStore: self._update_reservoir(batch_vecs) # 这里的 TRAIN_SIZE 取默认 10k,或者根据当前数据量动态判断 if len(self._reservoir_buffer) >= 10000: - logger.info(f"训练样本达到上限,开始训练...") + logger.info("训练样本达到上限,开始训练...") self._train_and_replay_unlocked() self._total_added += len(batch_ids) diff --git a/src/A_memorix/core/strategies/base.py b/src/A_memorix/core/strategies/base.py index ff250cdf..58e05303 100644 --- a/src/A_memorix/core/strategies/base.py +++ b/src/A_memorix/core/strategies/base.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import List, Dict, Any, Optional, Union +from typing import List, Dict, Any from dataclasses import dataclass, field from enum import Enum import hashlib diff --git a/src/A_memorix/core/strategies/factual.py b/src/A_memorix/core/strategies/factual.py index 4b7d6e56..b0444ccd 100644 --- a/src/A_memorix/core/strategies/factual.py +++ b/src/A_memorix/core/strategies/factual.py @@ -1,5 +1,5 @@ import re -from typing import List, Dict, Any +from typing import List from .base import BaseStrategy, ProcessedChunk, KnowledgeType, SourceInfo, ChunkContext class FactualStrategy(BaseStrategy): diff --git a/src/A_memorix/core/strategies/narrative.py b/src/A_memorix/core/strategies/narrative.py index 731414f7..18fa6f93 100644 --- a/src/A_memorix/core/strategies/narrative.py +++ b/src/A_memorix/core/strategies/narrative.py @@ -1,5 +1,5 @@ import re -from typing import List, Dict, Any +from typing import List from .base import BaseStrategy, ProcessedChunk, KnowledgeType, SourceInfo, ChunkContext class NarrativeStrategy(BaseStrategy): diff --git a/src/A_memorix/core/strategies/quote.py b/src/A_memorix/core/strategies/quote.py index 10733d64..d4d62ce0 100644 --- a/src/A_memorix/core/strategies/quote.py +++ b/src/A_memorix/core/strategies/quote.py @@ -1,4 +1,4 @@ -from typing import List, Dict, Any +from typing import List from .base import BaseStrategy, ProcessedChunk, KnowledgeType, SourceInfo, ChunkContext, ChunkFlags class QuoteStrategy(BaseStrategy): diff --git a/src/A_memorix/core/utils/hash.py b/src/A_memorix/core/utils/hash.py index b6363257..cfcc4ec4 100644 --- a/src/A_memorix/core/utils/hash.py +++ b/src/A_memorix/core/utils/hash.py @@ -6,7 +6,6 @@ import hashlib import re -from typing import Union def compute_hash(text: str, hash_type: str = "sha256") -> str: diff --git a/src/A_memorix/core/utils/io.py b/src/A_memorix/core/utils/io.py index ed14df43..4d2f84a1 100644 --- a/src/A_memorix/core/utils/io.py +++ b/src/A_memorix/core/utils/io.py @@ -5,7 +5,6 @@ IO Utilities """ import os -import shutil import contextlib from pathlib import Path from typing import Union diff --git a/src/A_memorix/core/utils/matcher.py b/src/A_memorix/core/utils/matcher.py index bddff5ee..de84c83c 100644 --- a/src/A_memorix/core/utils/matcher.py +++ b/src/A_memorix/core/utils/matcher.py @@ -4,7 +4,7 @@ 实现 Aho-Corasick 算法用于多模式匹配。 """ -from typing import List, Dict, Tuple, Set, Any +from typing import List, Dict, Tuple, Set from collections import deque diff --git a/src/A_memorix/core/utils/path_fallback_service.py b/src/A_memorix/core/utils/path_fallback_service.py index c8ef0be8..9d7de787 100644 --- a/src/A_memorix/core/utils/path_fallback_service.py +++ b/src/A_memorix/core/utils/path_fallback_service.py @@ -3,7 +3,7 @@ from __future__ import annotations import hashlib -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Sequence, Tuple from ..retrieval.dual_path import RetrievalResult diff --git a/src/A_memorix/core/utils/runtime_self_check.py b/src/A_memorix/core/utils/runtime_self_check.py index 6e9a41f2..ae1a6635 100644 --- a/src/A_memorix/core/utils/runtime_self_check.py +++ b/src/A_memorix/core/utils/runtime_self_check.py @@ -234,7 +234,7 @@ async def ensure_runtime_self_check( sample_text=sample_text, ) try: - setattr(plugin_or_config, "_runtime_self_check_report", report) + plugin_or_config._runtime_self_check_report = report except Exception: pass return report diff --git a/src/A_memorix/core/utils/search_execution_service.py b/src/A_memorix/core/utils/search_execution_service.py index ace051e9..3206d2f0 100644 --- a/src/A_memorix/core/utils/search_execution_service.py +++ b/src/A_memorix/core/utils/search_execution_service.py @@ -287,7 +287,7 @@ class SearchExecutionService: async def _executor() -> Dict[str, Any]: original_ppr = bool(getattr(retriever.config, "enable_ppr", True)) - setattr(retriever.config, "enable_ppr", bool(request.enable_ppr)) + retriever.config.enable_ppr = bool(request.enable_ppr) started_at = time.time() try: retrieved = await retriever.retrieve( @@ -380,7 +380,7 @@ class SearchExecutionService: elapsed_ms = (time.time() - started_at) * 1000.0 return {"results": retrieved, "elapsed_ms": elapsed_ms} finally: - setattr(retriever.config, "enable_ppr", original_ppr) + retriever.config.enable_ppr = original_ppr dedup_hit = False try: diff --git a/src/A_memorix/core/utils/summary_importer.py b/src/A_memorix/core/utils/summary_importer.py index 0728e4dc..7de7839a 100644 --- a/src/A_memorix/core/utils/summary_importer.py +++ b/src/A_memorix/core/utils/summary_importer.py @@ -5,7 +5,6 @@ 导入到 A_memorix 的存储组件中。 """ -from pathlib import Path from typing import Any, Dict, List, Optional, Tuple import json diff --git a/src/A_memorix/runtime_registry.py b/src/A_memorix/runtime_registry.py index d389cba9..cac8893e 100644 --- a/src/A_memorix/runtime_registry.py +++ b/src/A_memorix/runtime_registry.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Dict, Optional +from typing import Any, Dict _runtime_kernel: Any = None diff --git a/src/A_memorix/scripts/_bootstrap.py b/src/A_memorix/scripts/_bootstrap.py index f8b72d72..6bcb0f36 100644 --- a/src/A_memorix/scripts/_bootstrap.py +++ b/src/A_memorix/scripts/_bootstrap.py @@ -15,7 +15,7 @@ for _path in (SRC_ROOT, PROJECT_ROOT, PLUGIN_ROOT): if _path_str not in sys.path: sys.path.insert(0, _path_str) -from A_memorix.paths import config_path, default_data_dir, resolve_repo_path +from A_memorix.paths import config_path, default_data_dir DEFAULT_CONFIG_PATH = config_path() DEFAULT_DATA_DIR = default_data_dir() diff --git a/src/A_memorix/scripts/convert_lpmm.py b/src/A_memorix/scripts/convert_lpmm.py index 8772fbff..e7b028f1 100644 --- a/src/A_memorix/scripts/convert_lpmm.py +++ b/src/A_memorix/scripts/convert_lpmm.py @@ -10,14 +10,12 @@ LPMM 到 A_memorix 存储转换器 """ import sys -import os -import json import argparse import asyncio import pickle import logging from pathlib import Path -from typing import Dict, Any, List, Tuple +from typing import Dict, Any, Tuple import numpy as np import tomlkit diff --git a/src/A_memorix/scripts/process_knowledge.py b/src/A_memorix/scripts/process_knowledge.py index 1dfec182..7ea6f114 100644 --- a/src/A_memorix/scripts/process_knowledge.py +++ b/src/A_memorix/scripts/process_knowledge.py @@ -12,17 +12,14 @@ from datetime import datetime from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional from rich.console import Console -from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type import argparse import asyncio import hashlib import json -import os -import random import sys import time import tomlkit diff --git a/src/A_memorix/scripts/release_vnext_migrate.py b/src/A_memorix/scripts/release_vnext_migrate.py index 49c7517c..cd16bf65 100644 --- a/src/A_memorix/scripts/release_vnext_migrate.py +++ b/src/A_memorix/scripts/release_vnext_migrate.py @@ -17,7 +17,7 @@ import sqlite3 import sys from dataclasses import dataclass from pathlib import Path -from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Sequence, Tuple import tomlkit diff --git a/src/maisaka/reasoning_engine.py b/src/maisaka/reasoning_engine.py index a5d0e290..a155eb3c 100644 --- a/src/maisaka/reasoning_engine.py +++ b/src/maisaka/reasoning_engine.py @@ -14,7 +14,6 @@ from src.chat.message_receive.message import SessionMessage from src.common.data_models.message_component_data_model import EmojiComponent, ImageComponent, MessageSequence from src.common.logger import get_logger from src.common.prompt_i18n import load_prompt -from src.config.config import global_config from src.core.tooling import ToolExecutionContext, ToolExecutionResult, ToolInvocation, ToolSpec from src.llm_models.exceptions import ReqAbortException from src.llm_models.payload_content.tool_option import ToolCall