参考文档
开发案例: 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.
|