python开发milvus2.0.2开发,快速上手,参考文档、手册、案例

本文介绍了如何使用Python Milvus库创建集合、设置一致性级别,并创建IVF_FLAT索引。重点讲解了设置consistency_level的重要性和仅支持向量字段的索引创建。适合初学者了解Milvus在搜索加速中的基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考文档

开发案例:
https://gitee.com/AI-Mart/pymilvus/blob/master/examples/hello_milvus.py
https://github.com/milvus-io/pymilvus/blob/master/examples/hello_milvus.py
参考指南:
https://milvus.io/docs/v2.0.x/manage_connection.md
python开发api文档:
https://milvus.io/api-reference/pymilvus/v2.0.2/About.md

代码记录

1、创建集合

hello_milvus = Collection("hello_milvus", schema, consistency_level="Strong")

注意1

Milvus supports setting consistency level while creating a collection (only on PyMilvus currently). In this example, the consistency level of the collection is set as "Strong", meaning Milvus will read the most updated data view at the exact time point when a search or query request comes. By default, a collection created without specifying the consistency level is set with bounded consistency level, under which Milvus reads a less updated data view (usually several seconds earlier) when a search or query request comes. Besides collection creation, you can also set the consistency level specifically for search or query (only on PyMilvus currently). For other consistency level supported by Milvus, see Guarantee Timestamp in Search Requests.

注意2

The collection to create must contain a primary key field and a vector field. INT64 is the only supported data type for the primary key field in current release of Milvus.

2、 创建索引

# 4. create index
print(fmt.format("Start Creating index IVF_FLAT"))
index = {
    "index_type": "IVF_FLAT",
    "metric_type": "L2",
    "params": {"nlist": 128},
}

hello_milvus.create_index("embeddings", index)

注意1

# We are going to create an IVF_FLAT index for hello_milvus collection.
# create_index() can only be applied to `FloatVector` and `BinaryVector` fields.

Vector indexes are an organizational unit of metadata used to accelerate vector similarity search. Without index built on vectors, Milvus will perform a brute-force search by default

注意2

Current release of Milvus only supports index on vector field. Future releases will support index on scalar field.
By default, Milvus does not index a segment with less than 1,024 rows. To change this parameter, configure rootCoord.minSegmentSizeToEnableIndex in milvus.yaml.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值