How onlyvenkatadanush/al-powered-schema-selection-for-nl-to-sql-pipelines works
Main Components
• User Interface (UI) Layer:
• Templates Folder: Contains HTML files (index.html, 404.html) for rendering the web pages.
• Static Folder: Holds CSS (404.css, style.css) and JavaScript (script.js) for UI styling and behavior.
• API / Backend Layer:
• app.py: The main application file handling API endpoints such as database creation (/create_database) and query processing (/query).
• Endpoints for:
▪ NL query analysis,
▪ Database/table creation,
▪ Query execution,
▪ Results download (as JSON / YAML).
• AI Processing Component:
• NL Query Analysis: Uses SentenceTransformer to encode the user’s query, understands context, and then processes the query.
• Relevant Table Selection: Implements a select_relevant_tables() function that leverages cosine similarity to filter the tables in the schema.
• NL-to-SQL Conversion Preparation: Function (query_gemini()) that packages only the relevant tables and schema details for conversion.
• Data Storage and Schema Management:
• Database Files (newr.db) and JSON/YAML schema files (database_data.json, query_results.json, query_results.yaml).
• CSV File (table_structure.csv) which might be used to either validate or display table structures.
• Uploads Folder: Stores additional or updated schema files (uploads/database_data.json, uploads/newr_schema.json).
Analyzing Relationships and Interactions
• The User Interface sends a NL query via HTTP requests (using form submissions or AJAX calls).
• The API layer (app.py) receives the query and triggers the AI Processing Component.
• First, the NL query is processed by SentenceTransformer to extract semantic meaning.
• The schema is loaded (from JSON/YAML files and the CSV) and then analyzed using cosine similarity to identify the relevant tables.
• The filtered result is then forwarded (possibly through query_gemini()) to the NL-to-SQL conversion engine for further processing.
• Additionally, there’s an endpoint for creating or updating the database; this involves reading from schema files and populating newr.db, if needed.
• The system sends back responses (query results) in JSON/YAML format to the UI or the client requesting the data.
Highlighting Architectural Patterns and Design Principles
• Layered Architecture:
• Separation between the frontend (Templates and Static) and backend logic (app.py).
• Clear division of concerns, e.g., UI rendering versus business logic/API.
• Modular Design:
• The project segments different functionalities (query analysis, table selection, database management) into distinct functions or modules within the backend.
• API-Driven Interaction:
• Use of clearly defined HTTP endpoints for actions like querying, database creation, and result download.
• Error Handling and Input Validation:
• Robust checks for scenarios such as missing API keys, erroneous files, or invalid queries, as stated in the README.