Spaces:
Sleeping
Sleeping
Update app/rag/self_rag.py
Browse files- app/rag/self_rag.py +9 -4
app/rag/self_rag.py
CHANGED
|
@@ -17,7 +17,7 @@ class SelfRAG:
|
|
| 17 |
fallback = {
|
| 18 |
"should_retrieve": normalized not in simple_markers,
|
| 19 |
"retrieve": normalized not in simple_markers,
|
| 20 |
-
"intent": "smalltalk" if normalized in simple_markers else "
|
| 21 |
"risk_level": "low" if normalized in simple_markers else "medium",
|
| 22 |
}
|
| 23 |
result = self.llm.invoke_json(
|
|
@@ -27,7 +27,7 @@ class SelfRAG:
|
|
| 27 |
"Return JSON with exactly these keys:\n"
|
| 28 |
"- should_retrieve: boolean\n"
|
| 29 |
"- retrieve: boolean, same value as should_retrieve\n"
|
| 30 |
-
"- intent: one of smalltalk, general_insurance_concept, claim_scenario\n"
|
| 31 |
"- risk_level: one of low, medium, high\n\n"
|
| 32 |
"Use general_insurance_concept for educational questions about insurance terms, "
|
| 33 |
"regulation, compliance, procedures, definitions, or how insurance works. These "
|
|
@@ -36,6 +36,11 @@ class SelfRAG:
|
|
| 36 |
"death, bill, repair, approval, denial, coverage, or asks whether insurance will pay. "
|
| 37 |
"These questions should retrieve.\n"
|
| 38 |
"Use smalltalk only for greetings or capability questions. These usually do not retrieve.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"High risk means coverage decisions, denial, settlement, legal, fraud, death, injury, "
|
| 40 |
"large loss, regulatory complaint, or money."
|
| 41 |
),
|
|
@@ -43,12 +48,12 @@ class SelfRAG:
|
|
| 43 |
fallback=fallback,
|
| 44 |
)
|
| 45 |
intent = str(result.get("intent", fallback["intent"]))
|
| 46 |
-
if intent not in {"smalltalk", "general_insurance_concept", "claim_scenario"}:
|
| 47 |
intent = fallback["intent"]
|
| 48 |
should_retrieve = bool(result.get("should_retrieve", fallback["should_retrieve"]))
|
| 49 |
if intent in {"general_insurance_concept", "claim_scenario"}:
|
| 50 |
should_retrieve = True
|
| 51 |
-
if intent
|
| 52 |
should_retrieve = False
|
| 53 |
risk_level = str(result.get("risk_level", fallback["risk_level"]))
|
| 54 |
if risk_level not in {"low", "medium", "high"}:
|
|
|
|
| 17 |
fallback = {
|
| 18 |
"should_retrieve": normalized not in simple_markers,
|
| 19 |
"retrieve": normalized not in simple_markers,
|
| 20 |
+
"intent": "smalltalk" if normalized in simple_markers else "out_of_domain",
|
| 21 |
"risk_level": "low" if normalized in simple_markers else "medium",
|
| 22 |
}
|
| 23 |
result = self.llm.invoke_json(
|
|
|
|
| 27 |
"Return JSON with exactly these keys:\n"
|
| 28 |
"- should_retrieve: boolean\n"
|
| 29 |
"- retrieve: boolean, same value as should_retrieve\n"
|
| 30 |
+
"- intent: one of smalltalk, general_insurance_concept, claim_scenario, out_of_domain\n"
|
| 31 |
"- risk_level: one of low, medium, high\n\n"
|
| 32 |
"Use general_insurance_concept for educational questions about insurance terms, "
|
| 33 |
"regulation, compliance, procedures, definitions, or how insurance works. These "
|
|
|
|
| 36 |
"death, bill, repair, approval, denial, coverage, or asks whether insurance will pay. "
|
| 37 |
"These questions should retrieve.\n"
|
| 38 |
"Use smalltalk only for greetings or capability questions. These usually do not retrieve.\n"
|
| 39 |
+
"Use out_of_domain for questions that are not about insurance, insurance claims, "
|
| 40 |
+
"coverage, policies, documents, claim procedures, regulations, or this assistant's "
|
| 41 |
+
"insurance capability. Medical treatment, medicine dosage, birthday wishes, general "
|
| 42 |
+
"chitchat beyond a greeting, homework, coding, travel planning, and unrelated advice "
|
| 43 |
+
"are out_of_domain and should not retrieve.\n"
|
| 44 |
"High risk means coverage decisions, denial, settlement, legal, fraud, death, injury, "
|
| 45 |
"large loss, regulatory complaint, or money."
|
| 46 |
),
|
|
|
|
| 48 |
fallback=fallback,
|
| 49 |
)
|
| 50 |
intent = str(result.get("intent", fallback["intent"]))
|
| 51 |
+
if intent not in {"smalltalk", "general_insurance_concept", "claim_scenario", "out_of_domain"}:
|
| 52 |
intent = fallback["intent"]
|
| 53 |
should_retrieve = bool(result.get("should_retrieve", fallback["should_retrieve"]))
|
| 54 |
if intent in {"general_insurance_concept", "claim_scenario"}:
|
| 55 |
should_retrieve = True
|
| 56 |
+
if intent in {"smalltalk", "out_of_domain"}:
|
| 57 |
should_retrieve = False
|
| 58 |
risk_level = str(result.get("risk_level", fallback["risk_level"]))
|
| 59 |
if risk_level not in {"low", "medium", "high"}:
|