rohitsar567 commited on
Commit
33b4a96
·
1 Parent(s): c20e471

fix(api): KI-129 — /api/coverage must not surface 'profile' as an insurer

Browse files

The marketplace badge was showing '157 POLICIES / 21 INSURERS' on the live
HF Space when real corpus is 156/20. The +1 in each came from a 'profile'
slug surfacing in /api/coverage's by-insurer aggregation.

Background — per KI-118 design (backend/profile_rag.py:24), profile chunks
INTENTIONALLY live in the same Chroma 'policies' collection as policy
chunks. The orchestrator boosts them at retrieval time so the LLM sees a
'USER CONTEXT' block alongside policy/regulatory text — this is correct
and stays. But they were leaking into user-facing aggregations.

Fix is a 4-line filter in main.py at the /api/coverage by-insurer loop:
skip any chunk where insurer_slug=='profile' OR doc_type=='profile'. The
chunks remain queryable for retrieval boosting; they just don't count.

Verified on localhost (port 8000) after restart:
total_chunks=7296, total_policies=156, total_insurers=20, no 'profile' slug.

This is the user-visible piece. The companion endpoint /api/policies/all
reads from rag/extracted/*.json on disk (not Chroma), so it's unaffected.

No DATASET_CACHE_BUST bump needed — this is a code-only change; data is
unchanged. HF Space rebuild picks up the patched main.py on next push.

Files changed (1) hide show
  1. backend/main.py +6 -0
backend/main.py CHANGED
@@ -558,6 +558,12 @@ async def coverage():
558
  res = coll.get(limit=10000, include=["metadatas"])
559
  for m in res.get("metadatas", []):
560
  slug = m.get("insurer_slug", "unknown")
 
 
 
 
 
 
561
  name = m.get("policy_name", "")
562
  url = m.get("source_url", "")
563
  if slug not in by_insurer:
 
558
  res = coll.get(limit=10000, include=["metadatas"])
559
  for m in res.get("metadatas", []):
560
  slug = m.get("insurer_slug", "unknown")
561
+ # KI-129 (2026-05-15) — profile chunks live in the same
562
+ # collection as policies (KI-118 design — they get retrieval-
563
+ # boosted as USER CONTEXT inline with policy text), but they
564
+ # must NEVER count as a user-facing insurer or policy. Skip.
565
+ if slug == "profile" or m.get("doc_type") == "profile":
566
+ continue
567
  name = m.get("policy_name", "")
568
  url = m.get("source_url", "")
569
  if slug not in by_insurer: