目录
- milvus sdk常用命令
- python
milvus sdk常用命令
python
https://milvus.io/docs/manage_databases.md
pip3 install pymilvus
#!/usr/bin/env
from pymilvus import connections, db
from pymilvus import CollectionSchema, FieldSchema, DataType
from pymilvus import Collection
from pymilvus import utility
#conn = connections.connect(host="192.168.10.26", port=19530)
conn = connections.connect(host="211.154.163.93", port=19530)
#db.using_database("liwenchao")
#utility.drop_collection("collection")
#db.drop_database("liwenchao")
print(db.list_database())
#创建和删除数据和mysql类似有先后顺序
#创建顺序为 database>collection>partition
#删除顺序反过来 partition>collection>database
#create database
database = db.create_database("liwenchao")
print(db.list_database())
#using databse
db.using_database("liwenchao")
#create collection prepare,创建机器前初始化结构体
book_id = FieldSchema(
name="book",
dtype=DataType.INT64,
is_primary=True,
)
book_name = FieldSchema(
name="book_name",
dtype=DataType.VARCHAR,
max_length=200,
)
word_count = FieldSchema(
name="word_count",
dtype=DataType.INT64,
)
book_intro = FieldSchema(
name="book_intro",
dtype=DataType.FLOAT_VECTOR,
dim=2
)
schema = CollectionSchema(
fields=[book_id, book_name,word_count, book_intro],
description="Test book search",
enable_dynamic_field=True
)
collection_name = "collection"
#create collection
collection = Collection(
name=collection_name,
using='default',
schema=schema,
shards_num=2
)
#print all collection
print(utility.list_collections())
#check collection is here
print(utility.has_collection("collection"))
#create partition
collection = Collection("collection") # Get an existing collection.
collection.create_partition("novel")
#check partition is here
collection = Collection("collection") # Get an existing collection.
print (collection.has_partition("novel"))
#delete partition
collection.drop_partition("novel")
#delete collection
utility.drop_collection("collection")
#drop database
db.drop_database("liwenchao")
print(db.list_database())