diff --git a/app/service/agent/implementations/customer_service.py b/app/service/agent/implementations/customer_service.py index ba717bb..4bcb605 100644 --- a/app/service/agent/implementations/customer_service.py +++ b/app/service/agent/implementations/customer_service.py @@ -262,7 +262,11 @@ class CustomerServiceAgent(BaseAgent): first = next((line.strip() for line in answer.splitlines() if line.strip()), "") first = first.lstrip("#").strip() topic = first.split(":", 1)[0].strip() if ":" in first else first - if not topic or len(topic) > 20 or "," in topic or "。" in topic: + # FAQ 型回答的首行是"问:C1 客户能买什么产品?",冒号前只有一个"问"字; + # 拿它当主语只会把检索词污染成"问 那它风险高吗"。 + if not topic or topic in {"问", "答"}: + return "" + if len(topic) > 20 or "," in topic or "。" in topic: return "" return topic diff --git a/tests/unit/service/test_customer_service_search_query.py b/tests/unit/service/test_customer_service_search_query.py index cf63daf..745ec71 100644 --- a/tests/unit/service/test_customer_service_search_query.py +++ b/tests/unit/service/test_customer_service_search_query.py @@ -51,6 +51,13 @@ def test_fallback_answer_yields_no_topic() -> None: assert CustomerServiceAgent._topic_of("") == "" +def test_faq_style_answer_yields_no_topic() -> None: + """FAQ 型回答首行是"问:…",冒号前只有一个"问"字,不能当主语。""" + assert CustomerServiceAgent._topic_of( + "问:C1 客户能买什么产品?\n答:C1(保守型)客户可以购买 R1、R2 等级的产品。" + ) == "" + + def test_topic_change_does_not_drag_previous_question_in() -> None: """客户换话题时,检索词里不能出现上一轮的痕迹(实测的答非所问场景)。""" query = CustomerServiceAgent._search_query(_request("基金赎回几天到账", PREVIOUS, ANSWER))