Image retrieval using Lindorm's multimodal capabilities
Quickly build an image retrieval service that supports search by text and search by image, using Lindorm's scalar, full-text, and vector hybrid search combined with online inference.
Background
As autonomous driving, AI-generated content (AIGC), and multimodal foundation models evolve, the demand for image retrieval continues to grow. Whether you need to filter high-quality datasets from massive image libraries for model training or improve generated content by searching the internet for images, intelligent image retrieval is a key part of the workflow.
Lindorm's multimodal database provides an intelligent search solution that addresses the following core challenges:
-
High-quality recall: Combines scalar, full-text, and vector retrieval with AI multimodal models for precise matching of images, text, and features.
-
Efficient cost control: Stores and retrieves massive amounts of image data at lower cost.
-
Elastic scaling: Scales in seconds to handle rapid data growth.
With this solution, you can quickly build a high-performance, low-cost image retrieval service. The storage-compute separation architecture enables scaling in seconds to meet your business needs.
Architecture
The following Python code examples demonstrate how to build an image retrieval service by using Lindorm's scalar, full-text, and vector hybrid search capabilities along with online inference.
Step 1: Enable Lindorm's multimodal capabilities
-
Log on to the Lindorm console.
-
In the upper-left corner of the page, click Create.
-
On the Lindorm purchase page, configure the following parameters.
Parameter
Description
Product type
Select Lindorm.
Instance configuration
Select Search Engine, Vector Engine, and AI Engine.
Note-
You must submit a ticket to enable the AI Engine.
-
Before you create an instance, submit a ticket to be added to the allowlist. Then, you can select AI Engine during the creation process.
-
If you have already created an instance, submit a ticket to enable the AI Engine feature separately.
-
-
The Vector Engine depends on the Search Engine. You must enable both engines.
-
For more information about the engines, see Engine types.
-
You can change the instance specification and number of nodes based on your workload. For more information, see Change instance specifications.
-
-
Click Buy Now and complete the payment process.
Step 2: Configure an IP address whitelist
Add your client's IP address to the Lindorm IP address whitelist. To set the whitelist, see Set an IP address whitelist.
Step 3: Download the sample code
Download the code sample multimodalRetrieval for building the image retrieval service in the following steps.
Step 4: Configure the environment
Runtime environment
Ensure Python 3.10 or later is installed.
Install dependencies
pip3 install -r requirements.txt
Configure Lindorm connection endpoints
In the env script of the downloaded code, configure the connection endpoints for each Lindorm engine. For information about how to obtain connection endpoints, see View connection endpoints.
Large model inference uses Model Studio and requires an API key. For information about how to obtain an API key, see Obtain an API key.
# AI host (Configure the AI Engine endpoint)
AI_HOST="ld-bp17j28j2y7pm****-proxy-ai-pub.lindorm.aliyuncs.com"
AI_PORT="9002"
# Search host (Configure the Search Engine endpoint)
SEARCH_HOST="ld-bp17j28j2y7pm****-proxy-search-pub.lindorm.aliyuncs.com"
SEARCH_PORT="30070"
# Lindorm user and password (Configure the Lindorm user password)
LD_USER="root"
LD_PASSWORD="test****"
# The maximum number of results to return
SEARCH_TOP_K="9"
# Configure the API key for Model Studio
DASHSCOPE_API_KEY="sk-****"
# Fixed model names
LD_VL_MODEL="bge_visual0"
LD_TEXT_MODEL="bge_m3_model"
Install Jupyter Notebook
-
Install Jupyter.
pip3 install jupyter -
Generate the configuration file
~/.jupyter/jupyter_notebook_config.py.jupyter notebook --generate-config -
Generate a password hash for Jupyter access.
from passlib.hash import argon2 print(argon2.hash('Vector123'))The output is a password hash used for Jupyter Notebook password configuration. The following is a sample output:
$argon2id$v=19$m=65536,t=3,p=4$4TyndM75H8N4b+291xqjdA$n0QSxlv/uCLjGR0TX/jbD/XFlEu9BzQGI1b2Mcu6gxg -
Run the
vim ~/.jupyter/jupyter_notebook_config.pycommand to open and edit the configuration file.# Add the following configurations to the end of the file. c.NotebookApp.ip = '*' # The default directory for the notebook. Set this yourself. # Whether to open a browser after the notebook starts. Set to False. c.NotebookApp.open_browser = False # The default access port. You can change this. c.NotebookApp.port = 9000 # Replace the content after argon2 in the code below with the Jupyter password hash you obtained in the previous step. c.NotebookApp.password = 'argon2:$argon2id$v=19$m=65536,t=3,p=4$4TyndM75H8N4b+291xqjdA$n0QSxlv/uCLjGR0TX/jbD/XFlEu9BzQGI1b2Mcu6gxg' # This home directory is important. You must place the files that you want to access in this directory. c.NotebookApp.notebook_dir = u'/data/lindorm/LindormDemo' # Set the directory that you want to display when you open Jupyter Notebook. You can set it to a frequently used path. -
Start the Jupyter service. Start the service in the foreground to check for startup errors. To stop the service, press
Ctrl+C.jupyter notebookNoteIn production environments, we recommend that you start the Jupyter service in the background to prevent service interruptions if the terminal is closed. To start the service in the background, run the following command:
nohup jupyter notebook --allow-root >/tmp/jupyter.log 2>&1 &.
Step 5: Run the .ipynb script
Create Lindorm multimodal retrieval models
The sample code depends on two Lindorm multimodal retrieval models:
-
Text embedding model: bge_m3_model.
-
Image embedding model: bge_visual0.
For more information about how to deploy models in the AI Engine and for parameter details, see Model management and Use the AI Engine by using cURL commands.
Deploy the bge_m3_model
curl -i -k --location --header 'x-ld-ak:<username>' --header 'x-ld-sk:<password>' -X POST http://ld-bp17j28j2y7pm****-proxy-ai-pub.lindorm.aliyuncs.com:9002/v1/ai/models/create \
-H "Content-Type: application/json" \
-d '{
"model_name": "bge_m3_model",
"model_path": "huggingface://BAAI/bge-m3",
"task": "FEATURE_EXTRACTION",
"algorithm": "BGE_M3",
"settings": {"instance_count": "2"}
}'
Deploy the bge_visual0 model
curl -X POST "http://ld-bp17j28j2y7pm****-proxy-ai-pub.lindorm.aliyuncs.com:9002/v1/ai/models/create" \
-H "x-ld-ak: <username>" \
-H "x-ld-sk: <password>" \
-H "Content-Type: application/json" \
-d '{
"model_name": "bge_visual0",
"model_path": "huggingface://BAAI/bge-visualized",
"task": "FEATURE_EXTRACTION",
"algorithm": "BGE_VISUALIZED_M3",
"settings": {
"model_type": "ensemble",
"instance_count": "4"
}}'
List all models
curl -i -k --location --header 'x-ld-ak:<username>' --header 'x-ld-sk:<password>' --request GET 'http://ld-bp17j28j2y7pm****-proxy-ai-pub.lindorm.aliyuncs.com:9002/v1/ai/models/list'
Deployment process
In Jupyter, run the LindormQwenVlMultiModalSearch.ipynb script to build a high-quality image retrieval library by using the Qwen-VL image recognition model and Lindorm's multimodal models.
|
Step |
Description |
Engines involved |
|
Create a search index |
Create a search index table that contains a column for image vectors.
|
Search Engine Vector Engine |
|
Ingest images |
Process raw image data into vectors and write them to the index table.
|
AI Engine Search Engine Vector Engine |
Retrieval methods
-
Retrieval methods: search by text and search by image.
-
Search options: vector search and hybrid search (full-text and vector).
-
Image deduplication: Uses search by image to identify and filter out images that meet or exceed a specified similarity threshold, preventing duplicate imports and returning similar images for reference.
|
Retrieval method |
Description |
Engines involved |
|
Search by text |
Search for images by using text. You can use pure vector search or full-text and vector hybrid search.
|
AI Engine Search Engine Vector Engine |
|
Search by image |
Search for images by using an image. This method performs a vector search.
|
AI Engine Search Engine Vector Engine |
|
Search by image - image deduplication |
Run
|
AI Engine Search Engine Vector Engine |