Skip to content

Conversation

@kartiktongaria
Copy link

Step 1:
I developed a SQLite database using Python and created an Employee table containing essential fields like name, age, city, gender, total experience, and blood group.

Step 2:
I designed a CSV file (employee_questions.csv) where I documented natural language questions, their corresponding SQL queries, and short explanations which is also known as few short prompting.
This file serves as few-shot examples to help the model understand and generate correct queries.

Step 3:
I converted the questions and queries into embeddings using OpenAI's embedding model and stored them in FAISS — a high-speed vector database — for efficient retrieval.

Step 4:
Using LangChain, I implemented:

A FAISS retriever to search similar examples based on user input.

A Conversational Retrieval Chain that connects the retriever to a language model (LLM).

Step 5:
I integrated OpenAI GPT-3.5-turbo as the main language model.
However, the architecture is flexible and can easily switch to other models like Gemini, Llama, or any open-source LLM.

Step 6:
I built a Flask-based API where:

The user submits a question.

FAISS retrieves related examples.

A final prompt is crafted combining the database schema, examples, and the user’s question.

The model generates the corresponding SQL query.

The SQL query is cleaned and validated.

The query is executed against the employee.db database.

The API returns both the generated SQL query and its results.

Step 7:
In the future, I plan to enhance the system by:

Supporting multi-table joins and data modification operations (INSERT/UPDATE/DELETE).

Integrating conversation history, allowing the bot to understand the flow of previous interactions for better and more connected answers.

Replacing the LLM with open-source models to reduce costs and improve control.

✅ To check the chatbot outputs, you can refer to the result_img folder available in the repository, where I have attached screenshots of the working results.

@kartiktongaria
Copy link
Author

Hello @ShlokRana,

I have developed a Text-to-SQL chatbot, and you can refer to the README file where I have explained everything clearly — including the complete flow, architecture, and setup details.

I am genuinely excited about the opportunity to contribute to this project and work alongside you.
If you face any issues or need any clarifications regarding the code, I will be more than happy to address them and make corrections as quickly as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant