Spaces:
Sleeping
Sleeping
Update services/kb_creation.py
Browse files- services/kb_creation.py +17 -7
services/kb_creation.py
CHANGED
|
@@ -516,15 +516,25 @@ def _literal_query_match_boost(text: str, query_norm: str) -> float:
|
|
| 516 |
# NEW: weight using metadata action tags overlap
|
| 517 |
def _action_meta_weight(meta: Dict[str, Any], user_actions: List[str]) -> float:
|
| 518 |
raw = (meta or {}).get("action_tags", "") or ""
|
| 519 |
-
doc_actions = [a.strip() for a in raw.split(",") if a.strip()] if isinstance(raw, str) else (raw or [])
|
| 520 |
if not user_actions:
|
| 521 |
return 0.0
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
def hybrid_search_knowledge_base(query: str, top_k: int = 10, alpha: float = 0.6, beta: float = 0.4) -> dict:
|
| 530 |
norm_query = _normalize_query(query)
|
|
|
|
| 516 |
# NEW: weight using metadata action tags overlap
|
| 517 |
def _action_meta_weight(meta: Dict[str, Any], user_actions: List[str]) -> float:
|
| 518 |
raw = (meta or {}).get("action_tags", "") or ""
|
| 519 |
+
doc_actions = [a.strip().lower() for a in raw.split(",") if a.strip()] if isinstance(raw, str) else (raw or [])
|
| 520 |
if not user_actions:
|
| 521 |
return 0.0
|
| 522 |
+
ua = set(a.lower() for a in user_actions)
|
| 523 |
+
da = set(doc_actions)
|
| 524 |
+
|
| 525 |
+
# Strong preference for overlap
|
| 526 |
+
overlap = len(ua & da)
|
| 527 |
+
if overlap > 0:
|
| 528 |
+
return 1.2 * overlap # stronger positive
|
| 529 |
+
|
| 530 |
+
# Symmetric demotion when clearly conflicting
|
| 531 |
+
if "update" in ua and "create" in da and "update" not in da:
|
| 532 |
+
return -1.4
|
| 533 |
+
if "create" in ua and "update" in da and "create" not in da:
|
| 534 |
+
return -1.2
|
| 535 |
+
|
| 536 |
+
# Mild demotion for no overlap
|
| 537 |
+
return -0.4
|
| 538 |
|
| 539 |
def hybrid_search_knowledge_base(query: str, top_k: int = 10, alpha: float = 0.6, beta: float = 0.4) -> dict:
|
| 540 |
norm_query = _normalize_query(query)
|