Spaces:
Sleeping
Sleeping
Commit ·
7d2b5a0
1
Parent(s): f15911b
fix(single_brain): KI-236 — explicit retrieval query construction guidance
Browse filesLive smoke test of Path B showed Gemini constructing vague queries
("first family policy") that returned 0 chunks. Strengthens both the
SYSTEM_PROMPT and the retrieve_policies query parameter description with:
- Explicit profile-attribute checklist (family shape, city tier, SI band,
age band, health condition or "no PED", primary goal)
- A concrete query example built from a sample profile snapshot
- Retry-with-broader-query rule before giving up on empty results
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- backend/single_brain.py +22 -3
backend/single_brain.py
CHANGED
|
@@ -74,9 +74,23 @@ TOOL USE RULES:
|
|
| 74 |
- After the recommendation, the user may ask follow-ups. For "tell me about #2", call retrieve_policies(query, policy_filter_ids=[the policy_id]) to narrow.
|
| 75 |
- Call mark_recommendation with the policy_ids whenever you put a ranked shortlist in your reply.
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
GROUND RULES:
|
| 78 |
- NEVER invent policies, UINs, premiums, or sums insured. Only cite what retrieve_policies returns.
|
| 79 |
-
- If retrieve_policies returns zero chunks
|
|
|
|
| 80 |
- Be concise: 2-3 sentence turns. No emoji unless the user used one first.
|
| 81 |
- Indian context: use lakh / crore, ₹, IRDAI, Section 80D. Don't say "dollars" or "$".
|
| 82 |
- Returning users may have a pre-populated profile — greet them by name, summarise what you remember, and ask them to confirm or update before recommending.
|
|
@@ -167,8 +181,13 @@ TOOL_SCHEMAS: list[dict] = [
|
|
| 167 |
"query": {
|
| 168 |
"type": "STRING",
|
| 169 |
"description": (
|
| 170 |
-
"Natural-language search query
|
| 171 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
),
|
| 173 |
},
|
| 174 |
"top_k": {
|
|
|
|
| 74 |
- After the recommendation, the user may ask follow-ups. For "tell me about #2", call retrieve_policies(query, policy_filter_ids=[the policy_id]) to narrow.
|
| 75 |
- Call mark_recommendation with the policy_ids whenever you put a ranked shortlist in your reply.
|
| 76 |
|
| 77 |
+
QUERY CONSTRUCTION FOR retrieve_policies:
|
| 78 |
+
- ALWAYS build the query string from the profile snapshot. NEVER pass a vague phrase like "first family policy" or "best plan".
|
| 79 |
+
- Required ingredients in the query: family-shape (individual / family floater / parents),
|
| 80 |
+
city tier (metro / tier-2 / tier-3), sum-insured band (e.g. "10-15 lakh"), age band,
|
| 81 |
+
health condition keywords (if any) or "no PED", and the primary goal keyword.
|
| 82 |
+
- Example for {age=34, location_tier=metro, income_band=10-25L, dependents=spouse+1 kid,
|
| 83 |
+
primary_goal=first_buy, health_conditions=[]}:
|
| 84 |
+
query = "family floater plan metro tier-1 sum insured 10-15 lakh adult 30-40 with spouse and one child no pre-existing diseases first-time buyer"
|
| 85 |
+
- Top-k 8 is the default; raise to 12 only when retrieving for comparison across many policies.
|
| 86 |
+
- If the FIRST retrieve_policies call returns 0 or 1 chunk, do NOT give up — retry once with a
|
| 87 |
+
broader query (drop the most specific filter, e.g. drop the health-condition keyword, or
|
| 88 |
+
broaden the sum-insured band by one tier) before asking the user a clarifying question.
|
| 89 |
+
|
| 90 |
GROUND RULES:
|
| 91 |
- NEVER invent policies, UINs, premiums, or sums insured. Only cite what retrieve_policies returns.
|
| 92 |
+
- If retrieve_policies returns zero chunks after both attempts above, ask the user a clarifying
|
| 93 |
+
question (e.g. "Would you be open to a slightly higher sum insured?") — do NOT fabricate.
|
| 94 |
- Be concise: 2-3 sentence turns. No emoji unless the user used one first.
|
| 95 |
- Indian context: use lakh / crore, ₹, IRDAI, Section 80D. Don't say "dollars" or "$".
|
| 96 |
- Returning users may have a pre-populated profile — greet them by name, summarise what you remember, and ask them to confirm or update before recommending.
|
|
|
|
| 181 |
"query": {
|
| 182 |
"type": "STRING",
|
| 183 |
"description": (
|
| 184 |
+
"Natural-language search query. BUILD IT FROM THE "
|
| 185 |
+
"PROFILE SNAPSHOT, not from user phrasing. Include: "
|
| 186 |
+
"family shape, city tier, sum-insured band, age band, "
|
| 187 |
+
"health-condition keywords (or 'no PED'), and the "
|
| 188 |
+
"primary goal. Example: 'family floater plan metro "
|
| 189 |
+
"sum insured 10-15 lakh adult 30-40 with spouse and "
|
| 190 |
+
"one child no pre-existing diseases first-time buyer'."
|
| 191 |
),
|
| 192 |
},
|
| 193 |
"top_k": {
|