Your own AI Agent to talk with your documents.
MyAgent is a complete RAG (Retrieval-Augmented Generation) system that allows you to upload PDF documents and interact with them using natural language queries. The system features a modern web interface built with Next.js and a robust FastAPI backend powered by Google's Gemini AI model and ChromaDB for vector storage.
- Modern Web Interface: Beautiful, responsive UI built with Next.js and Tailwind CSS
- PDF Document Processing: Upload and process PDF files with automatic text extraction
- Intelligent Chunking: Advanced text splitting for optimal document understanding
- Vector-Based Retrieval: ChromaDB-powered semantic search across documents
- AI-Powered Q&A: Google Gemini 2.0 Flash for intelligent responses
- Real-time Chat: Interactive chat interface with streaming responses
- RESTful API: Complete API for integration with other applications
- Docker Support: Containerized deployment for easy setup and scaling
- Next.js 15 - React framework with App Router
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first CSS framework
- React Hooks - State management and side effects
- FastAPI - Modern Python web framework
- Google Gemini AI - Advanced language model
- ChromaDB - Vector database for embeddings
- LangChain - LLM application framework
- PyPDF - PDF text extraction
- Sentence Transformers - Text embeddings
- Clone the repository:
git clone <repository-url>
cd MyAgent
- Set up your API key:
echo "GOOGLE_API_KEY=your_google_api_key_here" > backend/.env
- Run with Docker Compose:
docker-compose up --build
- Access the application:
- Web Interface: http://localhost:3000
- API Documentation: http://localhost:8000/docs
- Backend API: http://localhost:8000
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
cd backend
pip install -r requirements.txt
- Configure environment:
echo "GOOGLE_API_KEY=your_google_api_key_here" > .env
- Start the server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- Install dependencies:
cd frontend
npm install
- Start development server:
npm run dev
- Access the application: http://localhost:3000
- Click "Selecionar Arquivo PDF" to choose a PDF file
- Click "Fazer Upload e Indexar" to process and index the document
- The system will automatically extract text, create chunks, and generate embeddings
- Use the chat interface to ask questions about your uploaded documents
- The AI will search through your documents and provide relevant answers
- Questions are processed in real-time with streaming responses
- Use the RESTful API endpoints for programmatic access
- Full API documentation available at
/docs
- Support for both file uploads and chat queries
GET /api/v1/health
POST /api/v1/upload
Content-Type: multipart/form-data
Body: file (PDF)
POST /api/v1/chat
Content-Type: application/json
Body: {"question": "your question here"}
POST /api/v1/query
Content-Type: application/json
Body: {"question": "your question here"}
Health Check:
curl -X GET "http://localhost:8000/api/v1/health"
Upload Document:
curl -X POST "http://localhost:8000/api/v1/upload" \
-H "Content-Type: multipart/form-data" \
-F "[email protected]"
Ask Question:
curl -X POST "http://localhost:8000/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{"question": "What is the main topic of the document?"}'
import requests
# Upload a document
with open('document.pdf', 'rb') as f:
files = {'file': f}
response = requests.post('http://localhost:8000/api/v1/upload', files=files)
print(response.json())
# Ask a question
question_data = {"question": "What are the key points in the document?"}
response = requests.post('http://localhost:8000/api/v1/chat', json=question_data)
print(response.json())
MyAgent/
├── frontend/ # Next.js web application
│ ├── app/
│ │ ├── components/ # React components
│ │ │ ├── Chat.tsx # Chat interface
│ │ │ └── FileUpload.tsx # File upload component
│ │ ├── services/ # API services
│ │ │ └── api.ts # API client functions
│ │ ├── globals.css # Global styles
│ │ ├── layout.tsx # Root layout
│ │ └── page.tsx # Main page
│ ├── public/ # Static assets
│ ├── package.json # Node.js dependencies
│ ├── Dockerfile # Frontend container
│ └── next.config.ts # Next.js configuration
├── backend/ # FastAPI backend
│ ├── app/
│ │ ├── api/
│ │ │ └── routes.py # API endpoints
│ │ ├── core/
│ │ │ └── config.py # Configuration
│ │ ├── schemas/
│ │ │ └── chat.py # Pydantic models
│ │ ├── services/
│ │ │ └── rag_service.py # RAG implementation
│ │ ├── storage/
│ │ │ └── vector_store.py # Vector database
│ │ └── main.py # FastAPI application
│ ├── data/ # Uploaded documents
│ ├── chroma_db/ # Vector database storage
│ ├── requirements.txt # Python dependencies
│ └── Dockerfile # Backend container
├── docker-compose.yml # Multi-container orchestration
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
└── README.md # This file
- Model: Gemini 2.0 Flash
- Chunk Size: 1000 characters
- Chunk Overlap: 200 characters
- Retrieval Results: 3 most relevant chunks
- Backend Port: 8000
- Frontend Port: 3000
- API Base URL: http://localhost:8000/api/v1
# Build and start all services
docker-compose up --build
# Run in background
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# Rebuild specific service
docker-compose build backend
docker-compose build frontend
# Rebuild and restart with latest changes
docker-compose up --build --force-recreate
# View service status
docker-compose ps
# Execute commands in running containers
docker-compose exec backend python -c "print('Hello from backend')"
docker-compose exec frontend npm run lint
-
Google API Key Error
- Ensure your
.env
file contains a validGOOGLE_API_KEY
- Verify the API key has access to Gemini AI
- Ensure your
-
Port Conflicts
- Check if ports 3000 or 8000 are already in use
- Modify ports in docker-compose.yml if needed
-
Docker Build Issues
- Ensure Docker and Docker Compose are properly installed
- Clear Docker cache:
docker system prune -a
-
Frontend Not Loading
- Verify backend API is running and accessible
- Check browser console for CORS errors
-
PDF Processing Errors
- Ensure PDF files are not corrupted or password-protected
- Check file size limits
-
Import Errors
- Reinstall dependencies:
pip install -r requirements.txt
- Clear Python cache:
find . -name "*.pyc" -delete
- Reinstall dependencies:
- Large Documents: Consider splitting very large PDFs before upload
- Memory Usage: Monitor container resource usage with
docker stats
- Response Time: Adjust chunk size and overlap for better performance
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the troubleshooting section above
- Review the API documentation at
/docs
- Open an issue on GitHub