Spaces:
Configuration error
FastAPI RAG Chatbot Backend
This project implements a FastAPI backend for a Retrieval-Augmented Generation (RAG) chatbot. It integrates with OpenAI for chat completions and embeddings, Neon Serverless Postgres for persistent data, and Qdrant Cloud for vector storage.
Project Structure
backend/
βββ app/
β βββ __init__.py
β βββ main.py
β βββ config.py
β βββ database.py
β βββ qdrant_client.py
β βββ models/
β β βββ __init__.py
β β βββ user.py
β β βββ chat.py
β βββ schemas/
β β βββ __init__.py
β β βββ chat.py
β βββ routes/
β β βββ __init__.py
β β βββ chat.py
β β βββ health.py
β βββ services/
β βββ __init__.py
β βββ rag_service.py
β βββ embeddings_service.py
β βββ openai_service.py
βββ scripts/
β βββ ingest_content.py
βββ .env.example
βββ requirements.txt
βββ README.md
βββ .gitignore
Setup Instructions
Clone the repository:
git clone <repository-url> cd roboticNavigate to the backend directory:
cd backendSet up the Python virtual environment and install dependencies:
On Windows, run:
.\setup.batOn Linux/macOS, run:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txtConfigure Environment Variables:
Create a
.envfile in thebackend/directory by copying.env.exampleand filling in your credentials:copy .env.example .env # or for Linux/macOS cp .env.example .envEdit the
.envfile with your actual API keys and database URLs:OPENAI_API_KEY=your_openai_api_key_here NEON_DATABASE_URL=your_neon_postgres_connection_string_here QDRANT_URL=your_qdrant_cluster_url_here QDRANT_API_KEY=your_qdrant_api_key_here
Running the Application
Activate your virtual environment:
On Windows:
.\venv\Scripts\activateOn Linux/macOS:
source venv/bin/activateStart the FastAPI server:
On Windows, run:
.\run.batOn Linux/macOS, run:
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadThe API will be accessible at
http://localhost:8000.
API Endpoints
(Note: Detailed API documentation will be available at /docs once the server is running)
Health Check
- GET
/health- Returns the health status of the backend and its integrated services.
Chatbot Interaction
- POST
/chat/Description: Sends a user query to the RAG chatbot and receives a generated response.
Request Body Example:
{ "query": "What is the main topic of the book?" }Response Body Example:
{ "response": "The main topic of the book is ..." }
Content Ingestion Script
scripts/ingest_content.pyThis script is responsible for reading MDX files from
../physical-ai-humanoid-robotics/docs/, chunking the text, generating OpenAI embeddings, and storing them in Qdrant.Usage:
python scripts/ingest_content.py