This application implements a Retrieval-Augmented Generation (RAG) system that connects to a SQL Server database and provides answers based on the data stored in it.
- Python 3.8 or higher
- SQL Server
- OpenAI API key
- ODBC Driver for SQL Server
- Clone this repository
- Install the required dependencies:
pip install -r requirements.txt
- Install the SQL Server ODBC driver for your operating system
- Copy the
.env.examplefile to.env - Update the
.envfile with your configuration:- Database connection details
- OpenAI API key
- Vector store path
- Update the
table_namevariable inapp.pywith your target table name - Run the application:
python app.py
The application will:
- Connect to your SQL Server database
- Create a vector store from your table data
- Allow you to query the data using natural language
- The application connects to your SQL Server database
- It fetches data from the specified table
- The data is converted into text chunks and embedded using sentence transformers
- A vector store is created using Chroma
- When you ask a question, the system:
- Retrieves relevant context from the vector store
- Uses OpenAI's GPT model to generate an answer based on the context
- Returns the answer along with the source documents
You can customize the following aspects:
- Embedding model by changing the
model_namein theHuggingFaceEmbeddingsinitialization - Chunk size and overlap in the
RecursiveCharacterTextSplitter - Prompt template in the
get_qa_chainmethod - LLM model and parameters in the
ChatOpenAIinitialization
MIT