Background information
In the information explosion era, users often need to quickly retrieve necessary information from massive amounts of data. Efficient retrieval systems are required to quickly locate content of interest in online literature databases, e-commerce product catalogs, and rapidly growing multimedia content libraries. As the amount of data continues to increase, traditional keyword-based search methods cannot meet users' needs for both accuracy and speed. This is where vector search technology comes in. It encodes different types of data, such as text, images, and audio, into mathematical vectors and performs search operations in the vector space. This allows the system to capture the deep semantic information of data and provide more accurate and efficient search results.
This topic will show you how to build your own image search application using OceanBase's vector search technology.
Architecture
The image search application stores a library of images as vectors within a database. Users can upload the image they want to search for through the UI interface. The application then converts the image into a vector, searches for similar vectors in the database, and returns the results. The similar images are displayed on the UI interface.

Prerequisites
You have deployed OceanBase Database V4.3.3 or later and created a MySQL tenant. For more information about how to deploy an OceanBase cluster, see Overview.
The MySQL tenant you created has the
INSERTandSELECTprivileges. For more information about how to configure privileges, see Grant direct privileges.You have created a database. For more information about how to create a database, see Create a database.
The vector search feature is enabled for the database.
obclient> ALTER SYSTEM SET ob_vector_memory_limit_percentage = 30;You have prepared the required images. If you do not have enough images for testing, you can use the image datasets from open-source websites.
You have installed Python 3.9 or later.
You have installed Poetry.
python3 -m ensurepip python3 -m pip install poetry
Procedure
Clone the code repository.
git clone https://gitee.com/oceanbase-devhub/image-search.git cd image-searchInstall the dependencies.
poetry installSet environment variables.
cp .env.example .env # Update the database information in the .env file. vi .envHere's how to update the contents of the
.envfile.HF_ENDPOINT=https://hf-mirror.com DB_HOST="127.0.0.1" ## Set the IP address of the tenant. DB_PORT="2881" ## Set the port. DB_USER="root@test" ## Set the tenant and username. DB_NAME="test" ## Set the database name. DB_PASSWORD="" ## Set the password of the tenant user.Upload the prepared images to the server.
Start the image search program.
UI_LANG=en poetry run streamlit run --server.runOnSave false image_search_ui.pyThe return result is as follows:
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to false. You can now view your Streamlit app in your browser. Local URL: http://localhost:8501 Network URL: http://xxx.xxx.xxx.xxx:8501 External URL: http://xxx.xxx.xxx.xxx:8501Open the UI of the image search application. You can enter the URL returned in Step 5 based on the actual situation.
In the Loading Setting area, enter the absolute path of the directory where the images are stored on the server for Image Base.
Click Load Images.
After the images are loaded, you can proceed with image search.
Example
