Код: Выделить всё
import numpy as np
from pymilvus import connections, Collection, CollectionSchema, FieldSchema, DataType
connections.connect(alias='default',host='localhost', port='19530')
# Define the schema
schema = CollectionSchema([FieldSchema("id", DataType.INT64, is_primary=True, max_length=100),
FieldSchema("vector", DataType.FLOAT_VECTOR, dim=2)])
# Create a collection
collection = Collection("test_collection", schema)
# Insert data
data = [{"id":i, "vector": np.array([i, i],dtype=np.float32)} for i in range(10)]
collection.insert(data)
# Flush data
collection.flush()
# Disconnect from the server
connections.disconnect(alias='default')
Код: Выделить всё
from pymilvus import Collection, connections, db, utility
def get_info (host: str = "localhost", port: str = "19530"):
# Connect to Milvus (replace with your connection details)
connections.connect(alias="default", host=host, port=port) # Replace with your connection parameters
# Print the list of databases and collections
db_list = db.list_database()
for db_name in db_list:
print(f"Database: {db_name}")
collection_list = utility.list_collections(using=db_name)
if len(collection_list) == 0:
print(" No collections")
for collection_name in collection_list:
print(f" Collection: {collection_name}")
temp_collection = Collection(name=collection_name)
for info in temp_collection.describe():
print(f" {info}: {temp_collection.describe()[info]}")
print(f" Number of entities: {temp_collection.num_entities}")
# Disconnect from Milvus
connections.disconnect(alias='default')
if __name__ == "__main__":
get_info()
Код: Выделить всё
$ python test_milvus.py
$ python milvus_info.py
Database: default
Collection: test_collection
collection_name: test_collection
auto_id: False
num_shards: 1
description:
fields: [{'field_id': 100, 'name': 'id', 'description': '', 'type': , 'params': {}, 'is_primary': True}, {'field_id': 101, 'name': 'vector', 'description': '', 'type': , 'params': {'dim': 2}}]
aliases: []
collection_id: 450687678279804785
consistency_level: 2
properties: {}
num_partitions: 1
enable_dynamic_field: False
Number of entities: 10
Однако, если я снова запущу `test_milvus.py', количество объектов увеличивается до 20, хотя новые векторы не добавляются:
Код: Выделить всё
$ python test_milvus.py
$ python milvus_info.py
Database: default
Collection: test_collection
collection_name: test_collection
auto_id: False
num_shards: 1
description:
fields: [{'field_id': 100, 'name': 'id', 'description': '', 'type': , 'params': {}, 'is_primary': True}, {'field_id': 101, 'name': 'vector', 'description': '', 'type': , 'params': {'dim': 2}}]
aliases: []
collection_id: 450687678279804785
consistency_level: 2
properties: {}
num_partitions: 1
enable_dynamic_field: False
Number of entities: 20
Подробнее здесь: https://stackoverflow.com/questions/786 ... collection