VectorDB CLI + VectorDB Lite 本地高效调试向量数据库
更新时间:2025-01-22
使用Docker Compose启动VectorDB服务
Docker Compose配置docker-compose.yml
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服务
docker compose up -d
启动后本地会有两个目录,data保存数据和log保存日志
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
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服务
docker compose down
使用VectorDB CLI进行建表
使用VectorDB CLI链接本地的VectorDB
./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 >
建库
vectordb-cli > create database -d testdb
create database 'testdb' success
vectordb-cli > list databases
+--------------+
| databases |
+==============+
| testdb |
+--------------+
建表
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 |
+-----------+