Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
d909af15
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d909af15
编写于
8月 13, 2021
作者:
Z
zhuwenxing
提交者:
GitHub
8月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Set common var 'vectors' as a global var and add a search test case (#7096)
Signed-off-by:
N
zhuwenxing
<
wenxing.zhu@zilliz.com
>
上级
a0faf3d0
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
31 addition
and
27 deletion
+31
-27
tests20/python_client/testcases/test_search.py
tests20/python_client/testcases/test_search.py
+31
-27
未找到文件。
tests20/python_client/testcases/test_search.py
浏览文件 @
d909af15
...
...
@@ -25,7 +25,7 @@ default_search_field = ct.default_float_vec_field_name
default_search_params
=
ct
.
default_search_params
default_int64_field_name
=
ct
.
default_int64_field_name
default_float_field_name
=
ct
.
default_float_field_name
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
class
TestCollectionSearchInvalid
(
TestcaseBase
):
""" Test case of search interface """
...
...
@@ -111,7 +111,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
log
.
info
(
"test_search_no_connection: removed connection"
)
# 3. search without connection
log
.
info
(
"test_search_no_connection: searching without connection"
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
...
...
@@ -134,7 +133,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
.
drop
()
# 3. Search without collection
log
.
info
(
"test_search_no_collection: Searching without collection "
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
,
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -211,7 +209,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
invalid_search_field
=
get_invalid_fields_type
log
.
info
(
"test_search_param_invalid_field_type: searching with "
"invalid field: %s"
%
invalid_search_field
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
invalid_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -232,7 +229,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
invalid_search_field
=
get_invalid_fields_value
log
.
info
(
"test_search_param_invalid_field_value: searching with "
"invalid field: %s"
%
invalid_search_field
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
invalid_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -252,7 +248,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
# 2. search with invalid metric_type
log
.
info
(
"test_search_param_invalid_metric_type: searching with invalid metric_type"
)
invalid_metric
=
get_invalid_metric_type
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
search_params
=
{
"metric_type"
:
invalid_metric
,
"params"
:
{
"nprobe"
:
10
}}
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
search_params
,
default_limit
,
default_search_exp
,
...
...
@@ -282,7 +277,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
.
load
()
# 3. search
invalid_search_params
=
cf
.
gen_invaild_search_params_type
()
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
for
invalid_search_param
in
invalid_search_params
:
if
index
==
invalid_search_param
[
"index_type"
]:
search_params
=
{
"metric_type"
:
"L2"
,
"params"
:
invalid_search_param
[
"search_params"
]}
...
...
@@ -306,7 +300,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
invalid_limit
=
get_invalid_limit
log
.
info
(
"test_search_param_invalid_limit_type: searching with "
"invalid limit: %s"
%
invalid_limit
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
invalid_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -326,7 +319,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
# 2. search with invalid limit (topK)
log
.
info
(
"test_search_param_invalid_limit: searching with "
"invalid limit (topK) = %s"
%
limit
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
err_msg
=
"limit %d is too large!"
%
limit
if
limit
==
0
:
err_msg
=
"`limit` value 0 is illegal"
...
...
@@ -349,7 +341,7 @@ class TestCollectionSearchInvalid(TestcaseBase):
invalid_search_expr
=
get_invalid_expr_type
log
.
info
(
"test_search_param_invalid_expr_type: searching with "
"invalid expr: {}"
.
format
(
invalid_search_expr
))
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
invalid_search_expr
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -369,7 +361,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
invalid_search_expr
=
get_invalid_expr_value
log
.
info
(
"test_search_param_invalid_expr_value: searching with "
"invalid expr: %s"
%
invalid_search_expr
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
invalid_search_expr
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -386,7 +377,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
)[
0
]
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
# 2. search the invalid partition
partition_name
=
get_invalid_partition
err_msg
=
"`partition_name_array` value {} is illegal"
.
format
(
partition_name
)
...
...
@@ -409,7 +399,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
log
.
info
(
"test_search_with_output_fields_invalid_type: Searching collection %s"
%
collection_w
.
name
)
output_fields
=
get_invalid_output_fields
err_msg
=
"`output_fields` value {} is illegal"
.
format
(
output_fields
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
output_fields
=
output_fields
,
...
...
@@ -432,7 +421,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
.
release
()
# 3. Search the released collection
log
.
info
(
"test_search_release_collection: Searching without collection "
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
,
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
err_res
,
...
...
@@ -460,7 +448,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
# 3. Search the released partition
log
.
info
(
"test_search_release_partition: Searching specifying the released partition"
)
limit
=
10
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
,
default_search_field
,
default_search_params
,
limit
,
default_search_exp
,
[
par_name
],
...
...
@@ -480,7 +467,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
# 2. search collection without data before load
log
.
info
(
"test_search_with_empty_collection: Searching empty collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
err_msg
=
"collection"
+
collection_w
.
name
+
"was not loaded into memory"
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
timeout
=
1
,
...
...
@@ -517,7 +503,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
.
load
()
# 3. search after delete partitions
log
.
info
(
"test_search_partition_deleted: searching deleted partition"
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
[
deleted_par_name
],
...
...
@@ -571,7 +556,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
"""
# 1. initialize with data
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
# 2. create index
default_index
=
{
"index_type"
:
"IVF_FLAT"
,
"params"
:
{
"nlist"
:
128
},
"metric_type"
:
"L2"
}
collection_w
.
create_index
(
"float_vector"
,
default_index
)
...
...
@@ -633,7 +617,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
,
_
,
_
,
insert_ids
=
self
.
init_collection_general
(
prefix
,
True
)
# 2. search
log
.
info
(
"test_search_with_output_fields_not_exist: Searching collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
output_fields
=
[
"int63"
],
...
...
@@ -654,7 +637,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
# 2. search
log
.
info
(
"test_search_output_field_vector: Searching collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
output_fields
=
output_fields
,
...
...
@@ -674,7 +656,6 @@ class TestCollectionSearchInvalid(TestcaseBase):
collection_w
=
self
.
init_collection_general
(
prefix
,
True
)[
0
]
# 2. search
log
.
info
(
"test_search_output_field_vector: Searching collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
output_fields
=
output_fields
,
...
...
@@ -732,6 +713,29 @@ class TestCollectionSearch(TestcaseBase):
"ids"
:
insert_ids
,
"limit"
:
default_limit
})
@
pytest
.
mark
.
tag
(
CaseLabel
.
L0
)
def
test_search_with_hit_vectors
(
self
,
nq
,
dim
,
auto_id
):
"""
target: test search with vectors in collections
method: create connections,collection insert and search vectors in collections
expected: search successfully with limit(topK) and can be hit at top 1 (min distance is 0)
"""
collection_w
,
_vectors
,
_
,
insert_ids
=
\
self
.
init_collection_general
(
prefix
,
True
,
auto_id
=
auto_id
,
dim
=
dim
)
# get vectors that inserted into collection
vectors
=
np
.
array
(
_vectors
[
0
]).
tolist
()
vectors
=
[
vectors
[
i
][
-
1
]
for
i
in
range
(
nq
)]
search_res
,
_
=
collection_w
.
search
(
vectors
[:
nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
check_task
=
CheckTasks
.
check_search_results
,
check_items
=
{
"nq"
:
nq
,
"ids"
:
insert_ids
,
"limit"
:
default_limit
})
for
hits
in
search_res
:
# verify that top 1 hit is itself,so min distance is 0
assert
hits
.
distances
[
0
]
==
0.0
@
pytest
.
mark
.
tags
(
CaseLabel
.
L1
)
def
test_search_with_empty_vectors
(
self
,
dim
,
auto_id
,
_async
):
"""
...
...
@@ -1272,7 +1276,7 @@ class TestCollectionSearch(TestcaseBase):
partition_num
=
1
,
auto_id
=
auto_id
,
is_index
=
True
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
# 2. create index
default_index
=
{
"index_type"
:
"IVF_FLAT"
,
"params"
:
{
"nlist"
:
128
},
"metric_type"
:
"L2"
}
collection_w
.
create_index
(
"float_vector"
,
default_index
)
...
...
@@ -1643,7 +1647,7 @@ class TestCollectionSearch(TestcaseBase):
auto_id
=
auto_id
)
# 2. search
log
.
info
(
"test_search_with_output_field: Searching collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
res
=
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
_async
=
_async
,
...
...
@@ -1703,7 +1707,7 @@ class TestCollectionSearch(TestcaseBase):
auto_id
=
auto_id
)
# 2. search
log
.
info
(
"test_search_with_output_field_wildcard: Searching collection %s"
%
collection_w
.
name
)
vectors
=
[[
random
.
random
()
for
_
in
range
(
default_dim
)]
for
_
in
range
(
default_nq
)]
res
=
collection_w
.
search
(
vectors
[:
default_nq
],
default_search_field
,
default_search_params
,
default_limit
,
default_search_exp
,
_async
=
_async
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录