| # 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 | |
| 1. Clone this repository | |
| 2. Install dependencies: | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| 3. Set up environment variables (optional, defaults are provided): | |
| ```bash | |
| 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: | |
| ```bash | |
| 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 database | |
| - `POST /add-images-from-folder/`: Add all images from a folder to the database | |
| - `POST /search-by-image/`: Search for similar images using an uploaded image | |
| - `POST /search-by-image-scan/`: Search for similar images using a base64 encoded image | |
| - `GET /collections`: List all collections in the database | |
| - `GET /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: | |
| ```bash | |
| export ENVIRONMENT="development" | |
| python app.py | |
| ``` | |
| ## Deployment | |
| This application can be deployed to any platform that supports Python applications: | |
| 1. Docker | |
| 2. Kubernetes | |
| 3. Cloud platforms (AWS, GCP, Azure, etc.) | |
| 4. Serverless platforms (with appropriate adapters) | |
| Remember to set all required environment variables in your production environment. | |