diff --git a/CLAUDE.md b/CLAUDE.md index 1f0a8db..7b47a55 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,7 +11,7 @@ Markdown 文档向量数据库 — 将 .md 文件分块 → 嵌入 → 存入 Ch ```bash # --- 安装与测试 --- uv sync # 安装依赖(lockfile 已锁定 CUDA torch) -uv run pytest tests/ -v # 全部测试 (46 个) +uv run pytest tests/ -v # 全部测试 (115+ 个) uv run pytest tests/test_api.py -v # 单个测试模块 uv run pytest tests/ -v -k "test_search" # 按名称过滤 diff --git a/README.md b/README.md index be2f275..cb1fc9d 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ md-vector-db/ ## 测试 ```bash -uv run pytest tests/ -v # 全部测试 (46 个) +uv run pytest tests/ -v # 全部测试 (115+ 个) uv run pytest tests/test_embedder.py -v # 嵌入器测试 uv run pytest tests/ -v -k "search" # 按名称过滤 uv run pytest tests/ -v --cov=src --cov-report=term-missing # 覆盖率 diff --git a/src/server/app.py b/src/server/app.py index 5097c9a..3b0b96f 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -106,7 +106,11 @@ def list_collections( state: AppState = Depends(get_state), _: bool = Depends(verify_api_key), ): - return {"collections": state.list_collections_with_stats()} + try: + return {"collections": state.list_collections_with_stats()} + except Exception: + logger.exception("列出集合失败") + raise HTTPException(status_code=500, detail="服务器内部错误") @app.post("/api/v1/ingest") diff --git a/src/server/deps.py b/src/server/deps.py index 04899e6..1ccf2f9 100644 --- a/src/server/deps.py +++ b/src/server/deps.py @@ -54,11 +54,8 @@ class AppState: def list_collections_with_stats(self) -> list[dict]: """列出所有 collection 及其统计(直接从 ChromaDB 查询).""" result = [] - try: - for coll in self.db.list_collections(): - result.append({"name": coll.name, "count": coll.count()}) - except Exception: - logger.exception("列出集合失败") + for coll in self.db.list_collections(): + result.append({"name": coll.name, "count": coll.count()}) return result def is_healthy(self) -> dict: