diff --git a/src/A_memorix/core/embedding/manager.py b/src/A_memorix/core/embedding/manager.py index a65689ac..d161e23b 100644 --- a/src/A_memorix/core/embedding/manager.py +++ b/src/A_memorix/core/embedding/manager.py @@ -23,7 +23,10 @@ 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 88714b22..54e6f8b4 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, Union +from typing import Optional, Dict, Any, 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 ae701906..437f3dd7 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 +from typing import Optional, List, Dict, Any, Tuple, Union from enum import Enum import numpy as np @@ -320,7 +320,7 @@ class DualPathRetriever: # 调试模式:打印结果原文 if self.config.debug: - logger.info("[DEBUG] 检索结果内容原文:") + logger.info(f"[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 36e456d8..c8ee48bb 100644 --- a/src/A_memorix/core/retrieval/pagerank.py +++ b/src/A_memorix/core/retrieval/pagerank.py @@ -4,8 +4,9 @@ Personalized PageRank实现 提供个性化的图节点排序功能。 """ -from typing import Dict, List, Optional, Tuple, Any +from typing import Dict, List, Optional, Tuple, Union, Any from dataclasses import dataclass +import numpy as np from src.common.logger import get_logger from ..storage import GraphStore @@ -48,7 +49,7 @@ class PageRankConfig: raise ValueError(f"min_iterations必须大于等于0: {self.min_iterations}") if self.min_iterations >= self.max_iter: - raise ValueError("min_iterations必须小于max_iter") + raise ValueError(f"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 fc342b52..87a0094b 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("min_threshold必须小于max_threshold") + raise ValueError(f"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 64746205..a421b05a 100644 --- a/src/A_memorix/core/runtime/lifecycle_orchestrator.py +++ b/src/A_memorix/core/runtime/lifecycle_orchestrator.py @@ -3,6 +3,7 @@ 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 ed2a60ed..12681e05 100644 --- a/src/A_memorix/core/runtime/sdk_memory_kernel.py +++ b/src/A_memorix/core/runtime/sdk_memory_kernel.py @@ -4,6 +4,7 @@ import asyncio import json import pickle import time +import uuid from dataclasses import dataclass from datetime import datetime, timedelta from pathlib import Path @@ -18,7 +19,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 +from ..retrieval import RetrievalResult, SparseBM25Config, SparseBM25Index, TemporalQueryOptions 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 f036b6e4..e338ffc5 100644 --- a/src/A_memorix/core/storage/graph_store.py +++ b/src/A_memorix/core/storage/graph_store.py @@ -9,6 +9,7 @@ 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 @@ -41,6 +42,7 @@ 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 3590dba1..787e625a 100644 --- a/src/A_memorix/core/storage/vector_store.py +++ b/src/A_memorix/core/storage/vector_store.py @@ -4,6 +4,7 @@ 基于Faiss的高效向量存储与检索,支持SQ8量化、Append-Only磁盘存储和内存映射。 """ +import os import pickle import hashlib import shutil @@ -190,7 +191,7 @@ class VectorStore: self._update_reservoir(batch_vecs) # 这里的 TRAIN_SIZE 取默认 10k,或者根据当前数据量动态判断 if len(self._reservoir_buffer) >= 10000: - logger.info("训练样本达到上限,开始训练...") + logger.info(f"训练样本达到上限,开始训练...") 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 58e05303..ff250cdf 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 +from typing import List, Dict, Any, Optional, Union 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 b0444ccd..4b7d6e56 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 +from typing import List, Dict, Any 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 18fa6f93..731414f7 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 +from typing import List, Dict, Any 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 d4d62ce0..10733d64 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 +from typing import List, Dict, Any 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 cfcc4ec4..b6363257 100644 --- a/src/A_memorix/core/utils/hash.py +++ b/src/A_memorix/core/utils/hash.py @@ -6,6 +6,7 @@ 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 4d2f84a1..ed14df43 100644 --- a/src/A_memorix/core/utils/io.py +++ b/src/A_memorix/core/utils/io.py @@ -5,6 +5,7 @@ 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 de84c83c..bddff5ee 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 +from typing import List, Dict, Tuple, Set, Any 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 9d7de787..c8ef0be8 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, Sequence, Tuple +from typing import Any, Dict, List, Optional, 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 ae1a6635..6e9a41f2 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: - plugin_or_config._runtime_self_check_report = report + setattr(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 3206d2f0..ace051e9 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)) - retriever.config.enable_ppr = bool(request.enable_ppr) + setattr(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: - retriever.config.enable_ppr = original_ppr + setattr(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 7de7839a..0728e4dc 100644 --- a/src/A_memorix/core/utils/summary_importer.py +++ b/src/A_memorix/core/utils/summary_importer.py @@ -5,6 +5,7 @@ 导入到 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 cac8893e..d389cba9 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 +from typing import Any, Dict, Optional _runtime_kernel: Any = None diff --git a/src/A_memorix/scripts/_bootstrap.py b/src/A_memorix/scripts/_bootstrap.py index 6bcb0f36..f8b72d72 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 +from A_memorix.paths import config_path, default_data_dir, resolve_repo_path 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 e7b028f1..8772fbff 100644 --- a/src/A_memorix/scripts/convert_lpmm.py +++ b/src/A_memorix/scripts/convert_lpmm.py @@ -10,12 +10,14 @@ 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, Tuple +from typing import Dict, Any, List, 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 7ea6f114..1dfec182 100644 --- a/src/A_memorix/scripts/process_knowledge.py +++ b/src/A_memorix/scripts/process_knowledge.py @@ -12,14 +12,17 @@ from datetime import datetime from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Dict, List, 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 cd16bf65..49c7517c 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, List, Optional, Sequence, Tuple +from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple import tomlkit