データベース
Milvusはコレクションの上にデータベースレイヤーを導入し、マルチテナンシーをサポートしながら、より効率的なデータの管理・整理方法を提供します。
データベースとは
Milvusでは、データベースはデータを整理・管理するための論理的な単位として機能します。データのセキュリティを強化し、マルチテナントを実現するために、複数のデータベースを作成し、アプリケーションやテナントごとにデータを論理的に分離することができます。たとえば、ユーザー A のデータを格納するデータベースと、ユーザー B のデータを格納する別のデータベースを作成します。
データベースの作成
Milvus RESTful APIまたはSDKを使用して、プログラムでデータを作成することができます。
from pymilvus import MilvusClient
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
client.create_database(
db_name="my_database_1"
)
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.service.database.request.*;
ConnectConfig config = ConnectConfig.builder()
.uri("http://localhost:19530")
.token("root:Milvus")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
CreateDatabaseReq createDatabaseReq = CreateDatabaseReq.builder()
.databaseName("my_database_1")
.build();
client.createDatabase(createDatabaseReq);
import {MilvusClient} from '@zilliz/milvus2-sdk-node';
const client = new MilvusClient({
address: "http://localhost:19530",
token: 'root:Milvus'
});
await client.createDatabase({
db_name: "my_database_1"
});
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "localhost:19530",
Username: "Milvus",
Password: "root",
})
if err != nil {
// handle err
}
err = cli.CreateDatabase(ctx, milvusclient.NewCreateDatabaseOption("my_database_1"))
if err != nil {
// handle err
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "my_database_1"
}'
データベースを作成する際に、データベースのプロパティを設定することもできます。以下の例では、データベースのレプリカ数を設定しています。
client.create_database(
db_name="my_database_2",
properties={
"database.replica.number": 3
}
)
Map<String, String> properties = new HashMap<>();
properties.put("database.replica.number", "3");
CreateDatabaseReq createDatabaseReq = CreateDatabaseReq.builder()
.databaseName("my_database_2")
.properties(properties)
.build();
client.createDatabase(createDatabaseReq);
await client.createDatabase({
db_name: "my_database_2",
properties: {
"database.replica.number": 3
}
});
err := cli.CreateDatabase(ctx, milvusclient.NewCreateDatabaseOption("my_database_2").WithProperty("database.replica.number", 3))
if err != nil {
// handle err
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "my_database_2",
"properties": {
"database.replica.number": 3
}
}'
データベースの表示
Milvus RESTful APIまたはSDKを使用して、既存のすべてのデータベースを一覧表示し、その詳細を表示することができます。
# List all existing databases
client.list_databases()
# Output
# ['default', 'my_database_1', 'my_database_2']
# Check database details
client.describe_database(
db_name="default"
)
# Output
# {"name": "default"}
import io.milvus.v2.service.database.response.*;
ListDatabasesResp listDatabasesResp = client.listDatabases();
DescribeDatabaseResp descDBResp = client.describeDatabase(DescribeDatabaseReq.builder()
.databaseName("default")
.build());
await client.describeDatabase({
db_name: 'default'
});
// List all existing databases
databases, err := cli.ListDatabase(ctx, milvusclient.NewListDatabaseOption())
if err != nil {
// handle err
}
log.Println(databases)
db, err := cli.DescribeDatabase(ctx, milvusclient.NewDescribeDatabaseOption("default"))
if err != nil {
// handle err
}
log.Println(db)
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/describe" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "default"
}'
データベースプロパティの管理
データベースの作成で説明されているように、データベースを作成するときにデータベースのプロパティを設定したり、既存のデータベースのプロパティを変更および削除したりすることができます。
以下の表は、設定可能なデータベース・プロパティの一覧です。
プロパティ名 |
タイプ |
プロパティ 説明 |
|---|---|---|
|
整数 |
指定したデータベースのレプリカ数。 |
|
string |
指定したデータベースに関連付けられているリソースグループの名前(カンマ区切り)。 |
|
integer |
指定したデータベースのディスク容量の最大サイズ。 |
|
整数 |
指定したデータベースで許可されるコレクションの最大数。 |
|
boolean |
指定したデータベースに書き込み操作を拒否させるかどうか。 |
|
boolean |
指定したデータベースに読み取り操作を拒否させるかどうか。 |
|
文字列 |
データベース内の時間に敏感な操作、特に |
データベース・プロパティの変更
既存のデータベースのプロパティを以下のように変更できます。以下の例では、データベースで作成できるコレクションの数を制限しています。
client.alter_database_properties(
db_name="my_database_1",
properties={
"database.max.collections": 10
}
)
client.alterDatabaseProperties(AlterDatabasePropertiesReq.builder()
.databaseName("my_database_1")
.property("database.max.collections", "10")
.build());
await milvusClient.alterDatabaseProperties({
db_name: "my_database_1",
properties: {"database.max.collections", "10" },
})
err := cli.AlterDatabaseProperties(ctx, milvusclient.NewAlterDatabasePropertiesOption("my_database_1").
WithProperty("database.max.collections", 1))
if err != nil {
// handle err
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/alter" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "my_database",
"properties": {
"database.max.collections": 10
}
}'
データベースのプロパティの削除
以下のように、データベースのプロパティを削除してリセットすることもできます。以下の例では、データベースで作成できるコレクション数の制限を削除しています。
client.drop_database_properties(
db_name="my_database_1",
property_keys=[
"database.max.collections"
]
)
client.dropDatabaseProperties(DropDatabasePropertiesReq.builder()
.databaseName("my_database_1")
.propertyKeys(Collections.singletonList("database.max.collections"))
.build());
await milvusClient.dropDatabaseProperties({
db_name: my_database_1,
properties: ["database.max.collections"],
});
err := cli.DropDatabaseProperties(ctx, milvusclient.NewDropDatabasePropertiesOption("my_database_1", "database.max.collections"))
if err != nil {
// handle err
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/alter" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "my_database",
"propertyKeys": [
"database.max.collections"
]
}'
データベースの使用
Milvusから切断することなく、データベースを切り替えることができます。
RESTful APIはこの操作をサポートしていません。
client.use_database(
db_name="my_database_2"
)
client.useDatabase("my_database_2");
await milvusClient.useDatabase({
db_name: "my_database_2",
});
err = cli.UseDatabase(ctx, milvusclient.NewUseDatabaseOption("my_database_2"))
if err != nil {
// handle err
}
# This operation is unsupported because RESTful does not provide a persistent connection.
# As a workaround, initiate the required request again with the target database.
データベースの削除
データベースが不要になったら、そのデータベースを削除することができます。以下の点に注意してください:
デフォルトのデータベースは削除できません。
データベースを削除する前に、まずデータベース内のすべてのコレクションを削除する必要があります。
Milvus RESTful APIまたはSDKを使用して、プログラムでデータを作成することができます。
client.drop_database(
db_name="my_database_2"
)
client.dropDatabase(DropDatabaseReq.builder()
.databaseName("my_database_2")
.build());
await milvusClient.dropDatabase({
db_name: "my_database_2",
});
err = cli.DropDatabase(ctx, milvusclient.NewDropDatabaseOption("my_database_2"))
if err != nil {
// handle err
}
export CLUSTER_ENDPOINT="http://localhost:19530"
export TOKEN="root:Milvus"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/drop" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"dbName": "my_database"
}'
よくある質問
データベースの権限はどのように管理するのですか?
Milvusはロールベースアクセスコントロール(RBAC)を使用して権限を管理します。特定の権限を持つロールを作成し、ユーザに割り当てることで、異なるデータベースへのアクセスを制御することができます。詳細については、RBAC のドキュメントを参照してください。
データベースのクォータ制限はありますか?
Milvusでは、最大コレクション数など、データベースのクォータ制限を設定することができます。制限の包括的なリストについては、Milvus Limits ドキュメントを参照してください。