Spaces:
Sleeping
Sleeping
Commit ·
c014da5
1
Parent(s): a330410
fix: improve clarification context and meta-question routing
Browse files- Include clarification Q&A in combined query string so the QU layer
gets full context (app_cli.py + app_web.py)
- Route meta-questions about data availability to vector search,
not SQL (src/prompts.py)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app_cli.py +3 -2
- app_web.py +9 -2
- src/prompts.py +3 -0
app_cli.py
CHANGED
|
@@ -292,14 +292,15 @@ def main() -> None:
|
|
| 292 |
# Handle clarification
|
| 293 |
clarification_rounds = 0
|
| 294 |
while qu_result.get("action") == "clarify" and clarification_rounds < max_clarifications:
|
| 295 |
-
|
|
|
|
| 296 |
try:
|
| 297 |
clarification = input("You> ").strip()
|
| 298 |
except (EOFError, KeyboardInterrupt):
|
| 299 |
clarification = ""
|
| 300 |
if not clarification:
|
| 301 |
break
|
| 302 |
-
combined = f"{user_input}
|
| 303 |
with console.status("[bold blue]Understanding your question...[/bold blue]"):
|
| 304 |
try:
|
| 305 |
qu_result = understand_query(
|
|
|
|
| 292 |
# Handle clarification
|
| 293 |
clarification_rounds = 0
|
| 294 |
while qu_result.get("action") == "clarify" and clarification_rounds < max_clarifications:
|
| 295 |
+
clarification_question = qu_result.get('clarification_question', 'Could you be more specific?')
|
| 296 |
+
console.print(f"\n[bold yellow]Clarification needed:[/bold yellow] {clarification_question}")
|
| 297 |
try:
|
| 298 |
clarification = input("You> ").strip()
|
| 299 |
except (EOFError, KeyboardInterrupt):
|
| 300 |
clarification = ""
|
| 301 |
if not clarification:
|
| 302 |
break
|
| 303 |
+
combined = f"{user_input} (Clarification: Q: {clarification_question} A: {clarification})"
|
| 304 |
with console.status("[bold blue]Understanding your question...[/bold blue]"):
|
| 305 |
try:
|
| 306 |
qu_result = understand_query(
|
app_web.py
CHANGED
|
@@ -140,7 +140,13 @@ def render_chat():
|
|
| 140 |
pending = st.session_state.pending_clarification
|
| 141 |
if pending is not None:
|
| 142 |
# This prompt is the user's clarification answer
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
original_query = pending
|
| 145 |
st.session_state.pending_clarification = None
|
| 146 |
else:
|
|
@@ -172,8 +178,9 @@ def render_chat():
|
|
| 172 |
qu_result = {"action": "search", "search_query": combined, "display_query": combined, "original_query": original_query}
|
| 173 |
|
| 174 |
if qu_result.get("action") == "clarify" and pending is None and max_clarifications > 0:
|
| 175 |
-
# Ask clarification — store original query
|
| 176 |
st.session_state.pending_clarification = original_query
|
|
|
|
| 177 |
clarification_msg = f"**Before I search, could you clarify?** {qu_result.get('clarification_question', 'Could you be more specific?')}"
|
| 178 |
st.session_state.messages.append(
|
| 179 |
{"role": "assistant", "content": clarification_msg}
|
|
|
|
| 140 |
pending = st.session_state.pending_clarification
|
| 141 |
if pending is not None:
|
| 142 |
# This prompt is the user's clarification answer
|
| 143 |
+
# Include the clarification question for context
|
| 144 |
+
pending_question = st.session_state.get("pending_clarification_question", "")
|
| 145 |
+
if pending_question:
|
| 146 |
+
combined = f"{pending} (Clarification: Q: {pending_question} A: {prompt})"
|
| 147 |
+
else:
|
| 148 |
+
combined = f"{pending} — {prompt}"
|
| 149 |
+
st.session_state.pending_clarification_question = None
|
| 150 |
original_query = pending
|
| 151 |
st.session_state.pending_clarification = None
|
| 152 |
else:
|
|
|
|
| 178 |
qu_result = {"action": "search", "search_query": combined, "display_query": combined, "original_query": original_query}
|
| 179 |
|
| 180 |
if qu_result.get("action") == "clarify" and pending is None and max_clarifications > 0:
|
| 181 |
+
# Ask clarification — store original query and question for context
|
| 182 |
st.session_state.pending_clarification = original_query
|
| 183 |
+
st.session_state.pending_clarification_question = qu_result.get('clarification_question', 'Could you be more specific?')
|
| 184 |
clarification_msg = f"**Before I search, could you clarify?** {qu_result.get('clarification_question', 'Could you be more specific?')}"
|
| 185 |
st.session_state.messages.append(
|
| 186 |
{"role": "assistant", "content": clarification_msg}
|
src/prompts.py
CHANGED
|
@@ -175,6 +175,9 @@ When choosing a route:
|
|
| 175 |
(e.g., "PTS scores for China", "how many countries", "average GDP")
|
| 176 |
- "vector" — for conceptual, definitional, or methodology questions
|
| 177 |
(e.g., "what does PTS measure?", "explain the methodology")
|
|
|
|
|
|
|
|
|
|
| 178 |
- "both" — for mixed questions combining concepts with data
|
| 179 |
(e.g., "explain PTS methodology and show China's scores")
|
| 180 |
|
|
|
|
| 175 |
(e.g., "PTS scores for China", "how many countries", "average GDP")
|
| 176 |
- "vector" — for conceptual, definitional, or methodology questions
|
| 177 |
(e.g., "what does PTS measure?", "explain the methodology")
|
| 178 |
+
- "vector" — for meta-questions about what data is available
|
| 179 |
+
(e.g., "what datasets do you have?", "what is in the knowledge base?")
|
| 180 |
+
These are answered by codebooks and documentation, not by SQL queries.
|
| 181 |
- "both" — for mixed questions combining concepts with data
|
| 182 |
(e.g., "explain PTS methodology and show China's scores")
|
| 183 |
|