58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# from pymilvus import Collection, utility, connections, db
|
|
# from pymilvus import CollectionSchema, FieldSchema, DataType
|
|
# from pymilvus import Collection, db, connections
|
|
|
|
# conn = connections.connect(host="172.18.127.124", port=19530)
|
|
# # database = db.create_database("sample_db")
|
|
# print(db.list_database())
|
|
|
|
# db.using_database("sample_db")
|
|
|
|
# # m_id = FieldSchema(name="m_id", dtype=DataType.INT64, is_primary=True,)
|
|
# # embeding = FieldSchema(name="embeding", dtype=DataType.FLOAT_VECTOR, dim=768,)
|
|
# # count = FieldSchema(name="count", dtype=DataType.INT64,)
|
|
# # desc = FieldSchema(name="desc", dtype=DataType.VARCHAR, max_length=256,)
|
|
# # schema = CollectionSchema(
|
|
# # fields=[m_id, embeding, desc, count],
|
|
# # description="Test embeding search",
|
|
# # enable_dynamic_field=True
|
|
# # )
|
|
|
|
# # collection_name = "word_vector"
|
|
# # collection = Collection(name=collection_name, schema=schema, using='default', shards_num=2)
|
|
|
|
# index_params = {
|
|
# "metric_type": "IP",
|
|
# "index_type": "IVF_FLAT",
|
|
# "params": {"nlist": 1024}
|
|
# }
|
|
|
|
# collection = Collection("word_vector")
|
|
# collection.create_index(
|
|
# field_name="embeding",
|
|
# index_params=index_params
|
|
# )
|
|
|
|
# utility.index_building_progress("word_vector")
|
|
|
|
|
|
from pymilvus import Collection, db, connections
|
|
import numpy as np
|
|
|
|
conn = connections.connect(host="172.18.107.78", port=19530)
|
|
database = db.create_database("XIAN")
|
|
print(db.list_database())
|
|
# db.using_database("sample_db")
|
|
# coll_name = 'word_vector'
|
|
|
|
# mids, embedings, counts, descs = [], [], [], []
|
|
# data_num = 100
|
|
# for idx in range(0, data_num):
|
|
# mids.append(idx)
|
|
# embedings.append(np.random.normal(0, 0.1, 768).tolist())
|
|
# descs.append(f'random num {idx}')
|
|
# counts.append(idx)
|
|
|
|
# collection = Collection(coll_name)
|
|
# mr = collection.insert([mids, embedings, descs, counts])
|
|
# print(mr) |