feat: enforce knowledge type source hierarchy

This commit is contained in:
2026-07-17 15:14:18 +08:00
parent d647a3d44b
commit 821cb26930
3 changed files with 64 additions and 14 deletions

View File

@@ -164,6 +164,34 @@ def test_fixed_information_question_without_catalog_does_not_fall_back_to_genera
assert result.chunks == []
def test_course_type_is_preferred_over_qa_for_course_source_questions():
catalog = [
{
"knowledgeId": 2,
"name": "课程常见答疑",
"type": "qa",
"purpose": "回答课程练习问题",
"applicableQuestions": "课程练习",
"coreTopics": "静心练习",
"publishedAt": "2026-07-17T10:00:00",
},
{
"knowledgeId": 1,
"name": "课程原文",
"type": "course",
"purpose": "说明课程练习方法",
"applicableQuestions": "课程练习",
"coreTopics": "静心练习",
"publishedAt": "2026-07-16T10:00:00",
},
]
need_knowledge, selected_ids, _ = KnowledgeAgentService._decide("课程里的静心练习怎么做?", catalog)
assert need_knowledge is True
assert selected_ids[:2] == [1, 2]
def test_fixed_information_is_retrieved_first_and_overrides_other_types():
with _database() as db:
_add_published_knowledge(