milvus的collection操作

milvus的collection操作

创建collection

python 复制代码
import uuid

from pymilvus import (
    connections,
    FieldSchema, CollectionSchema, DataType,
    Collection,
)

collection_name = "hello_milvus"
host = "192.168.230.71"
port = 19530
username = ""
password = ""
num_entities, dim = 5000, 3

print("start connecting to Milvus")
connections.connect("default", host=host, port=port,user=username,password=password)

fields = [
    FieldSchema(name="pk", dtype=DataType.INT64, is_primary=True, auto_id=False),
    FieldSchema(name="random", dtype=DataType.DOUBLE),
    FieldSchema(name="comment", dtype=DataType.VARCHAR, max_length=200),
    FieldSchema(name="embeddings", dtype=DataType.FLOAT16_VECTOR, dim=dim)
]

schema = CollectionSchema(fields, "hello_milvus is the simplest demo to introduce the APIs")

print("Create collection `hello_world`")
coll = Collection(collection_name, schema, consistency_level="Bounded",shards_num=1)

print("done")

Collection()是一个构造函数,定义如下:

python 复制代码
class Collection:
    def __init__(
        self,
        name: str,
        schema: Optional[CollectionSchema] = None,
        using: str = "default",
        **kwargs,
    ) -> None:

name -- the name of collection

schema -- the schema of collection, defaults to None.

using -- Milvus connection alias name, defaults to 'default'.

**kwargs - 告诉python接受任意数量的关键字参数到这个字典中。

那milvus这里有哪些key?

看注释。

删除collection

python 复制代码
coll.drop()

函数定义:

python 复制代码
def drop(self, timeout: Optional[float] = None, **kwargs):

有一个timeout参数。

加载collection

功能:加载collection到内存。

python 复制代码
coll.load()

函数定义:

python 复制代码
def load(
        self,
        partition_names: Optional[list] = None,
        replica_number: int = 1,
        timeout: Optional[float] = None,
        **kwargs,
    )

参数说明:

python 复制代码
coll.load() #阻塞
coll.load(_async=True) #非阻塞
utility.wait_for_loading_complete("hello_iterator")

释放collection

从内存中卸载。

python 复制代码
coll.release()

描述collection

获取collection的信息

python 复制代码
infos = coll.describe()
for key, value in infos.items():
    print(key, value)
相关推荐
六bring个六几秒前
文件压缩处理(一)
开发语言·c#
Chrikk22 分钟前
现代化 C++ 工程构建:CMake 与包管理器的依赖治理
开发语言·c++
smj2302_7968265232 分钟前
解决leetcode第3782题交替删除操作后最后剩下的整数
python·算法·leetcode
gCode Teacher 格码致知1 小时前
Python基础教学:Python 3中的字符串在解释运行时的内存编码表示-由Deepseek产生
python·内存编码
世转神风-1 小时前
qt-kits-警告:No C++ compiler,无法正常解析工程项目.pro文件
开发语言·c++
翔云 OCR API1 小时前
承兑汇票识别接口技术解析与应用实践
开发语言·人工智能·python·计算机视觉·ocr
元周民1 小时前
matlab求两个具有共根的多项式的所有共根(未详细验证)
开发语言·matlab
不忘不弃2 小时前
十进制数转换为二进制数
开发语言
likerhood2 小时前
3. pytorch中数据集加载和处理
人工智能·pytorch·python
Data_agent2 小时前
京东图片搜索商品API,json数据返回
数据库·python·json