- Backend Structure
- Installation and Setup
- Environment Variables Setup
- Running the Application
- Using Docker
- Troubleshooting
.
├── __pycache__
├── .theflow
├── api
├── data
├── logs
├── src
├── venv
├── .env
├── .env.example
├── .gitignore
├── app_fastapi.py
├── docker-compose.yaml
├── README.md
├── requirements.txt
api/: Contains API logic for FastAPI.data/: Stores data, including Qdrant storage.logs/: Stores log files.src/: Additional source code.venv/: Virtual environment containing dependencies..env: Environment variables file..gitignore: Lists files and directories to ignore in Git.app_fastapi.py: Main FastAPI application.docker-compose.yaml: Docker Compose configuration.requirements.txt: Backend dependencies.
-
Clone the repository
git clone https://github.com/buithanhdam/rag-app-agent-llm.git cd rag-app-agent-llm/backend -
Set up the virtual environment
- Unix/macOS:
python3 -m venv venv source venv/bin/activate - Windows:
python -m venv venv .\venv\Scripts\activate
- Unix/macOS:
-
Install dependencies
- Backend (FastAPI):
pip install -r requirements.txt
- Backend (FastAPI):
-
Copy
.env.exampleto.envcp .env.example .env
-
Configure the environment variables
GOOGLE_API_KEY=<your_google_api_key> OPENAI_API_KEY=<your_openai_api_key> ANTHROPIC_API_KEY=<your_anthropic_api_key> BACKEND_API_URL=http://localhost:8000 QDRANT_URL=http://localhost:6333 MYSQL_USER=your_mysql_user MYSQL_PASSWORD=your_mysql_password MYSQL_HOST=your_mysql_host MYSQL_PORT=your_mysql_port MYSQL_DB=your_mysql_db MYSQL_ROOT_PASSWORD=root_password AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_REGION_NAME= AWS_STORAGE_TYPE= AWS_ENDPOINT_URL=
uvicorn app_fastapi:app --host 0.0.0.0 --port 8000 --reload- Access API at:
http://127.0.0.1:8000
-
Ensure Docker is running.
-
Build and start containers:
docker-compose build docker-compose up
- fastapi: Exposes port
8000. - qdrant: Exposes ports
6333,6334. - mysql: Exposes port
3306.
docker exec -it your-container-name bash
mysql -u root -p-
Enter
root password(configured in.envordocker-compose.yml). -
Run the following SQL queries:
CREATE USER 'user'@'%' IDENTIFIED BY '1'; GRANT ALL PRIVILEGES ON ragagent.* TO 'user'@'%'; FLUSH PRIVILEGES;
CREATE DATABASE ragagent;
- FastAPI:
http://localhost:8000
docker-compose down- Docker network:
rag-app-network(bridge). - FastAPI service uses
./Dockerfile.backend.
- Ensure
.envis correctly configured. - If there are changes in Docker, run:
docker-compose up --build
- Verify that required ports (8000, 6333) are not in use.
This documentation provides all necessary steps to set up, run, and manage the project efficiently.