Canner / WrenAI

šŸš€ An open-source SQL AI (Text-to-SQL) Agent that empowers data, product teams to chat with their data. šŸ¤˜
https://getwren.ai/oss
GNU Affero General Public License v3.0
2.04k stars 211 forks source link

feat(wren-ai-service): add historical queries in view chunk for follow-up question #666

Closed paopa closed 2 months ago

paopa commented 2 months ago

Description

This PR enhances the view chunking process to include historical queries, improving the context for follow-up questions in the AI service.

Key Changes

  1. Renamed ViewConverter to ViewChunker for clarity.
  2. Updated ViewChunker to include historical queries in the content:
    • Now combines historical_queries with the current question.
    • Example JSON configuration:
      {
       "views": [
           {
               "name": "book",
               "statement": "SELECT * FROM book where created_at = 2020",
               "properties": {
                   "question": "in 2020",
                   "summary": "Retrieve the number of books in 2020",
                   "viewId": "fake-id-1",
                   "historical_queries": [
                       "Retrieve the number of books"
                   ]
               }
           }
       ]
      }
  3. Modified AskService to use a combined query for retrieval:
    • Includes history summary and current query when available.
  4. Refactored Indexing class to use a component dictionary for better organization.
  5. Updated tests to reflect these changes and added new tests for historical queries.

Impact

These changes will improve the AI's ability to understand and respond to follow-up questions by providing more context from previous interactions. This should lead to more accurate and relevant responses to retrieve the saved view.

Screenshots