Spaces:
Sleeping
Sleeping
Update services/kb_creation.py
Browse files- services/kb_creation.py +3 -3
services/kb_creation.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
|
| 2 |
-
# kb_creation.py (single file)
|
| 3 |
# ---------------------------------------------------------------
|
| 4 |
# Action-aware KB ingestion + hybrid search for SOP documents.
|
| 5 |
# Tags each chunk with intent (steps/errors), module (appointments,
|
|
@@ -408,7 +408,7 @@ def _meta_overlap(meta: Dict[str, Any], q_terms: List[str]) -> float:
|
|
| 408 |
return inter / max(1, len(q_terms))
|
| 409 |
|
| 410 |
|
| 411 |
-
def hybrid_search_knowledge_base(query: str, top_k: int = 10) -> dict:
|
| 412 |
norm_q = _normalize_query(query)
|
| 413 |
q_terms = _tokenize(norm_q)
|
| 414 |
user_actions = _detect_user_action(query)
|
|
@@ -461,7 +461,7 @@ def hybrid_search_knowledge_base(query: str, top_k: int = 10) -> dict:
|
|
| 461 |
text = sem_text if sem_text else bm25_text
|
| 462 |
meta = sem_meta if sem_meta else bm25_meta
|
| 463 |
|
| 464 |
-
base =
|
| 465 |
overlap = 0.30 * _meta_overlap(meta, q_terms)
|
| 466 |
|
| 467 |
doc_mods = [m.strip() for m in (meta.get("module_tags") or "").split(",") if m.strip()]
|
|
|
|
| 1 |
|
| 2 |
+
# kb_creation.py (single file, alpha/beta-ready)
|
| 3 |
# ---------------------------------------------------------------
|
| 4 |
# Action-aware KB ingestion + hybrid search for SOP documents.
|
| 5 |
# Tags each chunk with intent (steps/errors), module (appointments,
|
|
|
|
| 408 |
return inter / max(1, len(q_terms))
|
| 409 |
|
| 410 |
|
| 411 |
+
def hybrid_search_knowledge_base(query: str, top_k: int = 10, alpha: float = 0.55, beta: float = 0.45) -> dict:
|
| 412 |
norm_q = _normalize_query(query)
|
| 413 |
q_terms = _tokenize(norm_q)
|
| 414 |
user_actions = _detect_user_action(query)
|
|
|
|
| 461 |
text = sem_text if sem_text else bm25_text
|
| 462 |
meta = sem_meta if sem_meta else bm25_meta
|
| 463 |
|
| 464 |
+
base = alpha * sem_sim + beta * bm25_sim
|
| 465 |
overlap = 0.30 * _meta_overlap(meta, q_terms)
|
| 466 |
|
| 467 |
doc_mods = [m.strip() for m in (meta.get("module_tags") or "").split(",") if m.strip()]
|