VectorDB CLI + VectorDB Lite 本地高效调试向量数据库
更新时间:2025-04-08
使用Docker Compose启动VectorDB服务
启动方式 1
Docker Compose配置docker-compose.yml
Shell
1services:
2 vdb-service:
3 image: mochow/vdb:2.1.5854 # 镜像名称和版本
4 container_name: baidu-vdb-container # 容器名称
5 ports:
6 - "5287:5287" # 映射容器内的 5287 端口到主机
7 environment:
8 - port=5287 # 配置容器内使用的端口
9 volumes:
10 - ./data:/mnt/data # 将本地 ./data 目录挂载到容器中的 /mnt/data
11 - ./log:/mnt/log # 将本地 ./log 目录挂载到容器中的 /mnt/log
12 restart: always # 自动重启策略,确保容器在意外退出时重启
启动本地VectorDB服务
Shell
1docker compose up -d
启动方式 2
国内用户如果无法访问 docker 服务,可以直接下载,然后通过命令安装
Shell
1curl http://public-vdb.bj.bcebos.com/vdb-standalone-2.1.tar.gz -o vdb-standalone-2.1.tar.gz
解压后启动本地 VectorDB 服务
Shell
1sh vdb_service.sh start
启动后本地会有两个目录,data保存数据和log保存日志
Shell
1ll
2total 12
3drwxr-xr-x 5 1000 1000 4096 Jan 10 10:57 data
4-rw-r--r-- 1 root root 536 Jan 10 10:55 docker-compose.yml
5drwxr-xr-x 2 1000 1000 4096 Jan 10 10:57 log
查看服务正常启动,服务端口为5287
Shell
1docker ps | grep vectordb
2709db1519963 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
1docker compose down
使用VectorDB CLI进行建表
使用VectorDB CLI链接本地的VectorDB,root默认密码为mochow。
Shell
1./vectordb-cli -u root -e http://127.0.0.1:5287
2api key for 'root' to 'http://127.0.0.1:5287':
32024/09/14 11:06:53 Successfully initialized mochow client.
4
5
6 __ __ _ ____ ____
7 \ \ / / ___ ___ | |_ ___ _ __ | _ \ | __ )
8 \ \ / / / _ \ / __| | __| / _ \ | '__| | | | | | _ \
9 \ V / | __/ | (__ | |_ | (_) | | | | |_| | | |_) |
10 \_/ \___| \___| \__| \___/ |_| |____/ |____/
11
12
13 type '-h' or 'help' to see usage
14vectordb-cli >
15vectordb-cli >
建库
Shell
1vectordb-cli > create database -d testdb
2create database 'testdb' success
3vectordb-cli > list databases
4+--------------+
5| databases |
6+==============+
7| testdb |
8+--------------+
建表
Shell
1vectordb-cli > create table
2
3input create table args, end with ';'
4... {
5... "database": "testdb",
6... "table": "book",
7... "description": "basic test",
8... "replication": 1,
9... "partition": {
10... "partitionType": "HASH",
11... "partitionNum": 3
12... },
13... "enableDynamicField": false,
14... "schema": {
15... "fields": [
16... {
17... "fieldName": "id",
18... "fieldType": "STRING",
19... "primaryKey": true,
20... "partitionKey": true,
21... "autoIncrement": false,
22... "notNull": true
23... },
24... {
25... "fieldName": "bookName",
26... "fieldType": "STRING",
27... "notNull": true
28... },
29... {
30... "fieldName": "author",
31... "fieldType": "STRING"
32... },
33... {
34... "fieldName": "page",
35... "fieldType": "UINT32"
36... },
37... {
38... "fieldName": "vector",
39... "fieldType": "FLOAT_VECTOR",
40... "notNull": true,
41... "dimension": 3
42... }
43... ],
44... "indexes": [
45... {
46... "indexName": "book_name_idx",
47... "field": "bookName",
48... "indexType": "SECONDARY"
49... },
50... {
51... "indexName": "vector_idx",
52... "field": "vector",
53... "indexType": "HNSW",
54... "metricType": "L2",
55... "params": {
56... "M": 32,
57... "efConstruction": 32
58... }
59... }
60... ]
61... }
62... };
63create table 'book' success
64
65vectordb-cli > list tables --db testdb
66+-----------+
67| tables |
68+===========+
69| book |
70+-----------+