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)
相关推荐
weixin_307779131 小时前
Azure上基于OpenAI GPT-4模型验证行政区域数据的设计方案
数据仓库·python·云计算·aws
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
多想和从前一样4 小时前
Django 创建表时 “__str__ ”方法的使用
后端·python·django
ll7788115 小时前
LeetCode每日精进:20.有效的括号
c语言·开发语言·算法·leetcode·职场和发展
小喵要摸鱼6 小时前
【Pytorch 库】自定义数据集相关的类
pytorch·python
IT古董6 小时前
【开源向量数据库】Milvus简介
数据库·开源·milvus
bdawn6 小时前
深度集成DeepSeek大模型:WebSocket流式聊天实现
python·websocket·openai·api·实时聊天·deepseek大模型·流式输出
Jackson@ML6 小时前
Python数据可视化简介
开发语言·python·数据可视化
mosquito_lover16 小时前
怎么把pyqt界面做的像web一样漂亮
前端·python·pyqt
赵琳琅6 小时前
Java语言的云计算
开发语言·后端·golang