Image Similarity Search API
A FastAPI application for image similarity search using CLIP embeddings and Qdrant vector database.
Features
- Upload images and store their vector embeddings
- Search for similar images using an uploaded image or base64 encoded image
- Secure API with API key authentication
- Well-organized, modular codebase following OOP principles
Installation
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables (optional, defaults are provided):
export QDRANT_URL="your-qdrant-url"
export QDRANT_API_KEY="your-qdrant-api-key"
export COLLECTION_NAME="your-collection-name"
export API_KEY="your-api-key"
export PORT=8000
export ENVIRONMENT="production" # Or "development" for debug mode with auto-reload
Usage
Run the application:
python app.py
The API will be available at http://localhost:8000 (or the port specified in environment variables).
API Documentation
Once running, API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
POST /add-image/: Add an image to the databasePOST /add-images-from-folder/: Add all images from a folder to the databasePOST /search-by-image/: Search for similar images using an uploaded imagePOST /search-by-image-scan/: Search for similar images using a base64 encoded imageGET /collections: List all collections in the databaseGET /health: Health check endpoint
Project Structure
image_similarity_api/
│
├── app.py # Main application entry point
├── config.py # Configuration settings
├── models/
│ ├── __init__.py
│ └── schemas.py # Pydantic models
├── services/
│ ├── __init__.py
│ ├── embedding.py # Image embedding service
│ ├── security.py # Security service
│ └── vector_db.py # Vector database service
├── api/
│ ├── __init__.py
│ └── routes.py # API routes
├── requirements.txt # Project dependencies
└── README.md # Project documentation
Development
For development, set the ENVIRONMENT variable to "development" for auto-reload:
export ENVIRONMENT="development"
python app.py
Deployment
This application can be deployed to any platform that supports Python applications:
- Docker
- Kubernetes
- Cloud platforms (AWS, GCP, Azure, etc.)
- Serverless platforms (with appropriate adapters)
Remember to set all required environment variables in your production environment.