From a892d45bca609680ad2edf78314cb12b1ed35718 Mon Sep 17 00:00:00 2001 From: Ben Constable Date: Fri, 20 Dec 2024 14:15:43 +0000 Subject: [PATCH] Rewriter (#111) --- .../prompts/query_rewrite_agent.yaml | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/query_rewrite_agent.yaml b/text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/query_rewrite_agent.yaml index 4b1bc90..1769215 100644 --- a/text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/query_rewrite_agent.yaml +++ b/text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/query_rewrite_agent.yaml @@ -33,23 +33,28 @@ system_message: | - 1. Analyze Query Complexity: - - Identify if the query contains patterns that can be simplified - - Look for superlatives, multiple dimensions, or comparisons - - Determine if breaking down would simplify processing - - 2. Break Down Complex Queries: - - Create independent sub-queries that can be processed separately - - Ensure each sub-query is simple and focused - - Include clear combination instructions - - Preserve all necessary context in each sub-query - - 3. Handle Date References: - - Resolve relative dates using {{ current_datetime }} - - Maintain consistent YYYY-MM-DD format - - Include date context in each sub-query - - 4. Maintain Query Context: + 1. Understanding: + - Use the chat history (that is available in reverse order) to understand the context of the current question. + - If the current question is related to the previous one, rewrite it based on the general meaning of the old question and the new question. Include spelling and grammar corrections. + - If they do not relate, output the new question as is with spelling and grammar corrections. + + 2. Analyze Query Complexity: + - Identify if the query contains patterns that can be simplified + - Look for superlatives, multiple dimensions, or comparisons + - Determine if breaking down would simplify processing + + 3. Break Down Complex Queries: + - Create independent sub-queries that can be processed separately + - Ensure each sub-query is simple and focused + - Include clear combination instructions + - Preserve all necessary context in each sub-query + + 4. Handle Date References: + - Resolve relative dates using {{ current_datetime }} + - Maintain consistent YYYY-MM-DD format + - Include date context in each sub-query + + 5. Maintain Query Context: - Each sub-query should be self-contained - Include all necessary filtering conditions - Preserve business context