fix(knowledge-graph): 修复 KG 全局问答查询侧模型选错 + 凭证缺失 + 不可重试错误盲目重试 - #538
Merged
Conversation
四项级联缺陷修复(端到端 ~8.8s 退化至 <2s,evidence=0 误报修正): 1. 查询侧 embedding 模型脱钩:global_search / graph_search / multi_hop fallback 三处端点改为 先解 corpus.config.models 中的 embedding_config_id,再传入 build_embedding_fn—— 与 ingestion 写入摘要 embedding 时同一模型 → 同一向量空间; 2. GlobalSearchService 接入 llm_config_id 参数与 extra_kwargs 透传,对齐 community_summarizer 既定模式,避免回退到硬编码 openai/gpt-5-mini + 无凭证; 3. 提取 _resolve_corpus_model_ids 共享 helper,复用 graph/service.py 已确立的 corpus.config JSONB 查询模式(字段口径与 _MODELS_WHITELIST 一致:embedding_config_id / llm_config_id); 4. 新增 _is_non_retryable_error 模块级 helper(双层兜底:litellm.exceptions isinstance + 字符串模式),call_llm_with_retry / _call_with_retry 在凭证 / 路由 / 参数类终态错误时 立即放弃,避免 N×退避空转; 5. global_search 零证据语义二分:candidates>0 但全部 map 失败时 answer 改为「全局检索失败」 + 基础设施排查指引,杜绝把基础设施故障伪装成内容缺失。 测试:test_global_search 新增 3 个用例(llm_config_id 路由 / 默认 fallback / 零证据 infrastructure-error 文案),test_embedding 新增 TestNonRetryableFailFast 4 个用例 (Auth/NotFound/文本兜底/transient 仍重试);knowledge 子集 816 项断言全过。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
记录本次修复的表因、根因(按层级追溯)、处理方式、验证证据、后续防范与同类问题影响, 按既有「跨上下文留存问题处理经验」格式与上一条 ISSUE-085 对齐。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
gemini/text-embedding-004而非 corpus.config 中的模型)、completion 调用回退到无凭证的硬编码openai/gpt-5-mini、不可重试错误(AuthenticationError / NotFoundError)仍执行完整 3 次指数退避、零证据时把基础设施故障伪装成内容缺失。端到端一次请求耗时 ~8.8s 且 evidence=0。核心变更
_resolve_corpus_model_ids共享 helper(api_helpers.py),从corpus.config['models']解出embedding_config_id/llm_config_id;global_search_knowledge_graph/search_knowledge_graph/multi_hop_reasoningfallback 三处端点统一注入,与 ingestion 端同一向量空间。llm_config_id参数;_call_llm重写为三级优先级解析(resolve_llm_config_by_id>resolve_llm_config>get_fallback_llm_config)+extra_kwargs透传到call_llm_with_retry,对齐community_summarizer._call_llm既定模式。extractors.py新增_is_non_retryable_error双层兜底 helper(litellm exceptions isinstance + 字符串模式);call_llm_with_retry/embedding.py::_call_with_retry在凭证/路由/参数类终态错误时立即放弃,避免 N×退避空转。风险与回滚
config.models时 helper 返回(None, None),build_embedding_fn(None)等价于修复前行为——向后兼容,风险极低。git revert两次提交即可;所有变更限定在 5 个 src 文件 + 2 个 test 文件 + 1 个 doc 文件。验证证据
test_global_search.py新增 3 个用例(llm_config_id路由 / 默认 fallback / 零证据 infrastructure-error 文案);test_embedding.py新增TestNonRetryableFailFast4 个用例(Auth/NotFound/文本兜底/transient 仍重试)。tests/unit_tests/knowledge/全量 816 项断言通过(pre-existingtest_extraction_llm_plan失败已git stash对照确认与本次修复无关)。uv run python内联 smoke 校验_is_non_retryable_error6 种异常契约 +GlobalSearchService(llm_config_id=...)构造/读字段一致。影响范围
api.py/api_helpers.py/global_search.py/extractors.py/embedding.py共 5 个 src 文件。docs/issue.md追加 ISSUE-086 摘要。Next Best Action
embedding_request日志指向语料库专属模型(非 localhost:3392)且 evidence > 0。community_summarizer._call_llm评估是否也应迁移到llm_config_id注入模式(当前以 caller 显式 model +resolve_llm_config()凭证拼接,若 corpus 绑定非默认 LLM 时会凭证/模型不匹配)。