随着大规模AI应用落地,向量数据库作为非结构化数据处理的核心基础设施,其开发调试效率直接影响模型迭代速度。对此,文章聚焦VectorDB Lite轻量级本地调试方案(更多信息:cloud.baidu.com/product/vdb...),结合Docker容器化与VectorDB CLI命令行工具,构建开箱即用的向量数据调试闭环。在当前行业追求敏捷开发的趋势下,通过本地化调试不仅降低测试成本,更能为高并发向量检索、多模态索引等场景提供快速验证能力,助力技术开发者们实现从原型到生产的无缝迁移。
调试方案第一步
需要使用Docker Compose启动VectorDB服务,但需要注意一点,VectorDB Lite 版目前仅支持 X86 机器启动,ARM 芯片暂时不支持。
启动方式 1 Docker Compose配置docker-compose.yml
shell
services:
vdb-service:
image: mochow/vdb:2.1.5854 # 镜像名称和版本
container_name: baidu-vdb-container # 容器名称
ports:
- "5287:5287" # 映射容器内的 5287 端口到主机
environment:
- port=5287 # 配置容器内使用的端口
volumes:
- ./data:/mnt/data # 将本地 ./data 目录挂载到容器中的 /mnt/data
- ./log:/mnt/log # 将本地 ./log 目录挂载到容器中的 /mnt/log
restart: always # 自动重启策略,确保容器在意外退出时重启
启动本地VectorDB服务
shell
# 注意 Compose V2 才支持 docker compose 命令,如果是 V1 建议先升级。
docker compose up -d
启动方式 2 国内用户如果无法访问 docker 服务,可以直接下载,然后通过命令安装
shell
curl http://public-vdb.bj.bcebos.com/vdb-standalone-2.1.tar.gz -o vdb-standalone-2.1.tar.gz
解压后启动本地 VectorDB 服务
shell
sh vdb_service.sh start
启动后本地会有两个目录,data保存数据和log保存日志
shell
ll
total 12
drwxr-xr-x 5 1000 1000 4096 Jan 10 10:57 data
-rw-r--r-- 1 root root 536 Jan 10 10:55 docker-compose.yml
drwxr-xr-x 2 1000 1000 4096 Jan 10 10:57 log
查看服务正常启动,服务端口为5287
shell
docker ps | grep vectordb
709db1519963 mochow/vdb:2.1.5854 "/root/entrypoint.sh" About a minute ago Up About a minute 0.0.0.0:5287->5287/tcp, :::5287->5287/tcp baidu-vdb-container
停止本地VectorDB服务
shell
docker compose down
调试方案第二步
下载 VectorDB CLI
- 下载链接:linux.vectordb-cli-2.1.1.tar.gz
- 执行 tar -zxvf linux.vectordb-cli-2.1.1.tar.gz 解压工具压缩包
使用VectorDB CLI进行建表,即使用VectorDB CLI链接本地的VectorDB,root默认密码为mochow。
shell
./vectordb-cli -u root -e http://127.0.0.1:5287
api key for 'root' to 'http://127.0.0.1:5287':
2024/09/14 11:06:53 Successfully initialized mochow client.
__ __ _ ____ ____
\ \ / / ___ ___ | |_ ___ _ __ | _ \ | __ )
\ \ / / / _ \ / __| | __| / _ \ | '__| | | | | | _ \
\ V / | __/ | (__ | |_ | (_) | | | | |_| | | |_) |
\_/ \___| \___| \__| \___/ |_| |____/ |____/
type '-h' or 'help' to see usage
vectordb-cli >
vectordb-cli >
建库操作如下:
shell
vectordb-cli > create database -d testdb
create database 'testdb' success
vectordb-cli > list databases
+--------------+
| databases |
+==============+
| testdb |
+--------------+
建表操作如下:
shell
vectordb-cli > create table
input create table args, end with ';'
... {
... "database": "testdb",
... "table": "book",
... "description": "basic test",
... "replication": 1,
... "partition": {
... "partitionType": "HASH",
... "partitionNum": 3
... },
... "enableDynamicField": false,
... "schema": {
... "fields": [
... {
... "fieldName": "id",
... "fieldType": "STRING",
... "primaryKey": true,
... "partitionKey": true,
... "autoIncrement": false,
... "notNull": true
... },
... {
... "fieldName": "bookName",
... "fieldType": "STRING",
... "notNull": true
... },
... {
... "fieldName": "author",
... "fieldType": "STRING"
... },
... {
... "fieldName": "page",
... "fieldType": "UINT32"
... },
... {
... "fieldName": "vector",
... "fieldType": "FLOAT_VECTOR",
... "notNull": true,
... "dimension": 3
... }
... ],
... "indexes": [
... {
... "indexName": "book_name_idx",
... "field": "bookName",
... "indexType": "SECONDARY"
... },
... {
... "indexName": "vector_idx",
... "field": "vector",
... "indexType": "HNSW",
... "metricType": "L2",
... "params": {
... "M": 32,
... "efConstruction": 32
... }
... }
... ]
... }
... };
create table 'book' success
vectordb-cli > list tables --db testdb
+-----------+
| tables |
+===========+
| book |
+-----------+
更详细的命令可以查看:cloud.baidu.com/doc/VDB/s/R...
通过VectorDB CLI的声明式建表能力与VectorDB Lite版服务的轻量级部署,技术开发者们可在本地高效构建向量数据管理全链路。以上文章演示的Docker Compose快速启动、跨平台CLI交互及表结构设计实践,直击向量数据库开发中的环境隔离与快速验证痛点。随着边缘计算与轻量化AI部署需求激增,此类本地调试方案将成为算法工程师的标准工具链,进一步释放向量数据库在实时推荐、语义搜索等场景的落地潜力。 更多相关文章可浏览:VectorDBⅹMCP:轻松打造向量数据库专属助手