This project is a web application that allows users to upload documents and perform question-answering (Q&A) using Retrieval-Augmented Generation (RAG). The application is built using Django (backend), React (frontend), Postgres with pgvector (vector database), Docker, and the OpenAI API for embeddings and LLM.
- Document Upload: Upload PDF documents. The application extracts text and splits it into chunks.
- Embedding Generation: Generates embeddings for text chunks using OpenAI's
text-embedding-ada-002
. - Vector Storage: Stores embeddings in Postgres using the pgvector extension for similarity search.
- Query-based Retrieval: Searches for relevant text chunks based on a user query and augments the query for LLM.
- Chatbot Interface: A React-based chatbot interface for asking questions and receiving responses.
- Containerized: Uses Docker and docker-compose for containerization.
- Docker
- Docker Compose
- OpenAI API Key
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Set up environment variables: Create a
.env
file in the root directory and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
-
Build and start the containers:
docker-compose up --build
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/api/
- Open the application in your browser at http://localhost:3000
- Use the upload form to add PDF documents
- Once documents are uploaded, use the chatbot interface to ask questions
- The system will retrieve relevant context from the uploaded documents and generate answers
project/
├── backend/
│ ├── Dockerfile
│ ├── requirements.txt
│ ├── init-db/
│ │ └── init.sql
│ ├── manage.py
│ ├── project/
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ └── app/
│ ├── models.py
│ ├── urls.py
│ └── views.py
├── frontend/
│ ├── Dockerfile
│ ├── package.json
│ └── src/
│ ├── App.js
│ ├── index.js
│ └── components/
│ ├── FileUpload.js
│ └── Chatbot.js
├── docker-compose.yml
└── README.md
- Ensure you have a valid OpenAI API key
- The system uses the following OpenAI models:
text-embedding-ada-002
for generating embeddingsgpt-3.5-turbo
for generating answers
- The pgvector extension is automatically enabled in the Postgres database
- The application uses a simple chunking strategy based on word count
- Similarity search threshold can be adjusted in the backend code
- Backend development server runs on port 8000
- Frontend development server runs on port 3000
- Postgres database runs on port 5432
This is a development setup. For production:
- Use proper authentication
- Implement rate limiting
- Set up HTTPS
- Use secure database credentials
- Implement proper error handling
- Add logging
- Add input validation
- Add CSRF protection