An API project for Retrieval-Augmented Generation (RAG) using OpenAI's models. This service enables document upload, storage, and intelligent querying using Large Language Models (LLMs).
- Document upload and storage
- Text extraction and chunking
- Vector embeddings generation using OpenAI
- Semantic search capabilities
- Question answering with context
- Document management
- FastAPI: Modern, fast web framework for building APIs
- OpenAI: Embeddings and Language Models
- PostgreSQL + pgvector: Vector similarity search
- Python 3.10+: Modern Python features
- Docker: Containerization and deployment
- Clone the repository:
git clone https://github.com/rrequeena/rag-api.git
cd rag-api
- Create a
.env
file with your configuration:
OPENAI_API_KEY=sk-this-is-your-super-api-key
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
DATABASE_NAME=rag_api_db
You will find a .env.example
file at the project folder.
- Start the services using Docker Compose:
docker-compose up --build
Or you can use Make commands:
make build
make compose
The API will be available at http://localhost:8080
Root endpoint that returns all the files stored in the DB.
curl -X 'GET' \
'http://0.0.0.0:8080/' \
-H 'accept: application/json'
Upload a document for processing.
curl -X 'POST' \
'http://0.0.0.0:8080/uploadfile/' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@your_file.pdf;type=application/pdf'
Ask questions for a given document ID.
curl -X 'POST' \
'http://0.0.0.0:8080/ask/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"document_id": 4,
"question": "What is the document talking about?"
}'
Find similar chunks of text for a given document.
curl -X 'POST' \
'http://0.0.0.0:8080/find-similar-chunks/4' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"question": "Something you want to check"
}'
Delete a document and its associated data.
curl -X DELETE "http://localhost:8080/delete-document/1" \
-H "accept: application/json"
Full API documentation is available at:
- Swagger UI:
http://localhost:8080/docs