Commit 1280b860 by 黄南光

Merge remote-tracking branch 'origin/codex/file-list-sort-filter' into codex/file-list-sort-filter

# Conflicts:
#	src/api/routes/ingest.py
2 parents d05f2472 49138246
......@@ -35,6 +35,16 @@ INGEST_MODEL_NAME = os.environ.get("INGEST_MODEL_NAME", "qwen3.7-plus")
QUERY_MODEL_NAME = os.environ.get("QUERY_MODEL_NAME", "deepseek-v4-flash")
LINT_MODEL_NAME = os.environ.get("LINT_MODEL_NAME", "deepseek-v4-flash")
# ==================================================================================
# 摄入并发控制
# ==================================================================================
# #2: 同时允许并行摄入的文件数量上限。设为 1 等价于旧的全局串行锁。
# 建议根据 LLM API 速率限制调整(默认 3 份文件并行)。
INGEST_MAX_CONCURRENT_FILES = int(os.environ.get("INGEST_MAX_CONCURRENT_FILES", "3"))
# #11: 单个文件内 Phase 2 Writer 并发数(同时向 LLM 提交的页面写作请求数)。
INGEST_WRITER_CONCURRENCY = int(os.environ.get("INGEST_WRITER_CONCURRENCY", "20"))
# INGEST_MODEL_NAME = os.environ.get("INGEST_MODEL_NAME", "qwen3.7-plus")
# QUERY_MODEL_NAME = os.environ.get("QUERY_MODEL_NAME", "qwen3.7-plus")
# LINT_MODEL_NAME = os.environ.get("LINT_MODEL_NAME", "qwen3.7-plus")
......
......@@ -51,6 +51,13 @@ async def startup_event():
await init_db()
await ensure_wiki_schema()
logger.info("Database initialized.")
# #3: 重启恢复 — 将上次中断的 Ingesting 文件回滚为 Pending
try:
from src.api.routes.ingest import recover_interrupted_ingests
recovered = await recover_interrupted_ingests()
logger.info("Ingest recovery check finished: recovered=%d", recovered)
except Exception as exc:
logger.warning("Ingest recovery check failed: %s", exc)
try:
from src.rag.service import repair_interrupted_indexes
......
......@@ -206,6 +206,15 @@ ecosystem_names:
- 嘀加 # 合作生态/产品服务品牌,不是车辆 brand
- 广联数科 # 公司/生态名称,不是车辆 brand
# Planner 未返回或无法确定某维度时的兜底默认值。
# Python 摄入网关从此处读取,避免业务默认值散布在代码中。
dim_defaults:
series: "未知系列[待确认]"
brand: "未知品牌[待确认]"
business_category: "未知业务[待确认]"
sub_business: "未知子业务[待确认]"
role: "通用"
# tags 建议词表。tags 是自由检索标签,不参与 5 维结构化过滤。
tag_suggestions:
- 异议处理 # 销售异议处理场景
......
......@@ -11,6 +11,9 @@ import yaml
CONTRACT_START = "<!-- INGEST_CONTRACT_START -->"
CONTRACT_END = "<!-- INGEST_CONTRACT_END -->"
# #5: Planner 每个 page 必须包含的字段
_PLANNER_PAGE_REQUIRED = ("type", "slug", "file_path", "title")
@dataclass(frozen=True)
class IngestContract:
......@@ -23,6 +26,7 @@ class IngestContract:
business_categories: tuple[str, ...]
vehicle_brands: tuple[str, ...]
ecosystem_names: tuple[str, ...]
dim_defaults: dict[str, str] # #9: Planner 维度兜底默认值
prompt_text: str
......@@ -73,6 +77,10 @@ def load_ingest_contract(schema_path: str | None = None) -> IngestContract:
if not canonical_types:
raise ValueError("schema contract 缺少 canonical_types")
# #9: 解析 dim_defaults,不存在时使用空字典(代码内有硬编码兜底)
dim_defaults_raw = raw.get("dim_defaults") or {}
dim_defaults = {str(k): str(v) for k, v in dim_defaults_raw.items()}
return IngestContract(
schema_version=str(raw.get("schema_version") or "").strip(),
required_fields=tuple(raw.get("required_fields") or ()),
......@@ -83,6 +91,7 @@ def load_ingest_contract(schema_path: str | None = None) -> IngestContract:
business_categories=tuple(raw.get("business_categories") or ()),
vehicle_brands=_flatten_vehicle_brands(raw.get("vehicle_brands") or {}),
ecosystem_names=tuple(raw.get("ecosystem_names") or ()),
dim_defaults=dim_defaults,
prompt_text=schema_text,
)
......@@ -186,3 +195,53 @@ def recompute_after_source_removal(
md["field_sources"] = fs
else:
md.pop("field_sources", None)
def validate_planner_output(plan_data: dict) -> tuple[dict, list[dict]]:
"""#5: 校验 Planner JSON 输出结构,返回 (global_dims, pages)。
格式不合规时抛 ValueError,让 Phase 1 直接终止或触发重试,
而非静默地将格式错误延迟到 Phase 2/3 才暴露。
"""
if not isinstance(plan_data, dict):
raise ValueError(
f"Planner 输出必须是 JSON 对象,实际类型为 {type(plan_data).__name__}"
)
pages = plan_data.get("pages")
if not isinstance(pages, list) or len(pages) == 0:
raise ValueError(
f"Planner 输出的 pages 必须是非空数组,"
f"实际类型为 {type(pages).__name__ if pages is not None else 'null'}"
)
for i, page in enumerate(pages):
if not isinstance(page, dict):
raise ValueError(
f"pages[{i}] 必须是 JSON 对象,实际类型为 {type(page).__name__}"
)
missing = [f for f in _PLANNER_PAGE_REQUIRED if not page.get(f)]
if missing:
raise ValueError(
f"pages[{i}](slug={page.get('slug', '?')})缺少必填字段: {missing}"
)
global_dims = plan_data.get("global_dims")
if global_dims is not None and not isinstance(global_dims, dict):
raise ValueError(
f"global_dims 必须是 JSON 对象或 null,实际类型为 {type(global_dims).__name__}"
)
# 必须包含至少 1 个 sources 类型页面
has_sources = any(
isinstance(p, dict) and str(p.get("type", "")).strip() in ("sources", "source")
for p in pages
)
if not has_sources:
raise ValueError(
"Planner 规划必须包含至少 1 个 type=sources 的来源摘要页"
)
return global_dims or {}, pages
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!