-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lixinguo <xinguo.li@zilliz.com>
- Loading branch information
lixinguo
committed
Jun 27, 2024
1 parent
943dc81
commit cc917b0
Showing
2 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pymilvus import CollectionSchema, FieldSchema, Collection, connections, DataType, Partition, utility | ||
import numpy as np | ||
import random | ||
import time | ||
|
||
# 建collection ————————————————————————————————————————————————————————————————————————————————————————————— | ||
dim = 128 | ||
int64_field = FieldSchema(name="int64", dtype=DataType.INT64, is_primary=True) | ||
float_field = FieldSchema(name="float", dtype=DataType.FLOAT) | ||
float_vector = FieldSchema( | ||
name="float_vector", dtype=DataType.FLOAT_VECTOR, dim=dim) | ||
schema = CollectionSchema(fields=[int64_field, float_field, float_vector]) | ||
connections.connect() | ||
utility.drop_collection("test_upsert") | ||
collection = Collection("test_upsert", schema=schema) | ||
|
||
# 建partition 和插入数据 ———————————————————————————————————————————————————————————————————————————————————— | ||
# partition = Partition(collection, "_default") | ||
# vectors = [[random.random() for _ in range(dim)] for _ in range(1500)] | ||
# partition.insert([[i for i in range(1500)], [np.float32(i) | ||
# for i in range(1500)], vectors]) | ||
|
||
index = {"index_type": "DISKANN", "metric_type": "L2", "params": {}} | ||
# collection.create_index("float_vector", index) | ||
# collection.load() # partition_new.load() | ||
|
||
nb = 17 | ||
vectors = [[random.random() for _ in range(dim)] for _ in range(nb)] | ||
data = [[(i+10000) for i in range(nb)], [np.float32(i+10000) | ||
for i in range(nb)], vectors] | ||
collection.insert(data=data) | ||
collection.create_index("float_vector", index) | ||
collection.load() | ||
|
||
search_params = {"metric_type": "L2", "params": {"search_list": 10}} | ||
output_fields = ["int64", "float", "float_vector"] | ||
res = collection.search(vectors, "float_vector", | ||
search_params, limit=10, | ||
output_fields=output_fields) | ||
|
||
print(len(res)) |