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)
相关推荐
会开花的二叉树19 小时前
继承与组合:C++面向对象的核心
java·开发语言·c++
潮汐退涨月冷风霜20 小时前
数字图像处理(1)OpenCV C++ & Opencv Python显示图像和视频
c++·python·opencv
长河20 小时前
Java开发者LLM实战——LangChain4j最新版教学知识库实战
java·开发语言
Cyan_RA921 小时前
SpringMVC @RequestMapping的使用演示和细节 详解
java·开发语言·后端·spring·mvc·ssm·springmvc
再见晴天*_*1 天前
SpringBoot 中单独一个类中运行main方法报错:找不到或无法加载主类
java·开发语言·intellij idea
lqjun08271 天前
Qt程序单独运行报错问题
开发语言·qt
酷飞飞1 天前
Python网络与多任务编程:TCP/UDP实战指南
网络·python·tcp/ip
hdsoft_huge1 天前
Java & Spring Boot常见异常全解析:原因、危害、处理与防范
java·开发语言·spring boot
风中的微尘1 天前
39.网络流入门
开发语言·网络·c++·算法
数字化顾问1 天前
Python:OpenCV 教程——从传统视觉到深度学习:YOLOv8 与 OpenCV DNN 模块协同实现工业缺陷检测
python