This project is a lightweight image search system based on Milvus Lite. Unlike the standard Milvus that requires Docker, Milvus Lite can run directly in a Python environment, greatly simplifying deployment and development.
This document will explain in detail how to run this project step by step based on your code and data.
The core code flow of this project is divided into three main steps, controlled by three independent Shell scripts. Please execute them in the following order:
-
Generate Embeddings (
1_generate_embeddings.sh):- Purpose: Reads the original image files, extracts features using the specified CLIP model, and saves these features (embeddings) as a
.pklfile. - This is the first step of the entire process and serves as the data foundation for subsequent steps.
- Purpose: Reads the original image files, extracts features using the specified CLIP model, and saves these features (embeddings) as a
-
Build Milvus Index (
2_build_milvus_lite_index.sh):- Purpose: Reads the
.pklfile generated in the previous step, creates a Collection in Milvus Lite, imports all vector data into it, and builds the index. - This step is responsible for loading the data into the vector database, preparing it for search.
- Purpose: Reads the
-
Start the Search Application (
search-run-milvus-lite.sh):- Purpose: Starts a Streamlit web application. This application connects to Milvus Lite and provides a user interface for real-time search via text or images.
- This is the final deliverable of the project, providing interactive search functionality.
-
Install Dependencies:
pip install -r requirements_milvus_lite.txt
-
Configure
1_generate_embeddings.sh:- Open the
1_generate_embeddings.shfile and must modify the following variables:IMG_DIR: Points to your image dataset directory.MODEL_PATH: Points to your local CLIP model directory.DATABASE_DIR: Defines the storage location for the generated feature vector file (.pkl).
- Open the
After configuration, run the first script:
./1_generate_embeddings.sh- Upon successful execution, you should see a
.pklfile in theDATABASE_DIRdirectory.
-
Configure
2_build_milvus_lite_index.sh(Optional):- Open the
2_build_milvus_lite_index.shfile. Usually, you do not need to modify it, but you can pay attention to:EMBEDDINGS_PATH: The script will automatically use the.pklfile path generated in the previous step.COLLECTION_NAME: The name of the Milvus collection, which can be customized.MILVUS_DATA_DIR: The storage location for Milvus Lite database files. Default is empty, can be modified via environment variables or script parameters.
- Open the
-
Run the Script:
./2_build_milvus_lite_index.sh
- This script will automatically install Milvus Lite (if not already installed) and complete the index build.
-
Configure
search-run-milvus-lite.sh(Optional):- Open the
search-run-milvus-lite.shfile. Usually, you do not need to modify it, but you can pay attention to:STREAMLIT_PORT: The access port for the web application, default is8080.
- Open the
-
Run the One-Click Startup Script:
./search-run-milvus-lite.sh
- The script will check if the previous steps are completed and then start the application.
- Access the Application:
- Open your browser and go to
http://localhost:8080(or your custom port) to start using the image search functionality.
- Open your browser and go to
.
├── app_milvus_lite.py # Streamlit application main program
├── clip_image_search/ # Core search logic
│ ├── extract_embeddings.py # Python file called by script 1: extracts image features
│ └── build_milvus_lite_index.py # Python file called by script 2: builds Milvus index
├── 1_generate_embeddings.sh # Script 1: Generate embeddings
├── 2_build_milvus_lite_index.sh # Script 2: Build index
├── search-run-milvus-lite.sh # Script 3: One-click application startup
├── start_milvus_lite.py # Milvus Lite service management tool (advanced)
├── requirements_milvus_lite.txt # Python dependencies
└── README.md # This document
- Zero Configuration: No Docker or complex configuration needed.
- Lightweight: Low resource usage, fast startup.
- Full-Featured: Supports vector search, indexing, and data persistence.
- Developer-Friendly: Ideal for rapid development and testing.
Milvus Lite not availableorNo module named 'milvus': Please ensure all dependencies are installed:pip install -r requirements_milvus_lite.txtCollection not found: The Collection does not exist. Please run./2_build_milvus_lite_index.shfirst to build the index.- Port Already in Use:
If port
8669is occupied, you can specify a new port when starting:streamlit run app_milvus_lite.py --server.port <new_port> - Image File Not Found:
Please check if the image path set in
1_generate_embeddings.shis correct.
Note: For the Chinese version of this documentation, please see README-zh.md.
注意:本文档的中文版请参见 README-zh.md。