srilakshu012456 commited on
Commit
8babecf
·
verified ·
1 Parent(s): 416f7ae

Update services/kb_creation.py

Browse files
Files changed (1) hide show
  1. 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
- overlap = len(set(user_actions) & set(doc_actions))
523
- if overlap == 0:
524
- if "update" in user_actions and "create" in doc_actions:
525
- return -1.0
526
- return -0.3
527
- return 0.9 * overlap
 
 
 
 
 
 
 
 
 
 
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)