chore: import upstream snapshot with attribution
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
from pymilvus import DataType
|
||||
from common import common_type as ct
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class DISKANN:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
# search_list_size
|
||||
# Type: Integer Range: [1, int_max]
|
||||
# Default value: 100
|
||||
{"description": "Minimum Boundary Test", "params": {"search_list_size": 1}, "expected": success},
|
||||
{"description": "Large Value Test", "params": {"search_list_size": 10000}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"search_list_size": -1}, "expected": success},
|
||||
{"description": "String Type Test", "params": {"search_list_size": "100"}, "expected": success},
|
||||
{"description": "Float Type Test", "params": {"search_list_size": 100.0}, "expected": success},
|
||||
{"description": "Boolean Type Test", "params": {"search_list_size": True}, "expected": success},
|
||||
{"description": "None Type Test", "params": {"search_list_size": None}, "expected": success},
|
||||
# search_cache_budget_gb_ratio
|
||||
# Type: Float Range: [0.0, 0.3)
|
||||
# Default value: 0.10
|
||||
# TODO: runt he minium bourndary test after issue #43176 fixed
|
||||
# {"description": "Minimum Boundary Test", "params": {"search_cache_budget_gb_ratio": 0.0}, "expected": success},
|
||||
{"description": "Maximum Boundary Test", "params": {"search_cache_budget_gb_ratio": 0.3}, "expected": success},
|
||||
{"description": "Default value Test", "params": {"search_cache_budget_gb_ratio": 0.1}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"search_cache_budget_gb_ratio": -0.1}, "expected": success},
|
||||
{"description": "Out of Range Test - Too Large", "params": {"search_cache_budget_gb_ratio": 0.31}, "expected": success},
|
||||
{"description": "String Type Test", "params": {"search_cache_budget_gb_ratio": "0.2"}, "expected": success},
|
||||
{"description": "Boolean Type Test", "params": {"search_cache_budget_gb_ratio": True}, "expected": success},
|
||||
{"description": "None Type Test", "params": {"search_cache_budget_gb_ratio": None}, "expected": success},
|
||||
# pq_code_budget_gb_ratio
|
||||
# Type: Float Range: (0.0, 0.25]
|
||||
# Default value: 0.125
|
||||
{"description": "Minimum Boundary Test", "params": {"pq_code_budget_gb_ratio": 0.0001}, "expected": success},
|
||||
{"description": "Maximum Boundary Test", "params": {"pq_code_budget_gb_ratio": 0.25}, "expected": success},
|
||||
{"description": "Default value Test", "params": {"pq_code_budget_gb_ratio": 0.125}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"pq_code_budget_gb_ratio": -0.1}, "expected": success},
|
||||
{"description": "Out of Range Test - Too Large", "params": {"pq_code_budget_gb_ratio": 0.26}, "expected": success},
|
||||
{"description": "String Type Test", "params": {"pq_code_budget_gb_ratio": "0.1"}, "expected": success},
|
||||
{"description": "Boolean Type Test", "params": {"pq_code_budget_gb_ratio": True}, "expected": success},
|
||||
{"description": "None Type Test", "params": {"pq_code_budget_gb_ratio": None}, "expected": success},
|
||||
# max_degree
|
||||
# Type: Integer Range: [1, 512]
|
||||
# Default value: 56
|
||||
{"description": "Minimum Boundary Test", "params": {"max_degree": 1}, "expected": success},
|
||||
{"description": "Maximum Boundary Test", "params": {"max_degree": 512}, "expected": success},
|
||||
{"description": "Default value Test", "params": {"max_degree": 56}, "expected": success},
|
||||
{"description": "Large Value Test", "params": {"max_degree": 128}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"max_degree": -1}, "expected": success},
|
||||
{"description": "String Type Test", "params": {"max_degree": "32"}, "expected": success},
|
||||
{"description": "Float Type Test", "params": {"max_degree": 32.0}, "expected": success},
|
||||
{"description": "Boolean Type Test", "params": {"max_degree": True}, "expected": success},
|
||||
{"description": "None Type Test", "params": {"max_degree": None}, "expected": success},
|
||||
# 组合参数
|
||||
{"description": "Optimal Performance Combination Test", "params": {"search_list_size": 100, "beamwidth": 10, "search_cache_budget_gb_ratio": 0.5, "pq_code_budget_gb_ratio": 0.5}, "expected": success},
|
||||
{"description": "empty dict params", "params": {}, "expected": success},
|
||||
{"description": "not_defined_param in the dict params", "params": {"search_list_size": 100, "not_defined_param": "nothing"}, "expected": success},
|
||||
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# beam_width_ratio
|
||||
# Type: Float Range: [1, max(128 / CPU number, 16)]
|
||||
# Default value: 4.0
|
||||
{"description": "Minimum Boundary Test", "params": {"beam_width_ratio": 1.0}, "expected": success},
|
||||
{"description": "Maximum Boundary Test", "params": {"beam_width_ratio": 16.0}, "expected": success},
|
||||
{"description": "Default value Test", "params": {"beam_width_ratio": 4.0}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"beam_width_ratio": -0.1}, "expected": success},
|
||||
{"description": "Out of Range Test - Too Large", "params": {"beam_width_ratio": 17.0}, "expected": success},
|
||||
{"description": "String Type Test", "params": {"beam_width_ratio": "2.0"}, "expected": success},
|
||||
{"description": "Boolean Type Test", "params": {"beam_width_ratio": True}, "expected": success},
|
||||
{"description": "None Type Test", "params": {"beam_width_ratio": None}, "expected": success},
|
||||
# search_list_size
|
||||
# Type: Integer Range: [1, int_max]
|
||||
# Default value: 100
|
||||
{"description": "Minimum Boundary Test", "params": {"search_list_size": 1}, "expected": {"err_code": 999, "err_msg": "search_list_size(1) should be larger than k(10)"}},
|
||||
{"description": "Large Value Test", "params": {"search_list_size": 1000}, "expected": success},
|
||||
{"description": "Default value Test", "params": {"search_list_size": 100}, "expected": success},
|
||||
{"description": "Out of Range Test - Negative", "params": {"search_list_size": -1}, "expected": {"err_code": 999, "err_msg": "param 'search_list_size' (-1) should be in range [1, 2147483647]"}},
|
||||
{"description": "String Type Test", "params": {"search_list_size": "100"}, "expected": success},
|
||||
{"description": "Float Type Test", "params": {"search_list_size": 100.0}, "expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'search_list_size' (100.0) should be integer"}},
|
||||
{"description": "Boolean Type Test", "params": {"search_list_size": True}, "expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'search_list_size' (true) should be integer"}},
|
||||
{"description": "None Type Test", "params": {"search_list_size": None}, "expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'search_list_size' (null) should be integer"}},
|
||||
# mix params
|
||||
{"description": "mix params", "params": {"search_list_size": 100, "beam_width_ratio": 0.5}, "expected": success},
|
||||
{"description": "mix params", "params": {}, "expected": success},
|
||||
]
|
||||
@@ -0,0 +1,103 @@
|
||||
from pymilvus import DataType
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class FAISS:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.BINARY_VECTOR,
|
||||
]
|
||||
|
||||
supported_metrics = ["L2", "IP", "COSINE"]
|
||||
|
||||
build_params = [
|
||||
{
|
||||
"description": "Flat float index",
|
||||
"params": {"faiss_index_name": "Flat"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "IVF Flat float index",
|
||||
"params": {"faiss_index_name": "IVF64,Flat"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "HNSW Flat float index",
|
||||
"params": {"faiss_index_name": "HNSW16,Flat"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "OPQ IVF PQ float index",
|
||||
"params": {"faiss_index_name": "OPQ16,IVF64,PQ16x4"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "IVF PQ RFlat float index",
|
||||
"params": {"faiss_index_name": "IVF64,PQ8x4,RFlat"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "PQ float index",
|
||||
"params": {"faiss_index_name": "PQ8x4"},
|
||||
"searchable": False,
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "Binary flat index",
|
||||
"params": {"faiss_index_name": "BFlat"},
|
||||
"vector_data_type": DataType.BINARY_VECTOR,
|
||||
"metric_type": "HAMMING",
|
||||
"expected": success,
|
||||
},
|
||||
]
|
||||
|
||||
search_params = [
|
||||
{
|
||||
"description": "IVF Flat nprobe",
|
||||
"build_params": {"faiss_index_name": "IVF64,Flat"},
|
||||
"search_params": {"nprobe": 8},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "IVF Flat stringified nprobe",
|
||||
"build_params": {"faiss_index_name": "IVF64,Flat"},
|
||||
"search_params": {"nprobe": "8"},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "IVF Flat invalid nprobe string",
|
||||
"build_params": {"faiss_index_name": "IVF64,Flat"},
|
||||
"search_params": {"nprobe": "invalid"},
|
||||
"expected": {"err_code": 999, "err_msg": "expects a number"},
|
||||
},
|
||||
{
|
||||
"description": "HNSW Flat efSearch",
|
||||
"build_params": {"faiss_index_name": "HNSW16,Flat"},
|
||||
"search_params": {"efSearch": 64},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "HNSW Flat invalid efSearch string",
|
||||
"build_params": {"faiss_index_name": "HNSW16,Flat"},
|
||||
"search_params": {"efSearch": "invalid"},
|
||||
"expected": {"err_code": 999, "err_msg": "expects a number"},
|
||||
},
|
||||
{
|
||||
"description": "IVF PQ RFlat rerank",
|
||||
"build_params": {"faiss_index_name": "IVF64,PQ8x4,RFlat"},
|
||||
"search_params": {"nprobe": 8, "k_factor": 4},
|
||||
"expected": success,
|
||||
},
|
||||
{
|
||||
"description": "IVF PQ RFlat invalid k_factor string",
|
||||
"build_params": {"faiss_index_name": "IVF64,PQ8x4,RFlat"},
|
||||
"search_params": {"nprobe": 8, "k_factor": "invalid"},
|
||||
"expected": {"err_code": 999, "err_msg": "expects a number"},
|
||||
},
|
||||
]
|
||||
|
||||
metric_factories = [
|
||||
{"faiss_index_name": "IVF64,Flat"},
|
||||
{"faiss_index_name": "HNSW16,Flat"},
|
||||
]
|
||||
@@ -0,0 +1,177 @@
|
||||
from pymilvus import DataType
|
||||
from common import common_type as ct
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class HNSW:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR,
|
||||
DataType.INT8_VECTOR,
|
||||
DataType.BINARY_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
# M params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"M": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"M": 2048},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"M": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'M' (-1) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Too Large",
|
||||
"params": {"M": 2049},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'M' (2049) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"M": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"M": 16.0},
|
||||
"expected": {"err_code": 999, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"M": True},
|
||||
"expected": {"err_code": 999, "err_msg": "invalid integer value, key: 'M', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"M": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"M": [16]},
|
||||
"expected": {"err_code": 999, "err_msg": "invalid integer value, key: 'M', value: '[16]': invalid parameter"}
|
||||
},
|
||||
# efConstruction params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"efConstruction": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"efConstruction": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"efConstruction": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'efConstruction' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"efConstruction": "100"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"efConstruction": 100.0},
|
||||
"expected": {"err_code": 999, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"efConstruction": True},
|
||||
"expected": {"err_code": 999, "err_msg": "invalid integer value, key: 'efConstruction', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"efConstruction": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"efConstruction": [100]},
|
||||
"expected": {"err_code": 999, "err_msg": "invalid integer value, key: 'efConstruction', value: '[100]': invalid parameter"}
|
||||
},
|
||||
# combination params test
|
||||
{
|
||||
"description": "Optimal Performance Combination Test",
|
||||
"params": {"M": 16, "efConstruction": 200},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "not_defined_param in the dict params",
|
||||
"params": {"M": 16, "efConstruction": 200, "not_defined_param": "nothing"},
|
||||
"expected": success
|
||||
},
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# ef params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"ef": 1},
|
||||
"expected": {"err_code": 999, "err_msg": "ef(1) should be larger than k(10)"} # assume default limit=10
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"ef": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"ef": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'ef' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"ef": "32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"ef": 32.0},
|
||||
"expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'ef' (32.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"ef": True},
|
||||
"expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'ef' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"ef": None},
|
||||
"expected": {"err_code": 999, "err_msg": "Type conflict in json: param 'ef' (null) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"ef": [32]},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'ef' ([32]) should be integer"}
|
||||
},
|
||||
# combination params test
|
||||
{
|
||||
"description": "Optimal Performance Combination Test",
|
||||
"params": {"ef": 64},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,529 @@
|
||||
import pytest
|
||||
from pymilvus import DataType
|
||||
from common import common_type as ct
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class HNSW_PQ:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR,
|
||||
DataType.INT8_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
|
||||
# M params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"M": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"M": 2048},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"M": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (-1) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Too Large",
|
||||
"params": {"M": 2049},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (2049) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"M": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"M": 16.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"M": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"M": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"M": [16]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: '[16]': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Nested dict in params",
|
||||
"params": {"M": {"value": 16}},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value"}
|
||||
},
|
||||
# efConstruction params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"efConstruction": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"efConstruction": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"efConstruction": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'efConstruction' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"efConstruction": "100"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"efConstruction": 100.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"efConstruction": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"efConstruction": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"efConstruction": [100]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: '[100]': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Nested List in Params",
|
||||
"params": {"efConstruction": [[100]]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value"}
|
||||
},
|
||||
# m params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"m": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Half of Dimension Value Test",
|
||||
"params": {"m": 64},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test (Dimension)",
|
||||
"params": {"m": 128},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"m": -1},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'm' (-1) should be in range [1, 65536]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Larger Value Test",
|
||||
"params": {"m": 256},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "The dimension of the vector (dim) should be a multiple of the number of subquantizers (m)."
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Not Divisible by Dimension Value Test",
|
||||
"params": {"m": 7},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "The dimension of the vector (dim) should be a multiple of the number of subquantizers (m)."
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"m": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"m": 16.0},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "wrong data type in json, key: 'm', value: '16.0': invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"m": True},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"m": [16]},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"m": None},
|
||||
"expected": success
|
||||
},
|
||||
# nbits params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"nbits": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test (doc:24) ",
|
||||
"params": {"nbits": 10},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Default Value Test",
|
||||
"params": {"nbits": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"nbits": -1},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nbits' (-1) should be in range [1, 24]: invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"nbits": 25},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nbits' (25) should be in range [1, 24]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"nbits": "8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"nbits": 8.0},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "wrong data type in json, key: 'nbits', value: '8.0'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"nbits": True},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"nbits": [8]},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"nbits": None},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
|
||||
# refine params test
|
||||
{
|
||||
"description": "refine = True",
|
||||
"params": {"refine": True},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"refine": "true"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid String Type Test",
|
||||
"params": {"refine": "test"},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine": [True]},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine": None},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
# refine_type params test
|
||||
{
|
||||
"description": "Valid refine_type - SQ6",
|
||||
"params": {"refine_type": "SQ6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - SQ8",
|
||||
"params": {"refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - BF16",
|
||||
"params": {"refine_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP16",
|
||||
"params": {"refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP32",
|
||||
"params": {"refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - unknown value",
|
||||
"params": {"refine_type": "INT8"},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : INT8, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine_type": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine_type": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1.0, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_type": ["FP16"]},
|
||||
"expected": {"err_code": 1100, "err_msg": "['FP16'], optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_type lower precision than sq_type but refine disabled",
|
||||
"params": {"sq_type": "FP16", "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_type lower than sq_type",
|
||||
"params": {"sq_type": "FP16", "refine_type": "SQ8", "refine": True},
|
||||
"expected": success
|
||||
},
|
||||
# combination params test
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "All optional parameters None",
|
||||
"params": {"M": None, "efConstruction": None, "m": None, "nbits":None, "refine": None, "refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Typical valid combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 64, "nbits": 8,"refine": True, "refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Refine Disabled",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 32, "nbits": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum Boundary Combination",
|
||||
"params": {"M": 2, "efConstruction": 1, "m": 1, "nbits": 1, "refine": True, "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
pytest.param(
|
||||
{
|
||||
"description": "Maximum Boundary Combination",
|
||||
"params": {"M": 2048, "efConstruction": 10000, "m": 128, "nbits": 10, "refine": True, "refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
marks=pytest.mark.skip(reason="Flaky in CI: index build with max params (M=2048, efConstruction=10000) "
|
||||
"takes ~30s but exceeds 120s client timeout under CI resource contention")
|
||||
),
|
||||
{
|
||||
"description": "Unknown extra parameter in combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 32, "nbits": 8, "refine": True, "refine_type": "FP16", "unknown_param": "nothing"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (M + m only)",
|
||||
"params": {"M": 32, "m": 32},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (efConstruction + nbits only)",
|
||||
"params": {"efConstruction": 500,"nbits": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid PQ m (not divisor of dimension)",
|
||||
"params": {"M": 16,"efConstruction": 200,"m": 7, "nbits": 8, "refine": True, "refine_type": "FP32"},
|
||||
"expected": {"err_code": 999, "err_msg": "The dimension of the vector (dim) should be a multiple of the number of subquantizers (m)."}
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# ef params test
|
||||
{
|
||||
"description": "Boundary Test - ef equals k",
|
||||
"params": {"ef": 10},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"ef": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"ef": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"ef": -1},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"ef": "32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"ef": 32.0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (32.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"ef": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"ef": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (null) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"ef": [32]},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' ([32]) should be integer"}
|
||||
},
|
||||
|
||||
# refine_k params test
|
||||
{
|
||||
"description": "refine_k default boundary",
|
||||
"params": {"refine_k": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k valid float",
|
||||
"params": {"refine_k": 2.5},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k out of range",
|
||||
"params": {"refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k integer type",
|
||||
"params": {"refine_k": 20},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"refine_k": "2.5"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty string type",
|
||||
"params": {"refine_k": ""},
|
||||
"expected": {"err_code": 65535, "err_msg": "invalid float value"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k boolean type",
|
||||
"params": {"refine_k": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'refine_k' (true) should be a number"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"refine_k": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_k": [15]},
|
||||
"expected": {"err_code": 65535, "err_msg":"Type conflict in json"}
|
||||
},
|
||||
|
||||
# combination params test
|
||||
{
|
||||
"description": "HNSW ef + SQ refine_k combination",
|
||||
"params": {"ef": 64, "refine_k": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid ef with invalid refine_k",
|
||||
"params": {"ef": 64, "refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg":"Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
]
|
||||
@@ -0,0 +1,591 @@
|
||||
from pymilvus import DataType
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class HNSW_PRQ:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR,
|
||||
DataType.INT8_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
|
||||
# M params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"M": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"M": 2048},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"M": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (-1) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Too Large",
|
||||
"params": {"M": 2049},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (2049) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"M": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"M": 16.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"M": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"M": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"M": [16]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: '[16]': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Nested dict in params",
|
||||
"params": {"M": {"value": 16}},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value"}
|
||||
},
|
||||
# efConstruction params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"efConstruction": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"efConstruction": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"efConstruction": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'efConstruction' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"efConstruction": "100"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"efConstruction": 100.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"efConstruction": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"efConstruction": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"efConstruction": [100]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: '[100]': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Nested List in Params",
|
||||
"params": {"efConstruction": [[100]]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value"}
|
||||
},
|
||||
# m params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"m": 1},
|
||||
"expected": success
|
||||
},
|
||||
# timeout
|
||||
# {
|
||||
# "description": "Half of Dimension Value Test",
|
||||
# "params": {"m": 64},
|
||||
# "expected": success
|
||||
# },
|
||||
# timeout
|
||||
# {
|
||||
# "description": "Maximum Boundary Test (Dimension)",
|
||||
# "params": {"m": 128},
|
||||
# "expected": success
|
||||
# },
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"m": -1},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'm' (-1) should be in range [1, 65536]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Larger Value Test",
|
||||
"params": {"m": 256},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "The dimension of a vector (dim) should be a multiple of the number of subquantizers (m)."
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Not Divisible by Dimension Value Test",
|
||||
"params": {"m": 7},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "The dimension of a vector (dim) should be a multiple of the number of subquantizers (m)."
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"m": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"m": 16.0},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "wrong data type in json, key: 'm', value: '16.0': invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"m": True},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"m": [16]},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"m": None},
|
||||
"expected": success
|
||||
},
|
||||
# nbits params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"nbits": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Default Value Test",
|
||||
"params": {"nbits": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"nbits": 10},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"nbits": -1},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nbits' (-1) should be in range [1, 24]: invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"nbits": 25},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nbits' (25) should be in range [1, 24]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"nbits": "8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"nbits": 8.0},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "wrong data type in json, key: 'nbits', value: '8.0'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"nbits": True},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"nbits": [8]},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"nbits": None},
|
||||
"expected": success
|
||||
},
|
||||
# nrq params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"nrq": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Default Value Test",
|
||||
"params": {"nrq": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"nrq": 16},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"nrq": -1},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nrq' (-1) should be in range [1, 16]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Larger Value Test",
|
||||
"params": {"nrq": 17},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "Out of range in json: param 'nrq' (17) should be in range [1, 16]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"nrq": "4"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"nrq": 4.0},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "wrong data type in json, key: 'nrq', value: '4.0': invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"nrq": True},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value, key: 'nrq', value: 'True': invalid parameter"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"nrq": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"nrq": [2]},
|
||||
"expected": {
|
||||
"err_code": 1100,
|
||||
"err_msg": "invalid integer value, key: 'nrq', value: '[2]': invalid parameter"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
# refine params test
|
||||
{
|
||||
"description": "refine = True",
|
||||
"params": {"refine": True},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"refine": "true"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid String Type Test",
|
||||
"params": {"refine": "test"},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine": [True]},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine": None},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
# refine_type params test
|
||||
{
|
||||
"description": "Valid refine_type - SQ6",
|
||||
"params": {"refine_type": "SQ6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - SQ8",
|
||||
"params": {"refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - BF16",
|
||||
"params": {"refine_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP16",
|
||||
"params": {"refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP32",
|
||||
"params": {"refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - unknown value",
|
||||
"params": {"refine_type": "INT8"},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : INT8, optional types are [sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine_type": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1, optional types are [sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine_type": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1.0, optional types are [sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_type": ["FP16"]},
|
||||
"expected": {"err_code": 1100, "err_msg": "['FP16'], optional types are [sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_type lower precision than sq_type but refine disabled",
|
||||
"params": {"sq_type": "FP16", "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_type lower than sq_type",
|
||||
"params": {"sq_type": "FP16", "refine_type": "SQ8", "refine": True},
|
||||
"expected": success
|
||||
},
|
||||
# combination params test
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "All optional parameters None",
|
||||
"params": {"M": None, "efConstruction": None, "m": None, "nbits":None, "nrq":None,"refine": None, "refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Typical valid combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 32, "nbits": 8, "nrq":1,"refine": True, "refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Refine Disabled",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 32, "nbits": 8,"nrq": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum Boundary Combination",
|
||||
"params": {"M": 2, "efConstruction": 1, "m": 1, "nbits": 1, "nrq":1, "refine": True, "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Combination",
|
||||
"params": {"M": 2048, "efConstruction": 10000, "m": 128, "nbits": 8, "nrq":1, "refine": True, "refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Unknown extra parameter in combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "m": 32, "nbits": 8, "nrq":1, "refine": True, "refine_type": "FP16", "unknown_param": "nothing"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (M + m only)",
|
||||
"params": {"M": 32, "m": 32},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (efConstruction + nbits only)",
|
||||
"params": {"efConstruction": 500,"nbits": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid m (not divisor of dimension)",
|
||||
"params": {"M": 16,"efConstruction": 200,"m": 7, "nbits": 8, "refine": True, "refine_type": "FP32"},
|
||||
"expected": {"err_code": 1100, "err_msg": "The dimension of a vector (dim) should be a multiple of the number of subquantizers (m)."}
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# ef params test
|
||||
{
|
||||
"description": "Boundary Test - ef equals k",
|
||||
"params": {"ef": 10},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"ef": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"ef": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"ef": -1},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"ef": "32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"ef": 32.0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (32.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"ef": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"ef": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (null) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"ef": [32]},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' ([32]) should be integer"}
|
||||
},
|
||||
|
||||
# refine_k params test
|
||||
{
|
||||
"description": "refine_k default boundary",
|
||||
"params": {"refine_k": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k valid float",
|
||||
"params": {"refine_k": 2.5},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k out of range",
|
||||
"params": {"refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k integer type",
|
||||
"params": {"refine_k": 20},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"refine_k": "2.5"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty string type",
|
||||
"params": {"refine_k": ""},
|
||||
"expected": {"err_code": 65535, "err_msg": "invalid float value"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k boolean type",
|
||||
"params": {"refine_k": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'refine_k' (true) should be a number"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"refine_k": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_k": [15]},
|
||||
"expected": {"err_code": 65535, "err_msg":"Type conflict in json"}
|
||||
},
|
||||
|
||||
# combination params test
|
||||
{
|
||||
"description": "HNSW ef + SQ refine_k combination",
|
||||
"params": {"ef": 64, "refine_k": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid ef with invalid refine_k",
|
||||
"params": {"ef": 64, "refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg":"Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
]
|
||||
@@ -0,0 +1,416 @@
|
||||
from pymilvus import DataType
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class HNSW_SQ:
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR,
|
||||
DataType.INT8_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
# M params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"M": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"M": 2048},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"M": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (-1) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Too Large",
|
||||
"params": {"M": 2049},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'M' (2049) should be in range [2, 2048]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"M": "16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"M": 16.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"M": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"M": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"M": [16]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'M', value: '[16]': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Nested dict in params",
|
||||
"params": {"M": {"value": 16}},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value"}
|
||||
},
|
||||
# efConstruction params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"efConstruction": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"efConstruction": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"efConstruction": -1},
|
||||
"expected": {"err_code": 1100, "err_msg": "param 'efConstruction' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"efConstruction": "100"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"efConstruction": 100.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"efConstruction": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"efConstruction": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"efConstruction": [100]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid integer value, key: 'efConstruction', value: '[100]': invalid parameter"}
|
||||
},
|
||||
|
||||
# sq_type params test
|
||||
{
|
||||
"description": "Valid sq_type - SQ6",
|
||||
"params": {"sq_type": "SQ6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid sq_type - SQ8",
|
||||
"params": {"sq_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid sq_type - BF16",
|
||||
"params": {"sq_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid sq_type - FP16",
|
||||
"params": {"sq_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Unknown String",
|
||||
"params": {"sq_type": "FP32"},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid scalar quantizer type: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"sq_type": 8},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid scalar quantizer type: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"sq_type": 8.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid scalar quantizer type: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"sq_type": True},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid scalar quantizer type: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"sq_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"sq_type": ["SQ8"]},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid scalar quantizer type: invalid parameter"}
|
||||
},
|
||||
|
||||
# refine params test
|
||||
{
|
||||
"description": "refine = True",
|
||||
"params": {"refine": True},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"refine": "true"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"refine": "test"},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine": [True]},
|
||||
"expected": {"err_code": 1100, "err_msg": "should be a boolean: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine": None},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
# refine_type params test
|
||||
{
|
||||
"description": "Valid refine_type - SQ6",
|
||||
"params": {"refine_type": "SQ6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - SQ8",
|
||||
"params": {"refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - BF16",
|
||||
"params": {"refine_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP16",
|
||||
"params": {"refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid refine_type - FP32",
|
||||
"params": {"refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - unknown value",
|
||||
"params": {"refine_type": "INT8"},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : INT8, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine_type": 1},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"refine_type": 1.0},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type : 1.0, optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_type": ["FP16"]},
|
||||
"expected": {"err_code": 1100, "err_msg": "['FP16'], optional types are [sq4u, sq6, sq8, fp16, bf16, fp32, flat]: invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
# combination params test
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "All optional parameters None",
|
||||
"params": {"M": None, "efConstruction": None, "sq_type": None, "refine": None, "refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Typical valid combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "sq_type": "SQ8", "refine": True, "refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum boundary combination",
|
||||
"params": {"M": 2, "efConstruction": 1, "sq_type": "SQ6"},
|
||||
"expected": success,
|
||||
# M=2 + efConstruction=1 produces a poorly connected graph; HNSW does not
|
||||
# guarantee returning topK results under these extreme parameters.
|
||||
"relaxed_limit": True
|
||||
},
|
||||
{
|
||||
"description": "Maximum boundary combination",
|
||||
"params": {"M": 2048, "efConstruction": 10000, "sq_type": "FP16", "refine": True, "refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Unknown extra parameter in combination",
|
||||
"params": {"M": 16, "efConstruction": 200, "sq_type": "SQ8", "refine": True, "refine_type": "FP16", "unknown_param": "nothing"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (M + sq_type only)",
|
||||
"params": {"M": 32, "sq_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Partial parameters set (efConstruction + refine only)",
|
||||
"params": {"efConstruction": 500,"refine": True},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid refine_type using vector data type",
|
||||
"params": {"sq_type": "SQ8", "refine": True, "refine_type": "INT8"},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid refine type"}
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# ef params test
|
||||
{
|
||||
"description": "Boundary Test - ef equals k",
|
||||
"params": {"ef": 10},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"ef": 1},
|
||||
"expected": {"err_code": 65535, "err_msg": "ef(1) should be larger than k(10)"} # assume default limit=10
|
||||
},
|
||||
{
|
||||
"description": "Large Value Test",
|
||||
"params": {"ef": 10000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"ef": -1},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' (-1) should be in range [1, 2147483647]"}
|
||||
},
|
||||
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"ef": "32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"ef": 32.0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (32.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"ef": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"ef": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'ef' (null) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"ef": [32]},
|
||||
"expected": {"err_code": 65535, "err_msg": "param 'ef' ([32]) should be integer"}
|
||||
},
|
||||
|
||||
# refine_k params test
|
||||
{
|
||||
"description": "refine_k default boundary",
|
||||
"params": {"refine_k": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k valid float",
|
||||
"params": {"refine_k": 2.5},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "refine_k out of range",
|
||||
"params": {"refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg": "Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k integer type",
|
||||
"params": {"refine_k": 20},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"refine_k": "2.5"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty string type",
|
||||
"params": {"refine_k": ""},
|
||||
"expected": {"err_code": 65535, "err_msg": "invalid float value"}
|
||||
},
|
||||
{
|
||||
"description": "refine_k boolean type",
|
||||
"params": {"refine_k": True},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json: param 'refine_k' (true) should be a number"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"refine_k": None},
|
||||
"expected": {"err_code": 65535, "err_msg": "Type conflict in json"}
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"refine_k": [15]},
|
||||
"expected": {"err_code": 65535, "err_msg":"Type conflict in json"}
|
||||
},
|
||||
|
||||
# combination params test
|
||||
{
|
||||
"description": "HNSW ef + SQ refine_k combination",
|
||||
"params": {"ef": 64, "refine_k": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Valid ef with invalid refine_k",
|
||||
"params": {"ef": 64, "refine_k": 0},
|
||||
"expected": {"err_code": 65535, "err_msg":"Out of range in json"}
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
]
|
||||
@@ -0,0 +1,355 @@
|
||||
from pymilvus import DataType
|
||||
from common import common_type as ct
|
||||
|
||||
success = "success"
|
||||
|
||||
|
||||
class IVF_RABITQ:
|
||||
|
||||
supported_vector_types = [
|
||||
DataType.FLOAT_VECTOR,
|
||||
DataType.FLOAT16_VECTOR,
|
||||
DataType.BFLOAT16_VECTOR
|
||||
]
|
||||
|
||||
supported_metrics = ['L2', 'IP', 'COSINE']
|
||||
|
||||
build_params = [
|
||||
# nlist params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"nlist": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Boundary Test",
|
||||
"params": {"nlist": 65536},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Negative",
|
||||
"params": {"nlist": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'nlist' (-1) should be in range [1, 65536]"}
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test - Too Large",
|
||||
"params": {"nlist": 65537},
|
||||
"expected": {"err_code": 999, "err_msg": "param 'nlist' (65537) should be in range [1, 65536]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test will ignore the wrong type",
|
||||
"params": {"nlist": "128"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"nlist": 128.0},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "wrong data type in json"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"nlist": True},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid integer value, key: 'nlist', value: 'True': invalid parameter"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test, use default value",
|
||||
"params": {"nlist": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "List Type Test",
|
||||
"params": {"nlist": [128]},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid integer value, key: 'nlist', value: '[128]': invalid parameter"}
|
||||
},
|
||||
|
||||
# refine params test
|
||||
{
|
||||
"description": "Enable Refine Test",
|
||||
"params": {"refine": 'true'},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Disable Refine Test",
|
||||
"params": {"refine": 'false'},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
# refine_type test
|
||||
{
|
||||
"description": "Refine Type Test",
|
||||
"params": {"refine_type": "PQ"},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid refine type : PQ, optional types are [sq6, sq8, fp16, bf16, fp32, flat]"}
|
||||
},
|
||||
{
|
||||
"description": "SQ6 Test",
|
||||
"params": {"refine": 'true', "refine_type": "SQ6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "SQ8 Test",
|
||||
"params": {"refine": 'TRUE', "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "FP16 Test",
|
||||
"params": {"refine": True, "refine_type": "FP16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "BF16 Test",
|
||||
"params": {"refine": 'True', "refine_type": "BF16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "FP32 Test",
|
||||
"params": {"refine": True, "refine_type": "FP32"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid Refine Type Test",
|
||||
"params": {"refine": 'true', "refine_type": "INVALID"},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid refine type : INVALID, optional types are [sq6, sq8, fp16, bf16, fp32, flat]"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine": 1},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'refine' (\"1\") should be a boolean"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test will success with default value",
|
||||
"params": {"refine": None},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Lowercase String Test",
|
||||
"params": {"refine": True, "refine_type": "sq6"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Mixed Case String Test",
|
||||
"params": {"refine": True, "refine_type": "Sq8.0"},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid refine type : Sq8.0, optional types are [sq6, sq8, fp16, bf16, fp32, flat]"}
|
||||
},
|
||||
{
|
||||
"description": "Whitespace String Test",
|
||||
"params": {"refine_type": " SQ8 "},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid refine type : SQ8 , optional types are [sq6, sq8, fp16, bf16, fp32, flat]"}
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine": True, "refine_type": 8},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "invalid refine type : 8, optional types are [sq6, sq8, fp16, bf16, fp32, flat]"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"refine": True, "refine_type": None},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
# combination params test
|
||||
{
|
||||
"description": "Optimal Performance Combination Test",
|
||||
"params": {"nlist": 128, "refine": 'true', "refine_type": "SQ8"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "not refine with refine_type",
|
||||
"params": {"nlist": 127, "refine": 'false', "refine_type": "fp16"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "not_defined_param in the dict params",
|
||||
"params": {"nlist": 127, "refine": 'true', "not_defined_param": "nothing"},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
search_params = [
|
||||
# nprobe params test
|
||||
{
|
||||
"description": "Minimum Boundary Test",
|
||||
"params": {"nprobe": 1},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Equal to nlist Test",
|
||||
"params": {"nprobe": 128}, # Assuming nlist=128
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Exceed nlist Test",
|
||||
"params": {"nprobe": 129}, # Assuming nlist=128
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Exceed nprobe Test",
|
||||
"params": {"nprobe": 65537},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "should be in range [1, 65536]"}
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"nprobe": -1},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Out of range in json: param 'nprobe' (-1) should be in range [1, 65536]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test, not check data type",
|
||||
"params": {"nprobe": "32"},
|
||||
"expected": success # to be fixed: #41767
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"nprobe": 32.0},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'nprobe' (32.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"nprobe": True},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'nprobe' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"nprobe": None},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'nprobe' (null) should be integer"}
|
||||
},
|
||||
|
||||
# rbq_bits_query test
|
||||
{
|
||||
"description": "Default Value Test",
|
||||
"params": {"rbq_bits_query": 0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Maximum Value Test",
|
||||
"params": {"rbq_bits_query": 8},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Recommended Value Test - 6bit",
|
||||
"params": {"rbq_bits_query": 6},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Out of Range Test",
|
||||
"params": {"rbq_bits_query": 9},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Out of range in json: param 'rbq_bits_query' (9) should be in range [0, 8]"}
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"rbq_bits_query": -1},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Out of range in json: param 'rbq_bits_query' (-1) should be in range [0, 8]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"rbq_bits_query": "6"},
|
||||
"expected": success # to be fixed: #41767
|
||||
},
|
||||
{
|
||||
"description": "Float Type Test",
|
||||
"params": {"rbq_bits_query": 6.0},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'rbq_bits_query' (6.0) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"rbq_bits_query": True},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'rbq_bits_query' (true) should be integer"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"rbq_bits_query": None},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'rbq_bits_query' (null) should be integer"}
|
||||
},
|
||||
|
||||
# refine_k test
|
||||
{
|
||||
"description": "Default Value Test",
|
||||
"params": {"refine_k": 1.0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Recommended Value Test - 2",
|
||||
"params": {"refine_k": 2.0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Recommended Value Test - 5",
|
||||
"params": {"refine_k": 5.0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Less Than One Test",
|
||||
"params": {"refine_k": 0.5},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Out of range in json: param 'refine_k' (0.5) should be in range [1.000000, 340282346638528859811704183484516925440.000000]"}
|
||||
},
|
||||
{
|
||||
"description": "Negative Value Test",
|
||||
"params": {"refine_k": -1.0},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Out of range in json: param 'refine_k' (-1.0) should be in range [1.000000, 340282346638528859811704183484516925440.000000]"}
|
||||
},
|
||||
{
|
||||
"description": "String Type Test",
|
||||
"params": {"refine_k": "2.0"},
|
||||
"expected": success # to be fixed: #41767
|
||||
},
|
||||
{
|
||||
"description": "Integer Type Test",
|
||||
"params": {"refine_k": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Boolean Type Test",
|
||||
"params": {"refine_k": True},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'refine_k' (true) should be a number"}
|
||||
},
|
||||
{
|
||||
"description": "None Type Test",
|
||||
"params": {"refine_k": None},
|
||||
"expected": {"err_code": 999,
|
||||
"err_msg": "Type conflict in json: param 'refine_k' (null) should be a number"}
|
||||
},
|
||||
|
||||
# combination params test
|
||||
{
|
||||
"description": "Optimal Performance Combination Test",
|
||||
"params": { "nprobe": 32, "rbq_bits_query": 6, "refine_k": 2.0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Highest Recall Combination Test",
|
||||
"params": { "nprobe": 128, "rbq_bits_query": 0, "refine_k": 5.0},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "empty dict params",
|
||||
"params": {},
|
||||
"expected": success
|
||||
},
|
||||
|
||||
]
|
||||
@@ -0,0 +1,191 @@
|
||||
from pymilvus import DataType
|
||||
from common import common_type as ct
|
||||
|
||||
success = "success"
|
||||
|
||||
class NGRAM:
|
||||
supported_field_types = [
|
||||
DataType.VARCHAR,
|
||||
DataType.JSON
|
||||
]
|
||||
|
||||
# Test parameter configurations
|
||||
build_params = [
|
||||
# min_gram parameter tests
|
||||
{
|
||||
"description": "min_gram value only specified",
|
||||
"params": {"min_gram": 2},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "min_gram - negative value",
|
||||
"params": {"min_gram": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "min_gram - zero value",
|
||||
"params": {"min_gram": 0},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - string type",
|
||||
"params": {"min_gram": "2"},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - float type",
|
||||
"params": {"min_gram": 2.5},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - None value",
|
||||
"params": {"min_gram": None},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
|
||||
# max_gram parameter tests
|
||||
{
|
||||
"description": "max_gram value only specified",
|
||||
"params": {"max_gram": 5},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "max_gram - negative value",
|
||||
"params": {"max_gram": -1},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "max_gram - zero value",
|
||||
"params": {"max_gram": 0},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "max_gram - string type",
|
||||
"params": {"max_gram": "3"},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "max_gram - float type",
|
||||
"params": {"max_gram": 2.5},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
{
|
||||
"description": "max_gram - None value",
|
||||
"params": {"max_gram": None},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
|
||||
# min_gram and max_gram combination tests
|
||||
{
|
||||
"description": "min_gram equals max_gram",
|
||||
"params": {"min_gram": 2, "max_gram": 2},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "min_gram less than max_gram",
|
||||
"params": {"min_gram": 2, "max_gram": 4},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "max_gram equals a large value",
|
||||
"params": {"min_gram": 2, "max_gram": 1000000000},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "min_gram greater than max_gram",
|
||||
"params": {"min_gram": 5, "max_gram": 3},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid min_gram or max_gram value for Ngram index"}
|
||||
},
|
||||
# min_gram invalid with both specified
|
||||
{
|
||||
"description": "Invalid min_gram - negative value (both specified)",
|
||||
"params": {"min_gram": -1, "max_gram": 3},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid min_gram or max_gram value for Ngram index"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - zero value (both specified)",
|
||||
"params": {"min_gram": 0, "max_gram": 3},
|
||||
"expected": {"err_code": 1100, "err_msg": "invalid min_gram or max_gram value for Ngram index"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - string type (both specified)",
|
||||
"params": {"min_gram": "2", "max_gram": 3},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Invalid min_gram - float type (both specified)",
|
||||
"params": {"min_gram": 2.5, "max_gram": 3},
|
||||
"expected": {"err_code": 999, "err_msg": "min_gram for Ngram index must be an integer, got: 2.5"}
|
||||
},
|
||||
{
|
||||
"description": "Invalid max_gram - string type (both specified)",
|
||||
"params": {"min_gram": 2, "max_gram": "3"},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "Both parameters missing",
|
||||
"params": {},
|
||||
"expected": {"err_code": 999, "err_msg": "Ngram index must specify both min_gram and max_gram"}
|
||||
},
|
||||
|
||||
# JSON field special parameter tests
|
||||
{
|
||||
"description": "JSON field with json_path parameter",
|
||||
"params": {
|
||||
"min_gram": 2,
|
||||
"max_gram": 3,
|
||||
"json_path": "json_field['body']",
|
||||
"json_cast_type": "varchar"
|
||||
},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "JSON field with enteir json field",
|
||||
"params": {
|
||||
"min_gram": 2,
|
||||
"max_gram": 3,
|
||||
"json_path": "json_field",
|
||||
"json_cast_type": "varchar"
|
||||
},
|
||||
"expected": success
|
||||
},
|
||||
{
|
||||
"description": "JSON field with not existing path",
|
||||
"params": {
|
||||
"min_gram": 2,
|
||||
"max_gram": 3,
|
||||
"json_path": "json_field['not_existing_path']",
|
||||
"json_cast_type": "varchar"
|
||||
},
|
||||
"expected": success
|
||||
},
|
||||
# skip for https://github.com/milvus-io/milvus/issues/43934
|
||||
# {
|
||||
# "description": "JSON field with invalid json_cast_type",
|
||||
# "params": {
|
||||
# "min_gram": 2,
|
||||
# "max_gram": 3,
|
||||
# "json_path": "json_field['body']",
|
||||
# "json_cast_type": "double"
|
||||
# },
|
||||
# "expected": {"err_code": 999, "err_msg": "json_cast_type must be varchar for NGRAM index"}
|
||||
# },
|
||||
{
|
||||
"description": "JSON field missing json_cast_type",
|
||||
"params": {
|
||||
"min_gram": 2,
|
||||
"max_gram": 3,
|
||||
"json_path": "json_field['body']"
|
||||
},
|
||||
"expected": {"err_code": 999, "err_msg": "JSON field with ngram index must specify json_cast_type"}
|
||||
},
|
||||
{
|
||||
"description": "JSON field missing json_path",
|
||||
"params": {
|
||||
"min_gram": 2,
|
||||
"max_gram": 3,
|
||||
"json_cast_type": "varchar"
|
||||
},
|
||||
"expected": success
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,221 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_diskann import DISKANN
|
||||
|
||||
index_type = "DISKANN"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"search_list_size": 100, "beamwidth": 10, "pq_code_budget_gb": 1.0, "num_threads": 8, "max_degree": 64, "indexing_list_size": 100, "build_dram_budget_gb": 2.0, "search_dram_budget_gb": 1.0}
|
||||
default_search_params = {"search_list_size": 100, "beamwidth": 10, "search_dram_budget_gb": 1.0}
|
||||
|
||||
|
||||
class TestDiskannBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("params", DISKANN.build_params)
|
||||
def test_diskann_build_params(self, params):
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb * insert_times, dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) == idx_info[key]
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_diskann_on_all_vector_types(self, vector_data_type):
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, nullable=True)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim, nullable=True)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
insert_times = 2
|
||||
rows = cf.gen_row_data_by_schema(insert_times * default_nb, schema=schema)
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
**default_build_params)
|
||||
if vector_data_type not in DISKANN.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index DISKANN: invalid parameter"})
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", DISKANN.supported_metrics)
|
||||
def test_diskann_on_all_metrics(self, metric):
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb*insert_times, default_dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
**default_build_params)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestDiskannSearchParams")
|
||||
class TestDiskannSearchParams(TestMilvusClientV2Base):
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestDiskannSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
client = self._client()
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
insert_times = 2
|
||||
float_vectors = cf.gen_vectors(default_nb * insert_times, dim=self.float_vector_dim,
|
||||
vector_data_type=DataType.FLOAT_VECTOR)
|
||||
for j in range(insert_times):
|
||||
rows = []
|
||||
for i in range(default_nb):
|
||||
pk = i + j * default_nb
|
||||
row = {
|
||||
pk_field_name: pk,
|
||||
self.float_vector_field_name: list(float_vectors[pk])
|
||||
}
|
||||
self.datas.append(row)
|
||||
rows.append(row)
|
||||
self.insert(client, self.collection_name, data=rows)
|
||||
self.primary_keys.extend([i + j * default_nb for i in range(default_nb)])
|
||||
self.flush(client, self.collection_name)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
self.load_collection(client, self.collection_name)
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", DISKANN.search_params)
|
||||
def test_diskann_search_params(self, params):
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
@@ -0,0 +1,402 @@
|
||||
import pytest
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
from common import common_func as cf
|
||||
from common import common_type as ct
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from idx_faiss import FAISS
|
||||
from pymilvus import DataType
|
||||
|
||||
index_type = "FAISS"
|
||||
success = "success"
|
||||
pk_field_name = "id"
|
||||
vector_field_name = "vector"
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_search_params = {"nprobe": 8}
|
||||
|
||||
|
||||
def _default_search_params_for_faiss_factory(faiss_index_name):
|
||||
if faiss_index_name.startswith("IVF"):
|
||||
return {"nprobe": 8}
|
||||
if faiss_index_name.startswith("HNSW"):
|
||||
return {"efSearch": 64}
|
||||
return {}
|
||||
|
||||
|
||||
class TestFaissBase(TestMilvusClientV2Base):
|
||||
def _create_collection(self, client, collection_name, vector_data_type=DataType.FLOAT_VECTOR):
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
return schema
|
||||
|
||||
def _insert_rows(self, client, collection_name, vector_data_type=DataType.FLOAT_VECTOR):
|
||||
vectors = cf.gen_vectors(default_nb, dim=dim, vector_data_type=vector_data_type)
|
||||
rows = [{pk_field_name: i, vector_field_name: vectors[i]} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
def _create_faiss_index(
|
||||
self, client, collection_name, metric_type="L2", params=None, check_task=None, check_items=None
|
||||
):
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(
|
||||
field_name=vector_field_name, metric_type=metric_type, index_type=index_type, params=params
|
||||
)
|
||||
return self.create_index(client, collection_name, index_params, check_task=check_task, check_items=check_items)
|
||||
|
||||
def _search_and_check(self, client, collection_name, vector_data_type=DataType.FLOAT_VECTOR, search_params=None):
|
||||
nq = ct.default_nq
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={
|
||||
"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name,
|
||||
},
|
||||
)
|
||||
|
||||
def _assert_index_params(self, client, collection_name, params, metric_type):
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
assert idx_info["index_type"] == index_type
|
||||
assert idx_info["metric_type"] == metric_type
|
||||
for key, value in params.items():
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in [str(v) for v in idx_info.values()]
|
||||
|
||||
|
||||
class TestFaissBuildParams(TestFaissBase):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", FAISS.build_params)
|
||||
def test_faiss_build_params(self, params):
|
||||
"""
|
||||
Test vanilla Faiss factory build parameters.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
vector_data_type = params.get("vector_data_type", DataType.FLOAT_VECTOR)
|
||||
metric_type = params.get("metric_type", "L2")
|
||||
build_params = params.get("params", None)
|
||||
|
||||
self._create_collection(client, collection_name, vector_data_type)
|
||||
self._insert_rows(client, collection_name, vector_data_type)
|
||||
|
||||
if params.get("expected", None) != success:
|
||||
self._create_faiss_index(
|
||||
client,
|
||||
collection_name,
|
||||
metric_type=metric_type,
|
||||
params=build_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"),
|
||||
)
|
||||
else:
|
||||
self._create_faiss_index(client, collection_name, metric_type=metric_type, params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
if vector_data_type == DataType.FLOAT_VECTOR and params.get("searchable", True):
|
||||
search_params = _default_search_params_for_faiss_factory(build_params["faiss_index_name"])
|
||||
self._search_and_check(client, collection_name, vector_data_type, search_params=search_params)
|
||||
elif vector_data_type != DataType.FLOAT_VECTOR:
|
||||
search_params = {}
|
||||
self._search_and_check(client, collection_name, vector_data_type, search_params=search_params)
|
||||
self._assert_index_params(client, collection_name, build_params, metric_type)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", FAISS.supported_metrics)
|
||||
@pytest.mark.parametrize("build_params", [{"faiss_index_name": "Flat"}] + FAISS.metric_factories)
|
||||
def test_faiss_on_all_float_metrics(self, metric, build_params):
|
||||
"""
|
||||
Test vanilla Faiss float index factories on all supported float metrics.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type=metric, params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
search_params = _default_search_params_for_faiss_factory(build_params["faiss_index_name"])
|
||||
self._search_and_check(client, collection_name, DataType.FLOAT_VECTOR, search_params=search_params)
|
||||
self._assert_index_params(client, collection_name, build_params, metric)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_faiss_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test vanilla Faiss vector type support.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, vector_data_type)
|
||||
self._insert_rows(client, collection_name, vector_data_type)
|
||||
|
||||
if vector_data_type == DataType.BINARY_VECTOR:
|
||||
metric_type = "HAMMING"
|
||||
build_params = {"faiss_index_name": "BFlat"}
|
||||
else:
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
build_params = {"faiss_index_name": "Flat"}
|
||||
|
||||
if vector_data_type not in FAISS.supported_vector_types:
|
||||
self._create_faiss_index(
|
||||
client,
|
||||
collection_name,
|
||||
metric_type=metric_type,
|
||||
params=build_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999, "err_msg": "invalid parameter"},
|
||||
)
|
||||
else:
|
||||
self._create_faiss_index(client, collection_name, metric_type=metric_type, params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
self._search_and_check(client, collection_name, vector_data_type, search_params={})
|
||||
self._assert_index_params(client, collection_name, build_params, metric_type)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize(
|
||||
"params", [p for p in FAISS.build_params if p.get("expected") == success and p.get("searchable", True)]
|
||||
)
|
||||
def test_faiss_build_release_load_search(self, params):
|
||||
"""
|
||||
Test vanilla Faiss index survives the full Milvus build -> release -> load -> search flow.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
vector_data_type = params.get("vector_data_type", DataType.FLOAT_VECTOR)
|
||||
metric_type = params.get("metric_type", "L2")
|
||||
build_params = params["params"]
|
||||
|
||||
self._create_collection(client, collection_name, vector_data_type)
|
||||
self._insert_rows(client, collection_name, vector_data_type)
|
||||
self._create_faiss_index(client, collection_name, metric_type=metric_type, params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
self.release_collection(client, collection_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_params = {}
|
||||
if vector_data_type == DataType.FLOAT_VECTOR:
|
||||
search_params = _default_search_params_for_faiss_factory(build_params["faiss_index_name"])
|
||||
self._search_and_check(client, collection_name, vector_data_type, search_params=search_params)
|
||||
self._assert_index_params(client, collection_name, build_params, metric_type)
|
||||
|
||||
|
||||
class TestFaissSearchParams(TestFaissBase):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", FAISS.search_params)
|
||||
def test_faiss_search_params(self, params):
|
||||
"""
|
||||
Test vanilla Faiss search parameter forwarding.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
build_params = params["build_params"]
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
if params.get("expected", None) != success:
|
||||
nq = ct.default_nq
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
search_params=params["search_params"],
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"),
|
||||
)
|
||||
else:
|
||||
self._search_and_check(
|
||||
client, collection_name, DataType.FLOAT_VECTOR, search_params=params["search_params"]
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_faiss_incompatible_search_params(self):
|
||||
"""
|
||||
Test vanilla Faiss rejects search parameters incompatible with the factory index.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
build_params = {"faiss_index_name": "Flat"}
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
nq = ct.default_nq
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
search_params={"efSearch": 64},
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999, "err_msg": "not supported"},
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize(
|
||||
"build_params",
|
||||
[
|
||||
{"faiss_index_name": "Flat"},
|
||||
{"faiss_index_name": "IVF64,Flat"},
|
||||
{"faiss_index_name": "HNSW16,Flat"},
|
||||
],
|
||||
)
|
||||
def test_faiss_search_with_scalar_filter(self, build_params):
|
||||
"""
|
||||
Test vanilla Faiss search honors Milvus scalar filter bitset.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params=build_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_params = _default_search_params_for_faiss_factory(build_params["faiss_index_name"])
|
||||
search_vectors = cf.gen_vectors(1, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
results = client.search(
|
||||
collection_name,
|
||||
search_vectors,
|
||||
filter=f"{pk_field_name} >= 100",
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
)
|
||||
assert len(results) == 1
|
||||
assert len(results[0]) == ct.default_limit
|
||||
assert all(hit["id"] >= 100 for hit in results[0])
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_faiss_flat_range_search(self):
|
||||
"""
|
||||
Test vanilla Faiss float Flat range search. The current adapter implements
|
||||
RangeSearch for float FAISS indexes.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params={"faiss_index_name": "Flat"})
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_vectors = cf.gen_vectors(1, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
range_params = {"radius": 100000.0, "range_filter": 0.0}
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
search_params=range_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={
|
||||
"enable_milvus_client_api": True,
|
||||
"nq": 1,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name,
|
||||
},
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_faiss_binary_range_search_not_supported(self):
|
||||
"""
|
||||
Test vanilla Faiss binary range search is explicitly not implemented.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.BINARY_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.BINARY_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="HAMMING", params={"faiss_index_name": "BFlat"})
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_vectors = cf.gen_vectors(1, dim=dim, vector_data_type=DataType.BINARY_VECTOR)
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
search_params={"radius": 1000, "range_filter": 0},
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999, "err_msg": "RangeSearch unsupported for binary faiss indexes"},
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_faiss_pq_search_selector_not_supported(self):
|
||||
"""
|
||||
Test vanilla Faiss IndexPQ rejects Milvus search because Milvus passes
|
||||
an ID selector/bitset and native FAISS IndexPQ does not support it.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params={"faiss_index_name": "PQ8x4"})
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_vectors = cf.gen_vectors(1, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(
|
||||
client,
|
||||
collection_name,
|
||||
search_vectors,
|
||||
filter=f"{pk_field_name} >= 100",
|
||||
search_params={},
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999, "err_msg": "selector not supported"},
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_faiss_search_iterator_not_supported(self):
|
||||
"""
|
||||
Test vanilla Faiss search iterator is rejected because the adapter does
|
||||
not expose raw-vector retrieval.
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
|
||||
self._create_collection(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._insert_rows(client, collection_name, DataType.FLOAT_VECTOR)
|
||||
self._create_faiss_index(client, collection_name, metric_type="L2", params={"faiss_index_name": "Flat"})
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
search_vectors = cf.gen_vectors(1, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search_iterator(
|
||||
client,
|
||||
collection_name,
|
||||
data=search_vectors,
|
||||
batch_size=100,
|
||||
search_params={},
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 65535, "err_msg": "Failed to create iterators from index"},
|
||||
)
|
||||
@@ -0,0 +1,264 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_hnsw import HNSW
|
||||
|
||||
index_type = "HNSW"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"M": 16, "efConstruction": 200}
|
||||
default_search_params = {"ef": 64}
|
||||
|
||||
|
||||
class TestHnswBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW.build_params)
|
||||
def test_hnsw_build_params(self, params):
|
||||
"""
|
||||
Test the build params of HNSW index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert data in 2 batches with unique primary keys
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb * insert_times, dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
# build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
# verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values()
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_hnsw_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test HNSW index on all the vector types and metrics
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, nullable=True)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim, nullable=True)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert data with unique primary keys
|
||||
rows = cf.gen_row_data_by_schema(default_nb, schema=schema)
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
M=16,
|
||||
efConstruction=200)
|
||||
if vector_data_type not in HNSW.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index HNSW: invalid parameter"})
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", HNSW.supported_metrics)
|
||||
def test_hnsw_on_all_metrics(self, metric):
|
||||
"""
|
||||
Test the search params of HNSW index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# insert data
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb*insert_times, dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
M=16,
|
||||
efConstruction=200)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestHnswSearchParams")
|
||||
class TestHnswSearchParams(TestMilvusClientV2Base):
|
||||
"""Test search with pagination functionality for HNSW index"""
|
||||
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestHnswSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
"""
|
||||
Initialize collection before test class runs
|
||||
"""
|
||||
client = self._client()
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
insert_times = 2
|
||||
float_vectors = cf.gen_vectors(default_nb * insert_times, dim=self.float_vector_dim,
|
||||
vector_data_type=DataType.FLOAT_VECTOR)
|
||||
for j in range(insert_times):
|
||||
rows = []
|
||||
for i in range(default_nb):
|
||||
pk = i + j * default_nb
|
||||
row = {
|
||||
pk_field_name: pk,
|
||||
self.float_vector_field_name: list(float_vectors[pk])
|
||||
}
|
||||
self.datas.append(row)
|
||||
rows.append(row)
|
||||
self.insert(client, self.collection_name, data=rows)
|
||||
self.primary_keys.extend([i + j * default_nb for i in range(default_nb)])
|
||||
self.flush(client, self.collection_name)
|
||||
# Create HNSW index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
self.load_collection(client, self.collection_name)
|
||||
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW.search_params)
|
||||
def test_hnsw_search_params(self, params):
|
||||
"""
|
||||
Test the search params of HNSW index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
@@ -0,0 +1,258 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_hnsw_pq import HNSW_PQ
|
||||
|
||||
index_type = "HNSW_PQ"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"M": 16, "efConstruction": 200, "m": 64, "nbits": 8}
|
||||
default_search_params = {"ef": 64, "refine_k": 1}
|
||||
|
||||
|
||||
class TestHnswPQBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_PQ.build_params)
|
||||
def test_hnsw_pq_build_params(self, params):
|
||||
"""
|
||||
Test the build params of HNSW_PQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
# build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
# verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values()
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_hnsw_pq_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test HNSW_PQ index on all the vector types and metrics
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
if vector_data_type not in HNSW_PQ.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index HNSW_PQ: invalid parameter"})
|
||||
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", HNSW_PQ.supported_metrics)
|
||||
def test_hnsw_pq_on_all_metrics(self, metric):
|
||||
"""
|
||||
Test the search params of HNSW_PQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestHnswPQSearchParams")
|
||||
class TestHnswPQSearchParams(TestMilvusClientV2Base):
|
||||
"""Test search with pagination functionality for HNSW_PQ index"""
|
||||
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestHnswPQSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
"""
|
||||
Initialize collection before test class runs
|
||||
"""
|
||||
client = self._client()
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
|
||||
all_data = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=collection_schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
self.insert(client, self.collection_name, data=all_data)
|
||||
self.primary_keys.extend([i for i in range(default_nb)])
|
||||
self.flush(client, self.collection_name)
|
||||
# Create HNSW_PQ index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
self.load_collection(client, self.collection_name)
|
||||
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_PQ.search_params)
|
||||
def test_hnsw_pq_search_params(self, params):
|
||||
"""
|
||||
Test the search params of HNSW_PQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
@@ -0,0 +1,263 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_hnsw_prq import HNSW_PRQ
|
||||
|
||||
index_type = "HNSW_PRQ"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"M": 16, "efConstruction": 200, "m": 64, "nbits": 8, "nrq":1}
|
||||
default_search_params = {"ef": 64, "refine_k": 1}
|
||||
|
||||
|
||||
class TestHnswPRQBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.skip(reason="ci tests index creation timeout")
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_PRQ.build_params)
|
||||
def test_hnsw_prq_build_params(self, params):
|
||||
"""
|
||||
Test the build params of HNSW_PRQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
# build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
# verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values()
|
||||
|
||||
@pytest.mark.skip(reason="ci tests index creation timeout")
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_hnsw_prq_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test HNSW_PRQ index on all the vector types and metrics
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
if vector_data_type not in HNSW_PRQ.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index HNSW_PRQ: invalid parameter"})
|
||||
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.skip(reason="ci tests index creation timeout")
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", HNSW_PRQ.supported_metrics)
|
||||
def test_hnsw_prq_on_all_metrics(self, metric):
|
||||
"""
|
||||
Test the search params of HNSW_PRQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestHnswPRQSearchParams")
|
||||
class TestHnswPRQSearchParams(TestMilvusClientV2Base):
|
||||
"""Test search with pagination functionality for HNSW_PRQ index"""
|
||||
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestHnswPRQSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.mark.skip(reason="ci tests index creation timeout")
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
"""
|
||||
Initialize collection before test class runs
|
||||
"""
|
||||
client = self._client()
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
all_data = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=collection_schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
self.insert(client, self.collection_name, data=all_data)
|
||||
self.primary_keys.extend([i for i in range(default_nb)])
|
||||
|
||||
self.flush(client, self.collection_name)
|
||||
# Create HNSW_PRQ index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
self.load_collection(client, self.collection_name)
|
||||
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.skip(reason="ci tests index creation timeout")
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_PRQ.search_params)
|
||||
def test_hnsw_prq_search_params(self, params):
|
||||
"""
|
||||
Test the search params of HNSW_PRQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
@@ -0,0 +1,267 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_hnsw_sq import HNSW_SQ
|
||||
|
||||
index_type = "HNSW_SQ"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"M": 16, "efConstruction": 200, "sq_type": "SQ8"}
|
||||
default_search_params = {"ef": 64, "refine_k": 1}
|
||||
|
||||
|
||||
class TestHnswSQBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_SQ.build_params)
|
||||
def test_hnsw_sq_build_params(self, params):
|
||||
"""
|
||||
Test the build params of HNSW_SQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
# build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
if params.get("relaxed_limit"):
|
||||
# Extreme params (e.g. M=2, efConstruction=1) produce a poorly connected
|
||||
# HNSW graph that may return fewer than topK results — only assert > 0.
|
||||
results = client.search(collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit)
|
||||
for r in results:
|
||||
assert len(r) > 0, f"expected > 0 results but got {len(r)}"
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
# verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values()
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_hnsw_sq_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test HNSW_SQ index on all the vector types and metrics
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
if vector_data_type not in HNSW_SQ.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index HNSW_SQ: invalid parameter"})
|
||||
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", HNSW_SQ.supported_metrics)
|
||||
def test_hnsw_sq_on_all_metrics(self, metric):
|
||||
"""
|
||||
Test the search params of HNSW_SQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
all_rows = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
|
||||
self.insert(client, collection_name, all_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestHnswSQSearchParams")
|
||||
class TestHnswSQSearchParams(TestMilvusClientV2Base):
|
||||
"""Test search with pagination functionality for HNSW_SQ index"""
|
||||
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestHnswSQSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
"""
|
||||
Initialize collection before test class runs
|
||||
"""
|
||||
client = self._client()
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
all_data = cf.gen_row_data_by_schema(
|
||||
nb=default_nb,
|
||||
schema=collection_schema,
|
||||
start=0,
|
||||
random_pk=False
|
||||
)
|
||||
self.insert(client, self.collection_name, data=all_data)
|
||||
self.primary_keys.extend([i for i in range(default_nb)])
|
||||
|
||||
self.flush(client, self.collection_name)
|
||||
# Create HNSW_SQ index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type=index_type,
|
||||
params=default_build_params)
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
self.load_collection(client, self.collection_name)
|
||||
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", HNSW_SQ.search_params)
|
||||
def test_hnsw_sq_search_params(self, params):
|
||||
"""
|
||||
Test the search params of HNSW_SQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
@@ -0,0 +1,306 @@
|
||||
import logging
|
||||
from utils.util_pymilvus import *
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from common import common_type as ct
|
||||
from common import common_func as cf
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
import pytest
|
||||
from idx_ivf_rabitq import IVF_RABITQ
|
||||
|
||||
index_type = "IVF_RABITQ"
|
||||
success = "success"
|
||||
pk_field_name = 'id'
|
||||
vector_field_name = 'vector'
|
||||
dim = ct.default_dim
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"nlist": 128, "refine": 'true', "refine_type": "SQ8"}
|
||||
default_search_params = {"nprobe": 8, "rbq_bits_query": 6, "refine_k": 1.0}
|
||||
|
||||
|
||||
class TestIvfRabitqBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", IVF_RABITQ.build_params)
|
||||
def test_ivf_rabitq_build_params(self, params):
|
||||
"""
|
||||
Test the build params of IVF_RABITQ index
|
||||
"""
|
||||
client = self._client()
|
||||
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert data in 3 batches with unique primary keys using a loop
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb * insert_times, dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
build_params = params.get("params", None)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type=index_type,
|
||||
params=build_params)
|
||||
# build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
# verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, vector_field_name)
|
||||
# check every key and value in build_params exists in idx_info
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values() # TODO: uncommented after #41783 fixed
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("vector_data_type", ct.all_vector_types)
|
||||
def test_ivf_rabitq_on_all_vector_types(self, vector_data_type):
|
||||
"""
|
||||
Test ivf_rabitq index on all the vector types and metrics
|
||||
"""
|
||||
client = self._client()
|
||||
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
if vector_data_type == DataType.SPARSE_FLOAT_VECTOR:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, nullable=True)
|
||||
else:
|
||||
schema.add_field(vector_field_name, datatype=vector_data_type, dim=dim, nullable=True)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert data unique primary keys using a loop
|
||||
rows = cf.gen_row_data_by_schema(default_nb, schema=schema)
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
metric_type = cf.get_default_metric_for_vector_type(vector_data_type)
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric_type,
|
||||
index_type=index_type,
|
||||
nlist=128, # flatten the params
|
||||
refine=True,
|
||||
refine_type="SQ8")
|
||||
if vector_data_type not in IVF_RABITQ.supported_vector_types:
|
||||
self.create_index(client, collection_name, index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999,
|
||||
"err_msg": f"can't build with this index IVF_RABITQ: invalid parameter"})
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=vector_data_type)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metric", IVF_RABITQ.supported_metrics)
|
||||
def test_ivf_rabitq_on_all_metrics(self, metric):
|
||||
"""
|
||||
Test the search params of IVF_RABITQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# insert data
|
||||
insert_times = 2
|
||||
random_vectors = list(cf.gen_vectors(default_nb*insert_times, default_dim, vector_data_type=DataType.FLOAT_VECTOR))
|
||||
for j in range(insert_times):
|
||||
start_pk = j * default_nb
|
||||
rows = [{
|
||||
pk_field_name: i + start_pk,
|
||||
vector_field_name: random_vectors[i + start_pk]
|
||||
} for i in range(default_nb)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=vector_field_name,
|
||||
metric_type=metric,
|
||||
index_type=index_type,
|
||||
nlist=128,
|
||||
refine=True,
|
||||
refine_type="SQ8")
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=default_search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
|
||||
@pytest.mark.xdist_group("TestIvfRabitqSearchParams")
|
||||
class TestIvfRabitqSearchParams(TestMilvusClientV2Base):
|
||||
"""Test search with pagination functionality"""
|
||||
|
||||
def setup_class(self):
|
||||
super().setup_class(self)
|
||||
self.collection_name = "TestIvfRabitqSearchParams" + cf.gen_unique_str("_")
|
||||
self.float_vector_field_name = vector_field_name
|
||||
self.float_vector_dim = dim
|
||||
self.primary_keys = []
|
||||
self.enable_dynamic_field = False
|
||||
self.datas = []
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
def prepare_collection(self, request):
|
||||
"""
|
||||
Initialize collection before test class runs
|
||||
"""
|
||||
# Get client connection
|
||||
client = self._client()
|
||||
|
||||
# Create collection
|
||||
collection_schema = self.create_schema(client)[0]
|
||||
collection_schema.add_field(pk_field_name, DataType.INT64, is_primary=True, auto_id=False)
|
||||
collection_schema.add_field(self.float_vector_field_name, DataType.FLOAT_VECTOR, dim=128)
|
||||
self.create_collection(client, self.collection_name, schema=collection_schema,
|
||||
enable_dynamic_field=self.enable_dynamic_field, force_teardown=False)
|
||||
# Define number of insert iterations
|
||||
insert_times = 2
|
||||
|
||||
# Generate vectors for each type and store in self
|
||||
float_vectors = cf.gen_vectors(default_nb * insert_times, dim=self.float_vector_dim,
|
||||
vector_data_type=DataType.FLOAT_VECTOR)
|
||||
|
||||
# Insert data multiple times with non-duplicated primary keys
|
||||
for j in range(insert_times):
|
||||
# Group rows by partition based on primary key mod 3
|
||||
rows = []
|
||||
for i in range(default_nb):
|
||||
pk = i + j * default_nb
|
||||
row = {
|
||||
pk_field_name: pk,
|
||||
self.float_vector_field_name: list(float_vectors[pk])
|
||||
}
|
||||
self.datas.append(row)
|
||||
rows.append(row)
|
||||
|
||||
# Insert into respective partitions
|
||||
self.insert(client, self.collection_name, data=rows)
|
||||
# Track all inserted data and primary keys
|
||||
self.primary_keys.extend([i + j * default_nb for i in range(default_nb)])
|
||||
|
||||
self.flush(client, self.collection_name)
|
||||
|
||||
# Create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(field_name=self.float_vector_field_name,
|
||||
metric_type="COSINE",
|
||||
index_type="IVF_RABITQ",
|
||||
params={"nlist": 128, "refine": 'true', "refine_type": "SQ8"})
|
||||
self.create_index(client, self.collection_name, index_params=index_params)
|
||||
self.wait_for_index_ready(client, self.collection_name, index_name=self.float_vector_field_name)
|
||||
|
||||
# Load collection
|
||||
self.load_collection(client, self.collection_name)
|
||||
|
||||
def teardown():
|
||||
self.drop_collection(self._client(), self.collection_name)
|
||||
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", IVF_RABITQ.search_params)
|
||||
def test_ivf_rabitq_search_params(self, params):
|
||||
"""
|
||||
Test the search params of IVF_RABITQ index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = self.collection_name
|
||||
|
||||
# search
|
||||
nq = 2
|
||||
search_vectors = cf.gen_vectors(nq, dim=self.float_vector_dim, vector_data_type=DataType.FLOAT_VECTOR)
|
||||
search_params = params.get("params", None)
|
||||
if params.get("expected", None) != success:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=params.get("expected"))
|
||||
else:
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
if len(search_params.keys()) == 3:
|
||||
# try to search again with flattened params
|
||||
search_params = {
|
||||
"nprobe": search_params["nprobe"],
|
||||
"rbq_bits_query": search_params["rbq_bits_query"],
|
||||
"refine_k": search_params["refine_k"]
|
||||
}
|
||||
self.search(client, collection_name, search_vectors,
|
||||
search_params=search_params,
|
||||
limit=ct.default_limit,
|
||||
check_task=CheckTasks.check_search_results,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": nq,
|
||||
"limit": ct.default_limit,
|
||||
"pk_name": pk_field_name})
|
||||
|
||||
@@ -0,0 +1,565 @@
|
||||
import pytest
|
||||
from base.client_v2_base import TestMilvusClientV2Base
|
||||
from common import common_func as cf
|
||||
from common import common_type as ct
|
||||
from common.common_type import CaseLabel, CheckTasks
|
||||
from idx_ngram import NGRAM
|
||||
from pymilvus import DataType
|
||||
|
||||
index_type = "NGRAM"
|
||||
success = "success"
|
||||
pk_field_name = "id"
|
||||
vector_field_name = "vector"
|
||||
content_field_name = "content_ngram"
|
||||
json_field_name = "json_field"
|
||||
dim = 32
|
||||
default_nb = ct.default_nb
|
||||
default_build_params = {"min_gram": 2, "max_gram": 3}
|
||||
|
||||
|
||||
class TestNgramBuildParams(TestMilvusClientV2Base):
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("params", NGRAM.build_params)
|
||||
def test_ngram_build_params(self, params):
|
||||
"""
|
||||
Test the build params of NGRAM index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim, nullable=True)
|
||||
schema.add_field(content_field_name, datatype=DataType.VARCHAR, max_length=100, nullable=True)
|
||||
|
||||
# Check if this test case requires JSON field
|
||||
build_params = params.get("params", None)
|
||||
has_json_params = build_params is not None and ("json_path" in build_params or "json_cast_type" in build_params)
|
||||
|
||||
target_field_name = content_field_name # Default to VARCHAR field
|
||||
|
||||
if has_json_params:
|
||||
# Add JSON field for JSON-related parameter tests
|
||||
schema.add_field(json_field_name, datatype=DataType.JSON)
|
||||
target_field_name = json_field_name
|
||||
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert test data
|
||||
nb = default_nb
|
||||
rows = cf.gen_row_data_by_schema(nb=nb, schema=schema, start=0)
|
||||
|
||||
if has_json_params:
|
||||
# Generate JSON test data with varied content
|
||||
json_keywords = ["stadium", "park", "school", "library", "hospital", "restaurant", "office", "store"]
|
||||
for i, row in enumerate(rows):
|
||||
keyword_idx = i % len(json_keywords)
|
||||
keyword = json_keywords[keyword_idx]
|
||||
row[content_field_name] = f"text content {i}" # Still provide VARCHAR data
|
||||
row[json_field_name] = {
|
||||
"body": f"This is a {keyword} building",
|
||||
"title": f"Location {i}",
|
||||
"description": f"Description for {keyword} number {i}",
|
||||
}
|
||||
else:
|
||||
# Generate VARCHAR test data with varied content
|
||||
varchar_keywords = ["stadium", "park", "school", "library", "hospital", "restaurant", "office", "store"]
|
||||
for i, row in enumerate(rows):
|
||||
keyword_idx = i % len(varchar_keywords)
|
||||
keyword = varchar_keywords[keyword_idx]
|
||||
row[content_field_name] = f"The {keyword} is large and beautiful number {i}"
|
||||
|
||||
# Insert data in batches for better performance
|
||||
batch_size = 1000
|
||||
for i in range(0, nb, batch_size):
|
||||
batch_rows = rows[i : i + batch_size]
|
||||
self.insert(client, collection_name, batch_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# Create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_name = cf.gen_str_by_length(10, letters_only=True)
|
||||
index_params.add_index(
|
||||
field_name=target_field_name, index_name=index_name, index_type=index_type, params=build_params
|
||||
)
|
||||
|
||||
# Build index
|
||||
if params.get("expected", None) != success:
|
||||
self.create_index(
|
||||
client, collection_name, index_params, check_task=CheckTasks.err_res, check_items=params.get("expected")
|
||||
)
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=index_name)
|
||||
|
||||
# Create vector index before loading collection
|
||||
vector_index_params = self.prepare_index_params(client)[0]
|
||||
vector_index_params.add_index(
|
||||
field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type="IVF_FLAT",
|
||||
params={"nlist": 128},
|
||||
)
|
||||
self.create_index(client, collection_name, vector_index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
# Load collection
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# Test query based on field type
|
||||
if has_json_params:
|
||||
filter_expr = f"{json_field_name}['body'] LIKE \"%stadium%\""
|
||||
else:
|
||||
filter_expr = f'{content_field_name} LIKE "%stadium%"'
|
||||
|
||||
# Calculate expected count: 2000 data points with 8 keywords cycling
|
||||
# Each keyword appears 2000/8 = 250 times
|
||||
expected_count = default_nb // 8 # 250 matches for "stadium"
|
||||
|
||||
self.query(
|
||||
client,
|
||||
collection_name,
|
||||
filter=filter_expr,
|
||||
output_fields=["count(*)"],
|
||||
check_task=CheckTasks.check_query_results,
|
||||
check_items={"enable_milvus_client_api": True, "count(*)": expected_count},
|
||||
)
|
||||
|
||||
# Verify the index params are persisted
|
||||
idx_info = client.describe_index(collection_name, index_name)
|
||||
if build_params is not None:
|
||||
for key, value in build_params.items():
|
||||
if value is not None and key not in ["json_path", "json_cast_type"]:
|
||||
assert key in idx_info.keys()
|
||||
assert str(value) in idx_info.values()
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("scalar_field_type", ct.all_scalar_data_types)
|
||||
def test_ngram_on_all_scalar_fields(self, scalar_field_type):
|
||||
"""
|
||||
Test NGRAM index on all scalar field types and verify proper error handling
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
|
||||
# Add the scalar field with appropriate parameters
|
||||
if scalar_field_type == DataType.VARCHAR:
|
||||
schema.add_field("scalar_field", datatype=scalar_field_type, max_length=1000, nullable=True)
|
||||
elif scalar_field_type == DataType.ARRAY:
|
||||
schema.add_field(
|
||||
"scalar_field",
|
||||
datatype=scalar_field_type,
|
||||
element_type=DataType.VARCHAR,
|
||||
max_capacity=10,
|
||||
max_length=100,
|
||||
)
|
||||
else:
|
||||
schema.add_field("scalar_field", datatype=scalar_field_type)
|
||||
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Generate appropriate test data for each field type
|
||||
nb = default_nb
|
||||
rows = cf.gen_row_data_by_schema(nb=nb, schema=schema, start=0)
|
||||
|
||||
# Update scalar field with appropriate test data
|
||||
if scalar_field_type == DataType.VARCHAR:
|
||||
# Generate varied VARCHAR data for better testing
|
||||
keywords = ["stadium", "park", "school", "library", "hospital", "restaurant", "office", "store"]
|
||||
for i, row in enumerate(rows):
|
||||
keyword_idx = i % len(keywords)
|
||||
keyword = keywords[keyword_idx]
|
||||
row["scalar_field"] = f"The {keyword} is a large building number {i}"
|
||||
elif scalar_field_type == DataType.JSON:
|
||||
# Generate varied JSON data for better testing
|
||||
keywords = ["school", "park", "mall", "library", "hospital", "restaurant", "office", "store"]
|
||||
for i, row in enumerate(rows):
|
||||
keyword_idx = i % len(keywords)
|
||||
keyword = keywords[keyword_idx]
|
||||
row["scalar_field"] = {
|
||||
"body": f"This is a {keyword}",
|
||||
"title": f"Location {i}",
|
||||
"category": f"Category {keyword_idx}",
|
||||
}
|
||||
elif scalar_field_type == DataType.ARRAY:
|
||||
# Generate varied ARRAY data for better testing
|
||||
base_words = ["word", "text", "data", "item", "element"]
|
||||
keywords = ["stadium", "park", "school", "library", "hospital"]
|
||||
for i, row in enumerate(rows):
|
||||
base_idx = i % len(base_words)
|
||||
keyword_idx = i % len(keywords)
|
||||
row["scalar_field"] = [f"{base_words[base_idx]}1", f"{base_words[base_idx]}2", keywords[keyword_idx]]
|
||||
# For other scalar types, keep the auto-generated data
|
||||
|
||||
# Insert data in batches for better performance
|
||||
batch_size = 1000
|
||||
for i in range(0, nb, batch_size):
|
||||
batch_rows = rows[i : i + batch_size]
|
||||
self.insert(client, collection_name, batch_rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# Create index
|
||||
index_name = cf.gen_str_by_length(10, letters_only=True)
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
if scalar_field_type == DataType.JSON:
|
||||
# JSON field requires json_path and json_cast_type
|
||||
index_params.add_index(
|
||||
field_name="scalar_field",
|
||||
index_name=index_name,
|
||||
index_type=index_type,
|
||||
params={"min_gram": 2, "max_gram": 3, "json_path": "scalar_field['body']", "json_cast_type": "varchar"},
|
||||
)
|
||||
else:
|
||||
index_params.add_index(
|
||||
field_name="scalar_field", index_name=index_name, index_type=index_type, params=default_build_params
|
||||
)
|
||||
|
||||
# Check if the field type is supported for NGRAM index
|
||||
if scalar_field_type not in NGRAM.supported_field_types:
|
||||
self.create_index(
|
||||
client,
|
||||
collection_name,
|
||||
index_params,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 999, "err_msg": "ngram index can only be created on VARCHAR or JSON field"},
|
||||
)
|
||||
else:
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=index_name)
|
||||
|
||||
# Create vector index before loading collection
|
||||
vector_index_params = self.prepare_index_params(client)[0]
|
||||
vector_index_params.add_index(
|
||||
field_name=vector_field_name,
|
||||
metric_type=cf.get_default_metric_for_vector_type(vector_type=DataType.FLOAT_VECTOR),
|
||||
index_type="IVF_FLAT",
|
||||
params={"nlist": 128},
|
||||
)
|
||||
self.create_index(client, collection_name, vector_index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# Test query for supported types
|
||||
if scalar_field_type == DataType.VARCHAR:
|
||||
# Calculate expected count: 2000 data points with 8 keywords cycling
|
||||
# Each keyword appears 2000/8 = 250 times
|
||||
expected_count = default_nb // 8 # 250 matches for "stadium"
|
||||
filter_expr = 'scalar_field LIKE "%stadium%"'
|
||||
self.query(
|
||||
client,
|
||||
collection_name,
|
||||
filter=filter_expr,
|
||||
output_fields=["count(*)"],
|
||||
check_task=CheckTasks.check_query_results,
|
||||
check_items={"enable_milvus_client_api": True, "count(*)": expected_count},
|
||||
)
|
||||
elif scalar_field_type == DataType.JSON:
|
||||
# Calculate expected count: 2000 data points with 8 keywords cycling
|
||||
# Each keyword appears 2000/8 = 250 times
|
||||
expected_count = default_nb // 8 # 250 matches for "school"
|
||||
filter_expr = "scalar_field['body'] LIKE \"%school%\""
|
||||
self.query(
|
||||
client,
|
||||
collection_name,
|
||||
filter=filter_expr,
|
||||
output_fields=["count(*)"],
|
||||
check_task=CheckTasks.check_query_results,
|
||||
check_items={"enable_milvus_client_api": True, "count(*)": expected_count},
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.skip(reason="skip for issue #44164")
|
||||
def test_ngram_alter_index_mmap_and_gram_values(self):
|
||||
"""
|
||||
Test the alter index with mmap and gram values
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
schema.add_field("content_ngram", datatype=DataType.VARCHAR, max_length=20)
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert data
|
||||
content_keywords = ["stadium", "park", "school", "library", "hospital", "restaurant", "office", "store"]
|
||||
rows = cf.gen_row_data_by_schema(nb=default_nb, schema=schema, start=0)
|
||||
for i, row in enumerate(rows):
|
||||
row["content_ngram"] = content_keywords[i % len(content_keywords)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# Create index
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(
|
||||
field_name="content_ngram",
|
||||
index_name="content_ngram",
|
||||
index_type=index_type,
|
||||
params={"min_gram": 2, "max_gram": 3},
|
||||
)
|
||||
index_params.add_index(
|
||||
field_name=vector_field_name, index_type="IVF_FLAT", metric_type="COSINE", params={"nlist": 128}
|
||||
)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name="content_ngram")
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.load_collection(client, collection_name)
|
||||
# Query to check if the index is created
|
||||
res = self.query(
|
||||
client, collection_name, filter="content_ngram LIKE 'stad_%'", output_fields=["id", "content_ngram"]
|
||||
)[0]
|
||||
assert len(res) == default_nb // len(content_keywords)
|
||||
|
||||
# Release collection before alter ngram index
|
||||
self.release_collection(client, collection_name)
|
||||
# Alter index mmap properties
|
||||
self.alter_index_properties(
|
||||
client, collection_name, index_name="content_ngram", properties={"mmap.enabled": True}
|
||||
)
|
||||
res = self.describe_index(client, collection_name, index_name="content_ngram")[0]
|
||||
assert res.get("mmap.enabled", None) == "True"
|
||||
# Load the collection and query again
|
||||
self.load_collection(client, collection_name)
|
||||
res = self.query(
|
||||
client, collection_name, filter="content_ngram LIKE 'stad_%'", output_fields=["id", "content_ngram"]
|
||||
)[0]
|
||||
assert len(res) == default_nb // len(content_keywords)
|
||||
|
||||
# Alter index gram value properties is not supported
|
||||
self.release_collection(client, collection_name)
|
||||
error = {ct.err_code: 1, ct.err_msg: "invalid mmap.enabled value: True, expected: true, false"}
|
||||
self.alter_index_properties(
|
||||
client,
|
||||
collection_name,
|
||||
index_name="content_ngram",
|
||||
properties={"min_gram": 3, "max_gram": 4},
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items=error,
|
||||
)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_ngram_search_with_diff_length_of_filter_value(self):
|
||||
"""
|
||||
Test the search params of NGRAM index
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
schema.add_field("content_no_index", datatype=DataType.VARCHAR, max_length=10)
|
||||
schema.add_field("content_ngram", datatype=DataType.VARCHAR, max_length=10)
|
||||
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Insert test data
|
||||
insert_times = 2
|
||||
content_keywords = ["stadium", "park", "school", "library", "hospital", "restaurant", "office", "store"]
|
||||
for i in range(insert_times):
|
||||
rows = cf.gen_row_data_by_schema(nb=default_nb, schema=schema, start=i * default_nb)
|
||||
for j, row in enumerate(rows):
|
||||
row["content_no_index"] = content_keywords[j % len(content_keywords)]
|
||||
row["content_ngram"] = content_keywords[j % len(content_keywords)]
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# Create vector index before loading collection
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(
|
||||
field_name=vector_field_name, metric_type="COSINE", index_type="IVF_FLAT", params={"nlist": 128}
|
||||
)
|
||||
min_gram = 2
|
||||
max_gram = 4
|
||||
index_params.add_index(
|
||||
field_name="content_ngram", index_type=index_type, params={"min_gram": min_gram, "max_gram": max_gram}
|
||||
)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.wait_for_index_ready(client, collection_name, index_name="content_ngram")
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
# Test query 0: filter value length is less than min_gram
|
||||
filter_expr = f'content_ngram LIKE "{content_keywords[0][: min_gram - 1]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "{content_keywords[0][: min_gram - 1]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query 1: filter value length is equal to min_gram
|
||||
filter_expr = f'content_ngram LIKE "{content_keywords[0][:min_gram]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "{content_keywords[0][:min_gram]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query 2: filter value length is less than max_gram
|
||||
filter_expr = f'content_ngram LIKE "{content_keywords[0][: max_gram - 1]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "{content_keywords[0][: max_gram - 1]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query 3: filter value length is equal to max_gram
|
||||
filter_expr = f'content_ngram LIKE "{content_keywords[0][:max_gram]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "{content_keywords[0][:max_gram]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query 4: filter value length is greater than max_gram
|
||||
filter_expr = f'content_ngram LIKE "{content_keywords[0][: max_gram + 1]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "{content_keywords[0][: max_gram + 1]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query with suffix match
|
||||
filter_expr = f'content_ngram LIKE "%{content_keywords[0][4:]}"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "%{content_keywords[0][4:]}"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query with infix match
|
||||
filter_expr = f'content_ngram LIKE "%{content_keywords[0][2:4]}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = f'content_no_index LIKE "%{content_keywords[0][2:4]}%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
# Test query with Mixed Wildcard Match
|
||||
filter_expr = 'content_ngram LIKE "%st_d_um%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_ngram) >= insert_times * default_nb // len(content_keywords)
|
||||
filter_expr = 'content_no_index LIKE "%st_d_um%"'
|
||||
res_no_index = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[0]
|
||||
assert len(res_no_index) >= insert_times * default_nb // len(content_keywords)
|
||||
assert res_ngram == res_no_index
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_ngram_search_with_multilingual_utf8_strings(self):
|
||||
"""
|
||||
Test NGRAM index with multilingual and UTF-8 strings for LIKE filtering
|
||||
"""
|
||||
client = self._client()
|
||||
collection_name = cf.gen_collection_name_by_testcase_name()
|
||||
schema, _ = self.create_schema(client)
|
||||
schema.add_field(pk_field_name, datatype=DataType.INT64, is_primary=True, auto_id=False)
|
||||
schema.add_field(vector_field_name, datatype=DataType.FLOAT_VECTOR, dim=dim)
|
||||
schema.add_field("content_no_index", datatype=DataType.JSON)
|
||||
schema.add_field("content_ngram", datatype=DataType.JSON)
|
||||
|
||||
self.create_collection(client, collection_name, schema=schema)
|
||||
|
||||
# Multilingual test data with various UTF-8 characters
|
||||
multilingual_keywords = [
|
||||
"北京大学", # Chinese
|
||||
"東京大学", # Japanese
|
||||
"Московский", # Russian
|
||||
"café", # French with accent
|
||||
"naïve", # French with diaeresis
|
||||
"München", # German with umlaut
|
||||
"🏫学校🎓", # Chinese with emojis
|
||||
"🌟star⭐", # English with emojis
|
||||
"مدرسة", # Arabic
|
||||
"Γειά", # Greek
|
||||
"प्रविष्टि", # Hindi/Devanagari
|
||||
"한국어", # Korean
|
||||
"español", # Spanish
|
||||
"português", # Portuguese
|
||||
"中英mix英文", # Mixed Chinese-English
|
||||
"café☕北京🏙️", # Mixed with emojis and multiple languages
|
||||
]
|
||||
|
||||
# Insert test data
|
||||
insert_times = 2
|
||||
for i in range(insert_times):
|
||||
rows = cf.gen_row_data_by_schema(nb=default_nb, schema=schema, start=i * default_nb)
|
||||
for j, row in enumerate(rows):
|
||||
keyword_idx = j % len(multilingual_keywords)
|
||||
keyword = multilingual_keywords[keyword_idx]
|
||||
row["content_no_index"] = {
|
||||
"body": f"This is a {keyword} building",
|
||||
"title": f"Location {i}",
|
||||
"description": f"Description for {keyword} number {i}",
|
||||
}
|
||||
row["content_ngram"] = {
|
||||
"body": f"This is a {keyword} building",
|
||||
"title": f"Location {i}",
|
||||
"description": f"Description for {keyword} number {i}",
|
||||
}
|
||||
self.insert(client, collection_name, rows)
|
||||
self.flush(client, collection_name)
|
||||
|
||||
# Create vector index before loading collection
|
||||
index_params = self.prepare_index_params(client)[0]
|
||||
index_params.add_index(
|
||||
field_name=vector_field_name, metric_type="COSINE", index_type="IVF_FLAT", params={"nlist": 128}
|
||||
)
|
||||
|
||||
# Create NGRAM index with appropriate parameters for multilingual content
|
||||
min_gram = 1 # Use 1 for better multilingual support
|
||||
max_gram = 3
|
||||
index_params.add_index(
|
||||
field_name="content_ngram",
|
||||
index_name="content_ngram",
|
||||
index_type=index_type,
|
||||
params={
|
||||
"min_gram": min_gram,
|
||||
"max_gram": max_gram,
|
||||
"json_path": "content_ngram['body']",
|
||||
"json_cast_type": "varchar",
|
||||
},
|
||||
)
|
||||
self.create_index(client, collection_name, index_params)
|
||||
self.wait_for_index_ready(client, collection_name, index_name=vector_field_name)
|
||||
self.wait_for_index_ready(client, collection_name, index_name="content_ngram")
|
||||
self.load_collection(client, collection_name)
|
||||
|
||||
test_keywords = [
|
||||
"北京", # Chinese
|
||||
"東京", # Japanese
|
||||
"Моск", # Russian Cyrillic
|
||||
"café", # French accent
|
||||
"🏫", # Emoji
|
||||
"⭐", # Star emoji
|
||||
"مدرسة", # Arabic
|
||||
"한국", # Korean
|
||||
"München", # German umlaut
|
||||
"mix", # Mixed language
|
||||
"café☕", # Complex multilingual with emoji prefix
|
||||
"प्रविष्टि", # Hindi/Devanagari
|
||||
"Γειά", # Greek
|
||||
"português", # Portuguese with tilde
|
||||
"学", # Single CJK character
|
||||
]
|
||||
|
||||
for keyword in test_keywords:
|
||||
filter_expr = f'content_ngram["body"] LIKE "%{keyword}%"'
|
||||
res_ngram = self.query(client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"])[
|
||||
0
|
||||
]
|
||||
filter_expr = f'content_no_index["body"] LIKE "%{keyword}%"'
|
||||
res_no_index = self.query(
|
||||
client, collection_name, filter=filter_expr, output_fields=["id", "content_ngram"]
|
||||
)[0]
|
||||
|
||||
assert len(res_ngram) > 0
|
||||
assert sorted(res_ngram, key=lambda item: item["id"]) == sorted(res_no_index, key=lambda item: item["id"])
|
||||
Reference in New Issue
Block a user