forge
Explore
Log in

Don't you dare go Hollow

Answer a greeting instead of abstaining for missing sources

Browse files at this commit

a8a0bdf6494aabc3d0b6750c4cc559004ee0b8d8Ahmet Kaan GümüşParent: a4b3874
  • fix
    • answer a greeting instead of abstaining for missing sources
Show full message
🐛 fix: answer a greeting instead of abstaining for missing sources

selam and merhaba hit retrieval and came back insufficient_data. The
SOHBET classifier already existed and was unused. chat() returns a short
greeting before routing or retrieval, including the multi-corpus path.
src/service/handler.pymodified+17 -0
@@ -14,6 +14,7 @@ from ..observability.trace import RequestTrace, redact, write_trace
1414 from ..providers.resilience import LlmUnavailable
1515 from ..guard.roles import RoleContext, Role, can_access
1616 from ..guard.tenant import TenantError, normalize_school
17+from ..understand import Intent, analyze
1718
1819
1920 def scope_pairs(scope) -> list:
@@ -126,6 +127,17 @@ SCOPE_TEXT = ("Seçtiğin bölüm bir seferde özetlenemeyecek kadar geniş. "
126127 "Daha dar bir aralık seçer misin?")
127128 TENANT_TEXT = ("Bu istek bir okula bağlanamadı; kaynaklar açılamıyor. Lütfen "
128129 "tekrar dene ya da öğretmenine haber ver.")
130+GREETING_TEXT = "Merhaba! Dersle ilgili bir sorun varsa sorabilirsin."
131+
132+
133+def sohbet_reply(query: str) -> dict | None:
134+ """A greeting is not a missing source. None means the caller should retrieve."""
135+ analysis = analyze(query)
136+ if analysis.is_out_of_scope and analysis.intent == Intent.SOHBET:
137+ return {"text": GREETING_TEXT, "abstained": False, "reason": "",
138+ "citations": [], "used_source_ids": [],
139+ "invalid_citations": [], "cost_usd": 0.0, "cache_hit": False}
140+ return None
129141
130142
131143 def _unknown_school(kind: str = "chat") -> dict:
@@ -215,6 +227,11 @@ class RagService:
215227 if not query:
216228 return {"text": "", "abstained": True, "reason": "empty_query",
217229 "citations": [], "used_source_ids": [], "cost_usd": 0.0, "cache_hit": False}
230+ # Smalltalk is not a missing source. Answer it here so it never reaches
231+ # retrieval or the insufficient_data gate.
232+ hit = sohbet_reply(query)
233+ if hit is not None:
234+ return hit
218235 # KİRACILIK: okul istekten gelir ve burada doğrulanır. Geçersiz/ayrılmış
219236 # bir değer 500'e değil TİPLİ bir redde düşmelidir (bkz. guard/tenant.py);
220237 # doğrulanmış değer aşağıya (retrieval + cache anahtarı) geçer.
src/service/multi.pymodified+7 -0
@@ -415,6 +415,13 @@ class MultiCorpusService:
415415 return {**ortak, "items": [], "span_ids": [], "pages": []}
416416
417417 def chat(self, req: dict) -> dict:
418+ # Same gate as RagService.chat. Routing first would turn "selam" into
419+ # no_corpus when the asker has no pair, which is the admin study bug.
420+ from .handler import sohbet_reply
421+ query = (req.get("query") or "").strip()
422+ hit = sohbet_reply(query) if query else None
423+ if hit is not None:
424+ return hit
418425 svc, sebep = self._route(req)
419426 return svc.chat(req) if svc is not None else self._refused(sebep, "chat")
420427
tests/unit/test_multi_corpus_service.pymodified+11 -0
@@ -70,6 +70,17 @@ def _svc(specs=("10/biyoloji", "10/kimya", "10/fizik"), gecikme=0.0,
7070 return s
7171
7272
73+
74+class GreetingRouteTests(unittest.TestCase):
75+ def test_greeting_is_not_a_missing_corpus(self):
76+ s = _svc()
77+ out = s.chat({"query": "selam", "school": _OKUL,
78+ "role": {"role": "admin"}, "scope": []})
79+ self.assertFalse(out["abstained"])
80+ self.assertNotEqual(out["reason"], "no_corpus")
81+ self.assertNotIn("bulunamadı", out["text"])
82+ self.assertEqual(s.registry.keys(), [])
83+
7384 def _bekle(s, sinif, ders, timeout=5.0):
7485 """Arka plan korpus kurulumunun bitmesini bekler.
7586
tests/unit/test_service.pymodified+26 -0
@@ -77,6 +77,32 @@ class ChatTests(unittest.TestCase):
7777 self.assertEqual(out["reason"], "empty_query")
7878 self.assertEqual(g.last_role, "UNSET") # generator ÇAĞRILMADI
7979
80+ def test_greeting_is_not_insufficient_data(self):
81+ g = _GenStub(_ANS)
82+ svc = RagService(g)
83+ for q in ("selam", "merhaba"):
84+ out = svc.chat({"query": q})
85+ self.assertNotEqual(out["reason"], "insufficient_data", q)
86+ self.assertFalse(out["abstained"], q)
87+ self.assertEqual(out["reason"], "", q)
88+ self.assertEqual(out["citations"], [], q)
89+ self.assertEqual(out["cost_usd"], 0.0, q)
90+ self.assertFalse(out["cache_hit"], q)
91+ self.assertTrue(out["text"].strip(), q)
92+ self.assertNotIn("bulunamadı", out["text"])
93+ self.assertEqual(g.last_role, "UNSET")
94+
95+ def test_non_greeting_question_still_calls_generator(self):
96+ g = _GenStub(_ANS)
97+ out = RagService(g).chat({
98+ "query": "Fotosentez nedir?",
99+ "role": {"role": "student", "sinif": "12", "ders_list": ["biyoloji"]},
100+ })
101+ self.assertNotEqual(g.last_role, "UNSET")
102+ self.assertEqual(g.last_role.role, Role.STUDENT)
103+ self.assertEqual(out["text"], "Cevap [1].")
104+ self.assertFalse(out["abstained"])
105+
80106 def test_invalid_role_becomes_none(self):
81107 g = _GenStub(_ANS)
82108 RagService(g).chat({"query": "q", "role": {"role": "hacker"}})