Vanshcc commited on
Commit
7562827
·
verified ·
1 Parent(s): de4b359

Upload 7 files

Browse files
router.py CHANGED
@@ -43,10 +43,12 @@ USER QUERY: {query}
43
 
44
  Determine if this query needs:
45
  1. RAG - Semantic search through text content (searching for meanings, concepts, descriptions)
46
- 2. SQL - Structured database query (counting, filtering, aggregating, specific lookups)
47
  3. HYBRID - Both semantic search and structured query
48
  4. GENERAL - General conversation not requiring database access
49
 
 
 
50
  Respond in this exact format:
51
  TYPE: [RAG|SQL|HYBRID|GENERAL]
52
  CONFIDENCE: [0.0-1.0]
@@ -122,7 +124,11 @@ REASONING: [brief explanation]"""
122
  'from new york', 'from chicago', 'from los angeles',
123
  # Specific lookups
124
  'price of', 'cost of', 'stock of', 'quantity',
125
- 'where', 'which', 'who'
 
 
 
 
126
  ]
127
 
128
  # RAG keywords - for semantic/conceptual questions
 
43
 
44
  Determine if this query needs:
45
  1. RAG - Semantic search through text content (searching for meanings, concepts, descriptions)
46
+ 2. SQL - Structured database query (counting, filtering, aggregating, specific lookups, OR pagination requests like "show more", "show other", "next results", "remaining items")
47
  3. HYBRID - Both semantic search and structured query
48
  4. GENERAL - General conversation not requiring database access
49
 
50
+ IMPORTANT: If the user asks to "show more", "show other", "see remaining", "next results", or similar - this is a PAGINATION request and should be routed to SQL, NOT GENERAL.
51
+
52
  Respond in this exact format:
53
  TYPE: [RAG|SQL|HYBRID|GENERAL]
54
  CONFIDENCE: [0.0-1.0]
 
124
  'from new york', 'from chicago', 'from los angeles',
125
  # Specific lookups
126
  'price of', 'cost of', 'stock of', 'quantity',
127
+ 'where', 'which', 'who',
128
+ # Pagination / follow-up requests
129
+ 'show more', 'show other', 'show rest', 'show remaining',
130
+ 'more results', 'next', 'remaining', 'rest of', 'other also',
131
+ 'continue', 'keep going', 'see more', 'view more'
132
  ]
133
 
134
  # RAG keywords - for semantic/conceptual questions
sql/__pycache__/generator.cpython-311.pyc CHANGED
Binary files a/sql/__pycache__/generator.cpython-311.pyc and b/sql/__pycache__/generator.cpython-311.pyc differ
 
sql/generator.py CHANGED
@@ -70,6 +70,10 @@ RULES:
70
  - Use `OR` to combine multiple column checks.
71
  6. DATA AWARENESS: In footwear databases, specific types like 'Formal', 'Casual', or 'Sports' often appear in `sub_category` OR `category`. Check both if available.
72
  7. Return ONLY the SQL query, no explanations.
 
 
 
 
73
 
74
  {dialect_hints}
75
 
@@ -131,13 +135,13 @@ Generate a single {dialect} SELECT query to answer the user's question."""
131
  def _extract_sql(self, response: str) -> str:
132
  """Extract SQL query from LLM response."""
133
  # Look for SQL in code blocks
134
- code_block = re.search(r'```(?:sql)?\\s*(.*?)```', response, re.DOTALL | re.IGNORECASE)
135
  if code_block:
136
  return code_block.group(1).strip()
137
 
138
  # Look for SELECT statement
139
  select_match = re.search(
140
- r'(SELECT\\s+.+?(?:;|$))',
141
  response,
142
  re.DOTALL | re.IGNORECASE
143
  )
 
70
  - Use `OR` to combine multiple column checks.
71
  6. DATA AWARENESS: In footwear databases, specific types like 'Formal', 'Casual', or 'Sports' often appear in `sub_category` OR `category`. Check both if available.
72
  7. Return ONLY the SQL query, no explanations.
73
+ 8. PAGINATION: If the user asks to "show more", "show other", "see remaining", or similar follow-up:
74
+ - Look at the previous conversation for the original query conditions.
75
+ - Use LIMIT with OFFSET to get the next set of results (e.g., LIMIT 10 OFFSET 10 for the second page).
76
+ - Keep the same WHERE conditions from the previous query.
77
 
78
  {dialect_hints}
79
 
 
135
  def _extract_sql(self, response: str) -> str:
136
  """Extract SQL query from LLM response."""
137
  # Look for SQL in code blocks
138
+ code_block = re.search(r'```(?:sql)?\s*(.*?)```', response, re.DOTALL | re.IGNORECASE)
139
  if code_block:
140
  return code_block.group(1).strip()
141
 
142
  # Look for SELECT statement
143
  select_match = re.search(
144
+ r'(SELECT\s+.+?(?:;|$))',
145
  response,
146
  re.DOTALL | re.IGNORECASE
147
  )