fix: 修复 11 个代码架构审计问题
H1: AppConfig 自定义 __init__ 改用 from_dict() 类方法 H2: list_collections_with_stats 改为从 ChromaDB 直接查询 H3: RateLimiter 过期 key 自动清理, 防止内存泄漏 M1: delete_by_source 区分 ValueError 与真实异常, 记日志 M2: VectorDB 新增 list_collections() 封装方法 M3: _remove_by_source 异常记日志, 不再静默吞掉 M4: CLI 集合回退支持 MD_VECTOR_DB_COLLECTION 环境变量 L1: DEFAULT_CONFIG_PATH 自动从项目根目录解析 L2: ingest 命令内重复 import 移至模块顶部 L3: 新增死循环回归测试 + 密集分隔符分块测试 L4: 统一 logger 名称为 md-vector-db 删除旧版审计文档 测试: 48 passed
This commit is contained in:
+7
-4
@@ -3,6 +3,8 @@ from pathlib import Path
|
||||
import sys
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import glob as _glob
|
||||
from typing import Annotated
|
||||
|
||||
import typer
|
||||
@@ -45,7 +47,10 @@ def _init_shared(config_path: str = DEFAULT_CONFIG_PATH):
|
||||
|
||||
|
||||
def _get_default_collection() -> str:
|
||||
return _cfg.chroma.collection_name if _cfg else "markdown_docs"
|
||||
return os.environ.get(
|
||||
"MD_VECTOR_DB_COLLECTION",
|
||||
_cfg.chroma.collection_name if _cfg else "markdown_docs",
|
||||
)
|
||||
|
||||
|
||||
def _resolve_collection(collection: str | None) -> str:
|
||||
@@ -94,10 +99,8 @@ def ingest(
|
||||
total = 0
|
||||
for fp in file_paths:
|
||||
# 支持通配符 (shell 展开或 Python glob)
|
||||
from pathlib import Path as _Path
|
||||
p = _Path(fp)
|
||||
p = Path(fp)
|
||||
if "*" in fp or "?" in fp:
|
||||
import glob as _glob
|
||||
matches = _glob.glob(fp, recursive=True)
|
||||
for m in matches:
|
||||
c = ingestor.ingest_file(m)
|
||||
|
||||
Reference in New Issue
Block a user