A searchable image database using SigLIP 2 (CLIP) embeddings and SQLite-vec for efficient similarity search.
Note: This code was generated with AI assistance.
- Image Indexing: Scan directories and extract CLIP embeddings from images
- Text Search: Search images using natural language queries
- Image Search: Find similar images using a reference image
- Combined Search: Combine text and image queries with weighted blending
- Interactive Mode: Load model once and run multiple queries
- 3D Visualization: UMAP-based 3D visualization of image embeddings with clustering
- HTML Gallery: Beautiful search results with image previews and direct file access
Note: The HTML search results use localexplorer: protocol links for opening files and folders. To use these links, you'll need a browser extension like Local Explorer for Chrome/Edge or similar extensions for other browsers. Without the extension, you can still view images and copy file paths manually.
- Python 3.8+
- CUDA-capable GPU (recommended) or CPU
- See
requirements.txtfor Python dependencies
- Clone this repository:
git clone <repository-url>
cd CLIP-database- Install dependencies:
cd code
pip install -r requirements.txt- Install sqlite-vec extension (if not already installed):
pip install sqlite-vec- (Optional) Copy
config.json.exampletoconfig.jsonand edit paths if needed.
Scan a directory and build the image database:
cd code
python image_database.py scan /path/to/images --batch-size 75 --inference-batch-size 16 --profile --limit 100Options:
--batch-size: Number of images to process before committing to DB (default: 75)--inference-batch-size: Batch size for model inference (default: 16, higher = faster but more VRAM)--profile: Show performance profiling information--limit: Limit number of images to process (for testing)
cd code
python image_database.py search "a red car" -k 20cd code
python image_database.py search /path/to/image.jpg --image -k 20cd code
python image_database.py search "sunset" --query2 /path/to/image.jpg --weights 0.7 0.3 -k 20cd code
python image_database.py search "nature" --negative "buildings" -k 20cd code
python image_database.py search --interactiveIn interactive mode:
- Enter text queries directly
- Use
image:/path/to/image.jpgfor image queries - Combine queries with
+:image:/path/to/img.jpg + sunset - Use negative prompts with
-:beautiful landscape - peopleorsunset - image:/path/to/unwanted.jpg - Change result count with
k:20 - Type
quitorexitto end session
Generate a UMAP 3D visualization of all image embeddings:
cd code
python visualize_umap.pyThis will:
- Load embeddings from the database
- Compute UMAP projections (cached for future runs)
- Cluster embeddings for color coding
- Generate an interactive HTML visualization
Open the generated HTML file in your browser and click on points to see image previews.
Note: The HTML results include "Open Image" and "Open Folder" links that use the localexplorer: protocol. To use these links, install a browser extension like Local Explorer for Chrome/Edge. Without the extension, images will still display, but the file/folder links won't work.
This project uses SigLIP 2 SO400M from Google, which provides:
- 1152-dimensional embeddings
- Strong text-image alignment
- Efficient inference
The model will be automatically downloaded from HuggingFace on first use (or use --model-cache to specify a custom cache directory).
The SQLite database contains:
imagestable: Image metadata (file path, last modified, hash)vec0virtual table: Vector embeddings (using sqlite-vec)image_embeddingstable: Mapping between images and embeddings
- Use
--inference-batch-sizeto optimize GPU memory usage - Enable
--profileto identify bottlenecks - The database uses WAL mode for better concurrent access
- UMAP projections are cached to avoid recomputation
MIT License - see LICENSE file for details.
This project uses:
- SigLIP 2 - Apache 2.0 License
- sqlite-vec - MIT/Apache 2.0 dual license
- SQLite - Public Domain
