Build RAG (Retrieval-Augmented Generation) Chat App" by integrating Deepseek V3 and Supabase, built base on a simple Streamlit application that provides an interactive user interface with a sidebar for navigation and content display. Separate projects with unique chats.
- Gain practical experience with modern AI models and database technologies.
- Explore the capabilities and use cases of DeepSeek V3.
- Develop a chat application using RAG for enhanced AI responses.
- Instead of OpenAI's paid models, leverage Hugging Face's RAG model for free.
-
Frameworks & Tools:
- Streamlit β Build and deploy the app.
- DeepSeek V3 β AI-powered model integration.
- Supabase β Store and retrieve embeddings efficiently.
-
Python Practice:
- Work with advanced Python features.
- Implement unit testing towards the end.
-
Extract text from PDFs using PyMuPDF (extract_text_from_pdf function).
-
For free embedding generation:
- Sentence Transformers (sentence-transformers library).
pip install sentence-transformers
- Hugging Face Transformers for pre-trained models.
pip install transformers
- Python 3.10
- Packages
pip install streamlit requests python-dotenv supabase - Read DeepSeek API documentation for python
https://api-docs.deepseek.com/api/create-chat-completion
- Chat app with DeepSeek V3 and Supabase
- Upload Document: The user uploads a document (PDF, TXT, DOCX) via the Streamlit sidebar.
- Process Document: The document is processed into chunks of text.
- Generate Embeddings: Embeddings are generated for each chunk using sentence-transformers.
- Save to Supabase: The chunks and their embeddings are saved to the Supabase database.
- Ask a Question: The user inputs a question.
- Retrieve Relevant Chunks: The system retrieves the most relevant chunks from Supabase based on the question's embedding.
- Generate Answer: The retrieved chunks and the question are sent to the DeepSeek API to generate an answer.
- Display Answer: The answer is displayed to the user.
β
Streamlit server setup
β
DeepSeek V3 API integration
β
Main chat area for displaying information from DeepSeek's work π
β
Sidebar for navigation
β
Display chat history in the main chat area
β
Supabase storage setup and API integration, schema design
β
Save chat history to Supabase, by different user and projects
β
Use the PyMuPDF library to extract text from PDF files.
β
Streamlit UI for uploading files
β
Embedding uploaded files and chunks to supabase
β
RAG model integration
β
Ask questions and get answers from RAG model
β
Retrieve chat history from Supabase
Build-RAG-Chat-App/
βββ .env
βββ app.py
βββ document_processor.py
βββ requirements.txt
βββ .gitignore
βββ README.mdTo run this application, you need to have Python installed on your machine. Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/yanliu1111/rag_chat_app_by_deepseek_and_supabase.git cd rag_chat_app_by_deepseek_and_supabase -
Install the required dependencies:
pip install -r requirements.txt
DEEPSEEK_API_KEY=your_deepseek_api_key
SUPABASE_URL=your_supabase_url
SUPABASE_API_KEY=your_supabase_api_key
YOUR_SITE_URL=http://localhost:8501
YOUR_SITE_NAME=your_site_name
To start the Streamlit application, run the following command in your terminal:
streamlit run app.py
CREATE TABLE IF NOT EXISTS messages (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
role TEXT NOT NULL,
content TEXT NOT NULL,
project TEXT NOT NULL,
timestamp TIMESTAMPTZ DEFAULT timezone('utc'::text, now()) NOT NULL,
embedding JSONB -- Add this line
);
ALTER TABLE messages ENABLE ROW LEVEL SECURITY;
-- Create policy
CREATE POLICY "Allow all operations"
ON messages FOR ALL
USING (true)
WITH CHECK (true);Upload a PDF file containing a story I generated, recreated from Turning Red πΌπΎ. The story includes unique names, family members, and their hobbies.
After uploading the file, you can ask questions based on the PDF and receive accurate answers. All embeddings, questions, answers, and timestamps are saved in Supabase.


