Skip to content

yanliu1111/rag_chat_app_by_deepseek_and_supabase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build RAG Chat App by Deepseek V3 πŸ‹ and Supabase ⚑

roadmap

Overview

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.

Purpose of the Project

πŸš€ Hands-on AI & Database Integration

  • Gain practical experience with modern AI models and database technologies.
  • Explore the capabilities and use cases of DeepSeek V3.

πŸ” Retrieval-Augmented Generation (RAG) Implementation

  • Develop a chat application using RAG for enhanced AI responses.
  • Instead of OpenAI's paid models, leverage Hugging Face's RAG model for free.

⚑ Tech Stack & Development

  • 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.

πŸ“„ PDF Handling & Embeddings

  • 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

Inital Technologies

  • 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

Workflow

  1. Chat app with DeepSeek V3 and Supabase
  2. Upload Document: The user uploads a document (PDF, TXT, DOCX) via the Streamlit sidebar.
  3. Process Document: The document is processed into chunks of text.
  4. Generate Embeddings: Embeddings are generated for each chunk using sentence-transformers.
  5. Save to Supabase: The chunks and their embeddings are saved to the Supabase database.
  6. Ask a Question: The user inputs a question.
  7. Retrieve Relevant Chunks: The system retrieves the most relevant chunks from Supabase based on the question's embedding.
  8. Generate Answer: The retrieved chunks and the question are sent to the DeepSeek API to generate an answer.
  9. Display Answer: The answer is displayed to the user.

Features

βœ… 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.md

Installation

To run this application, you need to have Python installed on your machine. Follow these steps to set up the project:

  1. 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
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    

Create Environment Variables (.env):

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

Running the Application

To start the Streamlit application, run the following command in your terminal:

streamlit run app.py

Supabase Setup

Create tables

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);

Demo View

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.

chat platform roadmap
supabase platform roadmap

About

πŸ‹Complete building RAG Chat App by integrating Deepseek V3 and Supabase

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages