router.py 624 B

123456789101112131415161718
  1. from __future__ import annotations
  2. import re
  3. _RELATIONSHIP_MARKERS = ("上游", "下游", "依赖", "关联", "经过", "血缘")
  4. _GLOBAL_MARKERS = ("整体", "主要主题", "跨域", "总结")
  5. _EXACT_PATTERN = re.compile(r"[\"'“”‘’`]|\b[a-zA-Z][a-zA-Z0-9_.$-]{2,}\b")
  6. def route_query(query: str) -> str:
  7. normalized = query.strip()
  8. if any(marker in normalized for marker in _RELATIONSHIP_MARKERS):
  9. return "relationship"
  10. if any(marker in normalized for marker in _GLOBAL_MARKERS):
  11. return "global"
  12. if _EXACT_PATTERN.search(normalized):
  13. return "exact"
  14. return "semantic"