A RAG (Retrieval-Augmented Generation) powered chat application that answers questions based on ingested documents using OpenAI embeddings and vector search.
BobChat is a full-stack application that combines:
- FastAPI backend with RAG processing
- React frontend for chat interface
- PostgreSQL with pgvector for vector storage and similarity search
- OpenAI API for embeddings and chat completions
When you ask a question, the system retrieves relevant document chunks, includes conversation history, and generates contextual responses using an LLM.
- Chat interface with real-time message polling
- RAG-powered responses based on ingested documents
- Conversation history awareness (last 5 messages)
- File-based chat persistence (
chat.txt) - Clear chat functionality
- Docker Compose setup for easy deployment
- Backend: FastAPI application with
/messagesendpoints - Frontend: React app with polling mechanism
- Database: PostgreSQL with pgvector extension for vector similarity search
- Storage: Chat messages stored in
chat.txt, document chunks in PostgreSQL
- Docker and Docker Compose
- OpenAI API key
-
Clone the repository (if applicable)
-
Configure environment variables:
cd back cp env.example .envEdit
.envand set your OpenAI API key:OPENAI_KEY=your_openai_api_key_here -
Start the services:
cd back docker-compose up --buildThis will start:
- PostgreSQL database (port 5432)
- FastAPI backend (port 8000)
- React frontend (port 3000)
-
Ingest documents (first time setup):
docker-compose exec chat-backend python cli.py ingestThis processes documents from
back/data/files/and stores them as vector embeddings.
-
Access the frontend: Open
http://localhost:3000in your browser -
Start chatting: Type a message and press Enter or click Send
-
View responses: The assistant response will appear automatically after processing (typically a few seconds)
-
Clear chat: Click the "Clear" button to delete all messages and start fresh
GET /messages- Retrieve all chat messagesPOST /messages- Create a new user message (triggers RAG processing in background)DELETE /messages- Clear all messages
- User sends a message via the frontend
- Backend immediately returns 201 response
- RAG processor runs in background thread:
- Retrieves relevant document chunks using vector similarity search
- Includes last 5 messages as conversation history
- Generates response using OpenAI with context
- Adds assistant message to chat
- Frontend polls every 5 seconds to fetch new messages
- Assistant response appears in the UI
bobchat/
├── back/ # FastAPI backend
│ ├── app.py # Main FastAPI application
│ ├── rag.py # RAG processor
│ ├── llm.py # OpenAI wrapper
│ ├── data/
│ │ ├── chat.py # Chat message storage
│ │ ├── storage.py # Database models
│ │ └── files/ # Documents to ingest
│ ├── templates/ # Jinja2 templates
│ └── docker-compose.yml
└── front/ # React frontend
└── src/
└── App.js # Main chat component
The backend uses hot-reload via uvicorn, and the frontend uses React's development server. Changes to code will automatically reload.
To stop all services:
docker-compose downTo view logs:
docker-compose logs -f