Spaces:
Sleeping
fix(#61): resolve the version-specific chunk-bearing card, not the empty base
Browse filesGround truth: my resolver returned the BASE 'niva-bupa__health-companion'
(0 corpus chunks) for 'Niva Bupa Health Companion V2022' because the base
name scored more generic tokens than 'Health Companion V2022' β so even
with the gate bypass, retrieval found nothing β 'I couldn't find it'.
Fix: when the query carries an explicit version token (v2022/2022),
the matched card whose name contains that exact version wins. Verified
deterministically: the exact #28 query β niva-bupa__health-companion-
v2022__brochure (5 chunks), base name w/o version β base, HDFC Optima
Restore β its id, generic/recommendation β None (gate intact). Gate
rc=0. Residual (flagged, not hidden): a 'V22' abbreviation vs 'V2022'
card name still maps to the chunk-less base; primary phrasing works.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- backend/brain_tools.py +22 -2
|
@@ -851,7 +851,7 @@ def _resolve_named_policy(query: str) -> Optional[str]:
|
|
| 851 |
if len(q) < 8:
|
| 852 |
return None
|
| 853 |
from backend.main import _marketplace_catalogue # lazy: avoids cycle
|
| 854 |
-
scored: list[tuple[int, float, str]] = []
|
| 855 |
for c in _marketplace_catalogue(None):
|
| 856 |
name = (getattr(c, "policy_name", "") or "").lower()
|
| 857 |
toks = {
|
|
@@ -865,9 +865,29 @@ def _resolve_named_policy(query: str) -> Optional[str]:
|
|
| 865 |
if hit >= 2 and cov >= 0.6:
|
| 866 |
pid = getattr(c, "policy_id", None)
|
| 867 |
if pid:
|
| 868 |
-
scored.append((hit, cov, pid))
|
| 869 |
if not scored:
|
| 870 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 871 |
scored.sort(key=lambda s: (s[0], s[1]), reverse=True)
|
| 872 |
if len(scored) == 1 or scored[0][0] > scored[1][0]:
|
| 873 |
return scored[0][2]
|
|
|
|
| 851 |
if len(q) < 8:
|
| 852 |
return None
|
| 853 |
from backend.main import _marketplace_catalogue # lazy: avoids cycle
|
| 854 |
+
scored: list[tuple[int, float, str, str]] = []
|
| 855 |
for c in _marketplace_catalogue(None):
|
| 856 |
name = (getattr(c, "policy_name", "") or "").lower()
|
| 857 |
toks = {
|
|
|
|
| 865 |
if hit >= 2 and cov >= 0.6:
|
| 866 |
pid = getattr(c, "policy_id", None)
|
| 867 |
if pid:
|
| 868 |
+
scored.append((hit, cov, pid, name))
|
| 869 |
if not scored:
|
| 870 |
return None
|
| 871 |
+
# VERSION DISAMBIGUATION (#61) β when the user explicitly states a
|
| 872 |
+
# version ("...Health Companion V2022" / "V22"), the matching card
|
| 873 |
+
# that carries that exact version token MUST win, even if a shorter
|
| 874 |
+
# base-name card scores more generic tokens. Without this the base
|
| 875 |
+
# "Niva Bupa Health Companion" (0 corpus chunks) was chosen over
|
| 876 |
+
# "Health Companion V2022" (the card the user named, which HAS
|
| 877 |
+
# chunks) β retrieval returned nothing β "I couldn't find it".
|
| 878 |
+
_ver = set(_re.findall(r"\bv?\d{2,4}\b", q))
|
| 879 |
+
if _ver:
|
| 880 |
+
_vmatch = [
|
| 881 |
+
s for s in scored
|
| 882 |
+
if any(v in _re.sub(r"[^a-z0-9 ]", " ",
|
| 883 |
+
s[3]).split() for v in _ver)
|
| 884 |
+
]
|
| 885 |
+
if len(_vmatch) == 1:
|
| 886 |
+
return _vmatch[0][2]
|
| 887 |
+
if _vmatch:
|
| 888 |
+
_vmatch.sort(key=lambda s: (s[0], s[1]), reverse=True)
|
| 889 |
+
if len(_vmatch) == 1 or _vmatch[0][0] > _vmatch[1][0]:
|
| 890 |
+
return _vmatch[0][2]
|
| 891 |
scored.sort(key=lambda s: (s[0], s[1]), reverse=True)
|
| 892 |
if len(scored) == 1 or scored[0][0] > scored[1][0]:
|
| 893 |
return scored[0][2]
|