2020-12-29 11:56:37 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License
|
|
|
|
|
2022-07-05 19:48:20 +08:00
|
|
|
#include <boost/format.hpp>
|
2024-02-28 12:29:00 +08:00
|
|
|
#include <gtest/gtest.h>
|
2021-10-18 18:09:04 +08:00
|
|
|
|
2023-04-21 11:46:32 +08:00
|
|
|
#include "common/Types.h"
|
2024-02-28 12:29:00 +08:00
|
|
|
#include "common/Tracer.h"
|
2022-09-21 20:16:51 +08:00
|
|
|
#include "index/IndexFactory.h"
|
2023-09-22 09:59:26 +08:00
|
|
|
#include "knowhere/version.h"
|
2024-02-28 12:29:00 +08:00
|
|
|
#include "segcore/SegmentSealedImpl.h"
|
2024-06-18 14:42:00 +08:00
|
|
|
#include "storage/MmapManager.h"
|
2023-09-15 10:21:20 +08:00
|
|
|
#include "storage/MinioChunkManager.h"
|
2024-02-28 12:29:00 +08:00
|
|
|
#include "storage/RemoteChunkManagerSingleton.h"
|
|
|
|
#include "storage/Util.h"
|
|
|
|
#include "test_utils/DataGen.h"
|
2023-09-15 10:21:20 +08:00
|
|
|
#include "test_utils/indexbuilder_test_utils.h"
|
2024-02-28 12:29:00 +08:00
|
|
|
#include "test_utils/storage_test_utils.h"
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
using namespace milvus;
|
2021-01-21 15:29:52 +08:00
|
|
|
using namespace milvus::query;
|
2021-10-18 18:09:04 +08:00
|
|
|
using namespace milvus::segcore;
|
2024-02-28 12:29:00 +08:00
|
|
|
|
2022-10-14 14:45:23 +08:00
|
|
|
using milvus::segcore::LoadIndexInfo;
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-04-07 14:20:29 +08:00
|
|
|
const int64_t ROW_COUNT = 10 * 1000;
|
|
|
|
const int64_t BIAS = 4200;
|
2021-09-23 16:55:54 +08:00
|
|
|
|
2024-03-13 00:16:30 +08:00
|
|
|
using Param = std::string;
|
|
|
|
class SealedTest : public ::testing::TestWithParam<Param> {
|
|
|
|
public:
|
|
|
|
void
|
|
|
|
SetUp() override {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-29 11:56:37 +08:00
|
|
|
TEST(Sealed, without_predicate) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
2022-06-29 14:20:19 +08:00
|
|
|
auto metric_type = knowhere::metric::L2;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fake_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto float_fid = schema->AddDebugField("age", DataType::FLOAT);
|
|
|
|
auto i64_fid = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(i64_fid);
|
2023-07-04 18:30:25 +08:00
|
|
|
|
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2021-09-23 16:55:54 +08:00
|
|
|
auto N = ROW_COUNT;
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto vec_col = dataset.get_col<float>(fake_id);
|
2020-12-29 11:56:37 +08:00
|
|
|
for (int64_t i = 0; i < 1000 * dim; ++i) {
|
|
|
|
vec_col.push_back(0);
|
|
|
|
}
|
2023-04-07 14:20:29 +08:00
|
|
|
auto query_ptr = vec_col.data() + BIAS * dim;
|
2023-04-26 10:14:41 +08:00
|
|
|
auto segment = CreateGrowingSegment(schema, empty_index_meta);
|
2020-12-29 11:56:37 +08:00
|
|
|
segment->PreInsert(N);
|
2023-03-10 09:47:54 +08:00
|
|
|
segment->Insert(0,
|
|
|
|
N,
|
|
|
|
dataset.row_ids_.data(),
|
|
|
|
dataset.timestamps_.data(),
|
|
|
|
dataset.raw_);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2020-12-29 11:56:37 +08:00
|
|
|
auto num_queries = 5;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group_raw =
|
|
|
|
CreatePlaceholderGroupFromBlob(num_queries, 16, query_ptr);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
std::vector<const PlaceholderGroup*> ph_group_arr = {ph_group.get()};
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
2021-12-02 11:45:32 +08:00
|
|
|
auto pre_result = SearchResultToJson(*sr);
|
2022-09-21 20:16:51 +08:00
|
|
|
milvus::index::CreateIndexInfo create_index_info;
|
|
|
|
create_index_info.field_type = DataType::VECTOR_FLOAT;
|
|
|
|
create_index_info.metric_type = knowhere::metric::L2;
|
|
|
|
create_index_info.index_type = knowhere::IndexEnum::INDEX_FAISS_IVFFLAT;
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info.index_engine_version =
|
2023-09-25 21:39:27 +08:00
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber();
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto indexing = milvus::index::IndexFactory::GetInstance().CreateIndex(
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info, milvus::storage::FileManagerContext());
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto build_conf =
|
|
|
|
knowhere::Json{{knowhere::meta::METRIC_TYPE, knowhere::metric::L2},
|
|
|
|
{knowhere::meta::DIM, std::to_string(dim)},
|
|
|
|
{knowhere::indexparam::NLIST, "100"}};
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-02-10 14:24:32 +08:00
|
|
|
auto search_conf = knowhere::Json{{knowhere::indexparam::NPROBE, 10}};
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-02-10 14:24:32 +08:00
|
|
|
auto database = knowhere::GenDataSet(N, dim, vec_col.data() + 1000 * dim);
|
2022-09-21 20:16:51 +08:00
|
|
|
indexing->BuildWithDataset(database, build_conf);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
auto vec_index = dynamic_cast<milvus::index::VectorIndex*>(indexing.get());
|
|
|
|
EXPECT_EQ(vec_index->Count(), N);
|
|
|
|
EXPECT_EQ(vec_index->GetDim(), dim);
|
2023-02-10 14:24:32 +08:00
|
|
|
auto query_dataset = knowhere::GenDataSet(num_queries, dim, query_ptr);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
milvus::SearchInfo searchInfo;
|
|
|
|
searchInfo.topk_ = topK;
|
|
|
|
searchInfo.metric_type_ = knowhere::metric::L2;
|
|
|
|
searchInfo.search_params_ = search_conf;
|
2024-02-21 14:02:53 +08:00
|
|
|
SearchResult result;
|
|
|
|
vec_index->Query(query_dataset, searchInfo, nullptr, result);
|
|
|
|
auto ref_result = SearchResultToJson(result);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
LoadIndexInfo load_info;
|
2021-01-22 15:41:54 +08:00
|
|
|
load_info.field_id = fake_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
load_info.index = std::move(indexing);
|
2020-12-29 11:56:37 +08:00
|
|
|
load_info.index_params["metric_type"] = "L2";
|
|
|
|
|
2023-06-21 14:00:42 +08:00
|
|
|
// load index for vec field, load raw data for scalar field
|
2022-05-26 14:58:01 +08:00
|
|
|
auto sealed_segment = SealedCreator(schema, dataset);
|
|
|
|
sealed_segment->DropFieldData(fake_id);
|
|
|
|
sealed_segment->LoadIndex(load_info);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
sr = sealed_segment->Search(plan.get(), ph_group.get(), timestamp);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2021-12-02 11:45:32 +08:00
|
|
|
auto post_result = SearchResultToJson(*sr);
|
2021-10-13 16:54:34 +08:00
|
|
|
std::cout << "ref_result" << std::endl;
|
2021-10-08 17:39:55 +08:00
|
|
|
std::cout << ref_result.dump(1) << std::endl;
|
|
|
|
std::cout << "post_result" << std::endl;
|
2020-12-29 11:56:37 +08:00
|
|
|
std::cout << post_result.dump(1);
|
2021-10-08 17:39:55 +08:00
|
|
|
// ASSERT_EQ(ref_result.dump(1), post_result.dump(1));
|
2024-01-09 11:38:48 +08:00
|
|
|
|
|
|
|
sr = sealed_segment->Search(plan.get(), ph_group.get(), 0);
|
|
|
|
EXPECT_EQ(sr->get_total_result_count(), 0);
|
2020-12-29 11:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, with_predicate) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
2022-06-29 14:20:19 +08:00
|
|
|
auto metric_type = knowhere::metric::L2;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fake_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto i64_fid = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(i64_fid);
|
2023-07-04 18:30:25 +08:00
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 101
|
|
|
|
data_type: Int64
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
int64_val: 4200
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
int64_val: 4205
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 6
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2021-09-23 16:55:54 +08:00
|
|
|
auto N = ROW_COUNT;
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto vec_col = dataset.get_col<float>(fake_id);
|
2023-04-07 14:20:29 +08:00
|
|
|
auto query_ptr = vec_col.data() + BIAS * dim;
|
2023-04-26 10:14:41 +08:00
|
|
|
auto segment = CreateGrowingSegment(schema, empty_index_meta);
|
2020-12-29 11:56:37 +08:00
|
|
|
segment->PreInsert(N);
|
2023-03-10 09:47:54 +08:00
|
|
|
segment->Insert(0,
|
|
|
|
N,
|
|
|
|
dataset.row_ids_.data(),
|
|
|
|
dataset.timestamps_.data(),
|
|
|
|
dataset.raw_);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2020-12-29 11:56:37 +08:00
|
|
|
auto num_queries = 5;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group_raw =
|
|
|
|
CreatePlaceholderGroupFromBlob(num_queries, 16, query_ptr);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
std::vector<const PlaceholderGroup*> ph_group_arr = {ph_group.get()};
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
2022-09-21 20:16:51 +08:00
|
|
|
milvus::index::CreateIndexInfo create_index_info;
|
|
|
|
create_index_info.field_type = DataType::VECTOR_FLOAT;
|
|
|
|
create_index_info.metric_type = knowhere::metric::L2;
|
|
|
|
create_index_info.index_type = knowhere::IndexEnum::INDEX_FAISS_IVFFLAT;
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info.index_engine_version =
|
2023-09-25 21:39:27 +08:00
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto indexing = milvus::index::IndexFactory::GetInstance().CreateIndex(
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info, milvus::storage::FileManagerContext());
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto build_conf =
|
|
|
|
knowhere::Json{{knowhere::meta::METRIC_TYPE, knowhere::metric::L2},
|
|
|
|
{knowhere::meta::DIM, std::to_string(dim)},
|
|
|
|
{knowhere::indexparam::NLIST, "100"}};
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-02-10 14:24:32 +08:00
|
|
|
auto database = knowhere::GenDataSet(N, dim, vec_col.data());
|
2022-09-21 20:16:51 +08:00
|
|
|
indexing->BuildWithDataset(database, build_conf);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
auto vec_index = dynamic_cast<index::VectorIndex*>(indexing.get());
|
|
|
|
EXPECT_EQ(vec_index->Count(), N);
|
|
|
|
EXPECT_EQ(vec_index->GetDim(), dim);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2023-02-10 14:24:32 +08:00
|
|
|
auto query_dataset = knowhere::GenDataSet(num_queries, dim, query_ptr);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
auto search_conf =
|
2023-03-10 09:47:54 +08:00
|
|
|
knowhere::Json{{knowhere::meta::METRIC_TYPE, knowhere::metric::L2},
|
|
|
|
{knowhere::indexparam::NPROBE, 10}};
|
2022-09-21 20:16:51 +08:00
|
|
|
milvus::SearchInfo searchInfo;
|
|
|
|
searchInfo.topk_ = topK;
|
|
|
|
searchInfo.metric_type_ = knowhere::metric::L2;
|
|
|
|
searchInfo.search_params_ = search_conf;
|
2024-02-21 14:02:53 +08:00
|
|
|
SearchResult result;
|
|
|
|
vec_index->Query(query_dataset, searchInfo, nullptr, result);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
LoadIndexInfo load_info;
|
2021-01-22 15:41:54 +08:00
|
|
|
load_info.field_id = fake_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
load_info.index = std::move(indexing);
|
2020-12-29 11:56:37 +08:00
|
|
|
load_info.index_params["metric_type"] = "L2";
|
|
|
|
|
2023-06-21 14:00:42 +08:00
|
|
|
// load index for vec field, load raw data for scalar field
|
2022-05-26 14:58:01 +08:00
|
|
|
auto sealed_segment = SealedCreator(schema, dataset);
|
|
|
|
sealed_segment->DropFieldData(fake_id);
|
|
|
|
sealed_segment->LoadIndex(load_info);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
sr = sealed_segment->Search(plan.get(), ph_group.get(), timestamp);
|
2020-12-29 11:56:37 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < num_queries; ++i) {
|
|
|
|
auto offset = i * topK;
|
2023-04-07 14:20:29 +08:00
|
|
|
ASSERT_EQ(sr->seg_offsets_[offset], BIAS + i);
|
2021-12-02 11:45:32 +08:00
|
|
|
ASSERT_EQ(sr->distances_[offset], 0.0);
|
2020-12-29 11:56:37 +08:00
|
|
|
}
|
2021-01-20 10:15:43 +08:00
|
|
|
}
|
|
|
|
|
2022-07-28 12:36:30 +08:00
|
|
|
TEST(Sealed, with_predicate_filter_all) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
// auto metric_type = MetricType::METRIC_L2;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fake_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-07-28 12:36:30 +08:00
|
|
|
auto i64_fid = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(i64_fid);
|
2023-07-04 18:30:25 +08:00
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 101
|
|
|
|
data_type: Int64
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
int64_val: 4200
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
int64_val: 4199
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 6
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2022-07-28 12:36:30 +08:00
|
|
|
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto vec_col = dataset.get_col<float>(fake_id);
|
2023-04-07 14:20:29 +08:00
|
|
|
auto query_ptr = vec_col.data() + BIAS * dim;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2022-07-28 12:36:30 +08:00
|
|
|
auto num_queries = 5;
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group_raw =
|
|
|
|
CreatePlaceholderGroupFromBlob(num_queries, 16, query_ptr);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2022-07-28 12:36:30 +08:00
|
|
|
|
|
|
|
std::vector<const PlaceholderGroup*> ph_group_arr = {ph_group.get()};
|
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
milvus::index::CreateIndexInfo create_index_info;
|
|
|
|
create_index_info.field_type = DataType::VECTOR_FLOAT;
|
|
|
|
create_index_info.metric_type = knowhere::metric::L2;
|
|
|
|
create_index_info.index_type = knowhere::IndexEnum::INDEX_FAISS_IVFFLAT;
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info.index_engine_version =
|
2023-09-25 21:39:27 +08:00
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ivf_indexing = milvus::index::IndexFactory::GetInstance().CreateIndex(
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info, milvus::storage::FileManagerContext());
|
2022-07-28 12:36:30 +08:00
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ivf_build_conf =
|
|
|
|
knowhere::Json{{knowhere::meta::DIM, std::to_string(dim)},
|
|
|
|
{knowhere::indexparam::NLIST, "100"},
|
|
|
|
{knowhere::meta::METRIC_TYPE, knowhere::metric::L2}};
|
2022-07-28 12:36:30 +08:00
|
|
|
|
2023-02-10 14:24:32 +08:00
|
|
|
auto database = knowhere::GenDataSet(N, dim, vec_col.data());
|
2022-09-21 20:16:51 +08:00
|
|
|
ivf_indexing->BuildWithDataset(database, ivf_build_conf);
|
2022-07-28 12:36:30 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
auto ivf_vec_index = dynamic_cast<index::VectorIndex*>(ivf_indexing.get());
|
|
|
|
EXPECT_EQ(ivf_vec_index->Count(), N);
|
|
|
|
EXPECT_EQ(ivf_vec_index->GetDim(), dim);
|
2022-07-28 12:36:30 +08:00
|
|
|
|
|
|
|
LoadIndexInfo load_info;
|
|
|
|
load_info.field_id = fake_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
load_info.index = std::move(ivf_indexing);
|
2022-07-28 12:36:30 +08:00
|
|
|
load_info.index_params["metric_type"] = "L2";
|
|
|
|
|
2023-06-21 14:00:42 +08:00
|
|
|
// load index for vec field, load raw data for scalar field
|
2022-07-28 12:36:30 +08:00
|
|
|
auto ivf_sealed_segment = SealedCreator(schema, dataset);
|
|
|
|
ivf_sealed_segment->DropFieldData(fake_id);
|
|
|
|
ivf_sealed_segment->LoadIndex(load_info);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = ivf_sealed_segment->Search(plan.get(), ph_group.get(), timestamp);
|
2023-12-20 12:56:42 +08:00
|
|
|
EXPECT_EQ(sr->unity_topK_, 0);
|
2022-07-28 12:36:30 +08:00
|
|
|
EXPECT_EQ(sr->get_total_result_count(), 0);
|
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto hnsw_conf =
|
|
|
|
knowhere::Json{{knowhere::meta::DIM, std::to_string(dim)},
|
|
|
|
{knowhere::indexparam::HNSW_M, "16"},
|
|
|
|
{knowhere::indexparam::EFCONSTRUCTION, "200"},
|
|
|
|
{knowhere::indexparam::EF, "200"},
|
|
|
|
{knowhere::meta::METRIC_TYPE, knowhere::metric::L2}};
|
2022-07-28 12:36:30 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
create_index_info.field_type = DataType::VECTOR_FLOAT;
|
|
|
|
create_index_info.metric_type = knowhere::metric::L2;
|
|
|
|
create_index_info.index_type = knowhere::IndexEnum::INDEX_HNSW;
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info.index_engine_version =
|
2023-09-25 21:39:27 +08:00
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto hnsw_indexing = milvus::index::IndexFactory::GetInstance().CreateIndex(
|
2023-09-22 09:59:26 +08:00
|
|
|
create_index_info, milvus::storage::FileManagerContext());
|
2022-09-21 20:16:51 +08:00
|
|
|
hnsw_indexing->BuildWithDataset(database, hnsw_conf);
|
2022-07-28 12:36:30 +08:00
|
|
|
|
2023-03-10 09:47:54 +08:00
|
|
|
auto hnsw_vec_index =
|
|
|
|
dynamic_cast<index::VectorIndex*>(hnsw_indexing.get());
|
2022-09-21 20:16:51 +08:00
|
|
|
EXPECT_EQ(hnsw_vec_index->Count(), N);
|
|
|
|
EXPECT_EQ(hnsw_vec_index->GetDim(), dim);
|
2022-07-28 12:36:30 +08:00
|
|
|
|
|
|
|
LoadIndexInfo hnsw_load_info;
|
|
|
|
hnsw_load_info.field_id = fake_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
hnsw_load_info.index = std::move(hnsw_indexing);
|
2022-07-28 12:36:30 +08:00
|
|
|
hnsw_load_info.index_params["metric_type"] = "L2";
|
|
|
|
|
2023-06-21 14:00:42 +08:00
|
|
|
// load index for vec field, load raw data for scalar field
|
2022-07-28 12:36:30 +08:00
|
|
|
auto hnsw_sealed_segment = SealedCreator(schema, dataset);
|
|
|
|
hnsw_sealed_segment->DropFieldData(fake_id);
|
|
|
|
hnsw_sealed_segment->LoadIndex(hnsw_load_info);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr2 =
|
|
|
|
hnsw_sealed_segment->Search(plan.get(), ph_group.get(), timestamp);
|
2023-12-20 12:56:42 +08:00
|
|
|
EXPECT_EQ(sr2->unity_topK_, 0);
|
2022-07-28 12:36:30 +08:00
|
|
|
EXPECT_EQ(sr2->get_total_result_count(), 0);
|
|
|
|
}
|
|
|
|
|
2021-01-20 10:15:43 +08:00
|
|
|
TEST(Sealed, LoadFieldData) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
2021-09-23 17:55:54 +08:00
|
|
|
auto N = ROW_COUNT;
|
2022-06-29 14:20:19 +08:00
|
|
|
auto metric_type = knowhere::metric::L2;
|
2021-01-20 10:15:43 +08:00
|
|
|
auto schema = std::make_shared<Schema>();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2021-01-26 09:38:40 +08:00
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
2022-05-17 20:15:55 +08:00
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
2023-03-01 18:07:49 +08:00
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
2023-04-21 11:46:32 +08:00
|
|
|
schema->AddDebugField("json", DataType::JSON);
|
2023-09-19 14:23:23 +08:00
|
|
|
schema->AddDebugField("array", DataType::ARRAY, DataType::INT64);
|
2022-04-29 13:35:49 +08:00
|
|
|
schema->set_primary_field_id(counter_id);
|
2021-01-20 17:33:31 +08:00
|
|
|
|
2021-01-20 10:15:43 +08:00
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
2021-01-20 10:15:43 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto indexing = GenVecIndexing(
|
|
|
|
N, dim, fakevec.data(), knowhere::IndexEnum::INDEX_FAISS_IVFFLAT);
|
2021-01-20 10:15:43 +08:00
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2023-07-04 18:30:25 +08:00
|
|
|
// std::string dsl = R"({
|
|
|
|
// "bool": {
|
|
|
|
// "must": [
|
|
|
|
// {
|
|
|
|
// "range": {
|
|
|
|
// "double": {
|
|
|
|
// "GE": -1,
|
|
|
|
// "LT": 1
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "vector": {
|
|
|
|
// "fakevec": {
|
|
|
|
// "metric_type": "L2",
|
|
|
|
// "params": {
|
|
|
|
// "nprobe": 10
|
|
|
|
// },
|
|
|
|
// "query": "$0",
|
|
|
|
// "topk": 5,
|
|
|
|
// "round_decimal": 3
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
// })";
|
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2021-01-21 15:29:52 +08:00
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2021-01-21 15:29:52 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2021-01-26 09:38:40 +08:00
|
|
|
|
2022-05-26 14:58:01 +08:00
|
|
|
SealedLoadFieldData(dataset, *segment);
|
2024-01-09 11:38:48 +08:00
|
|
|
segment->Search(plan.get(), ph_group.get(), timestamp);
|
2021-01-26 09:38:40 +08:00
|
|
|
|
2021-02-07 15:47:10 +08:00
|
|
|
segment->DropFieldData(fakevec_id);
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2021-01-26 09:38:40 +08:00
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
vec_info.index = std::move(indexing);
|
2022-06-24 10:34:18 +08:00
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
2021-01-26 09:38:40 +08:00
|
|
|
segment->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
ASSERT_EQ(segment->num_chunk(), 1);
|
2022-05-26 14:58:01 +08:00
|
|
|
ASSERT_EQ(segment->num_chunk_index(double_id), 0);
|
|
|
|
ASSERT_EQ(segment->num_chunk_index(str_id), 0);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto chunk_span1 = segment->chunk_data<int64_t>(counter_id, 0);
|
|
|
|
auto chunk_span2 = segment->chunk_data<double>(double_id, 0);
|
2024-06-30 20:16:06 +08:00
|
|
|
auto chunk_span3 =
|
|
|
|
segment->get_batch_views<std::string_view>(str_id, 0, 0, N);
|
2023-03-01 18:07:49 +08:00
|
|
|
auto ref1 = dataset.get_col<int64_t>(counter_id);
|
|
|
|
auto ref2 = dataset.get_col<double>(double_id);
|
|
|
|
auto ref3 = dataset.get_col(str_id)->scalars().string_data().data();
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
ASSERT_EQ(chunk_span1[i], ref1[i]);
|
|
|
|
ASSERT_EQ(chunk_span2[i], ref2[i]);
|
|
|
|
ASSERT_EQ(chunk_span3[i], ref3[i]);
|
|
|
|
}
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
2023-03-01 18:07:49 +08:00
|
|
|
auto json = SearchResultToJson(*sr);
|
|
|
|
std::cout << json.dump(1);
|
|
|
|
|
|
|
|
segment->DropIndex(fakevec_id);
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2023-03-01 18:07:49 +08:00
|
|
|
}
|
|
|
|
|
2024-02-27 20:58:40 +08:00
|
|
|
TEST(Sealed, ClearData) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
schema->AddDebugField("json", DataType::JSON);
|
|
|
|
schema->AddDebugField("array", DataType::ARRAY, DataType::INT64);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
|
|
|
|
auto indexing = GenVecIndexing(
|
|
|
|
N, dim, fakevec.data(), knowhere::IndexEnum::INDEX_FAISS_IVFFLAT);
|
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
// std::string dsl = R"({
|
|
|
|
// "bool": {
|
|
|
|
// "must": [
|
|
|
|
// {
|
|
|
|
// "range": {
|
|
|
|
// "double": {
|
|
|
|
// "GE": -1,
|
|
|
|
// "LT": 1
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "vector": {
|
|
|
|
// "fakevec": {
|
|
|
|
// "metric_type": "L2",
|
|
|
|
// "params": {
|
|
|
|
// "nprobe": 10
|
|
|
|
// },
|
|
|
|
// "query": "$0",
|
|
|
|
// "topk": 5,
|
|
|
|
// "round_decimal": 3
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
// })";
|
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
|
|
|
Timestamp timestamp = 1000000;
|
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
|
|
|
|
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
|
|
|
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
|
|
|
segment->Search(plan.get(), ph_group.get(), timestamp);
|
|
|
|
|
|
|
|
segment->DropFieldData(fakevec_id);
|
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
|
|
|
segment->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
ASSERT_EQ(segment->num_chunk(), 1);
|
|
|
|
ASSERT_EQ(segment->num_chunk_index(double_id), 0);
|
|
|
|
ASSERT_EQ(segment->num_chunk_index(str_id), 0);
|
|
|
|
auto chunk_span1 = segment->chunk_data<int64_t>(counter_id, 0);
|
|
|
|
auto chunk_span2 = segment->chunk_data<double>(double_id, 0);
|
2024-06-30 20:16:06 +08:00
|
|
|
auto chunk_span3 =
|
|
|
|
segment->get_batch_views<std::string_view>(str_id, 0, 0, N);
|
2024-02-27 20:58:40 +08:00
|
|
|
auto ref1 = dataset.get_col<int64_t>(counter_id);
|
|
|
|
auto ref2 = dataset.get_col<double>(double_id);
|
|
|
|
auto ref3 = dataset.get_col(str_id)->scalars().string_data().data();
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
ASSERT_EQ(chunk_span1[i], ref1[i]);
|
|
|
|
ASSERT_EQ(chunk_span2[i], ref2[i]);
|
|
|
|
ASSERT_EQ(chunk_span3[i], ref3[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
|
|
|
auto json = SearchResultToJson(*sr);
|
|
|
|
std::cout << json.dump(1);
|
|
|
|
|
|
|
|
auto sealed_segment = (SegmentSealedImpl*)segment.get();
|
|
|
|
sealed_segment->ClearData();
|
|
|
|
ASSERT_EQ(sealed_segment->get_row_count(), 0);
|
|
|
|
ASSERT_EQ(sealed_segment->get_real_count(), 0);
|
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
|
|
|
}
|
|
|
|
|
2023-03-01 18:07:49 +08:00
|
|
|
TEST(Sealed, LoadFieldDataMmap) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2023-03-01 18:07:49 +08:00
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
2023-04-21 11:46:32 +08:00
|
|
|
schema->AddDebugField("json", DataType::JSON);
|
2023-09-19 14:23:23 +08:00
|
|
|
schema->AddDebugField("array", DataType::ARRAY, DataType::INT64);
|
2023-03-01 18:07:49 +08:00
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto indexing = GenVecIndexing(
|
|
|
|
N, dim, fakevec.data(), knowhere::IndexEnum::INDEX_FAISS_IVFFLAT);
|
2023-03-01 18:07:49 +08:00
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2023-07-04 18:30:25 +08:00
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2023-03-01 18:07:49 +08:00
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2023-03-01 18:07:49 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2023-03-01 18:07:49 +08:00
|
|
|
|
|
|
|
SealedLoadFieldData(dataset, *segment, {}, true);
|
2024-01-09 11:38:48 +08:00
|
|
|
segment->Search(plan.get(), ph_group.get(), timestamp);
|
2023-03-01 18:07:49 +08:00
|
|
|
|
|
|
|
segment->DropFieldData(fakevec_id);
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2023-03-01 18:07:49 +08:00
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
|
|
|
segment->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
ASSERT_EQ(segment->num_chunk(), 1);
|
|
|
|
ASSERT_EQ(segment->num_chunk_index(double_id), 0);
|
|
|
|
ASSERT_EQ(segment->num_chunk_index(str_id), 0);
|
|
|
|
auto chunk_span1 = segment->chunk_data<int64_t>(counter_id, 0);
|
|
|
|
auto chunk_span2 = segment->chunk_data<double>(double_id, 0);
|
2024-06-30 20:16:06 +08:00
|
|
|
auto chunk_span3 =
|
|
|
|
segment->get_batch_views<std::string_view>(str_id, 0, 0, N);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto ref1 = dataset.get_col<int64_t>(counter_id);
|
|
|
|
auto ref2 = dataset.get_col<double>(double_id);
|
2022-05-17 20:15:55 +08:00
|
|
|
auto ref3 = dataset.get_col(str_id)->scalars().string_data().data();
|
2021-01-26 09:38:40 +08:00
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
ASSERT_EQ(chunk_span1[i], ref1[i]);
|
|
|
|
ASSERT_EQ(chunk_span2[i], ref2[i]);
|
2022-05-17 20:15:55 +08:00
|
|
|
ASSERT_EQ(chunk_span3[i], ref3[i]);
|
2021-01-26 09:38:40 +08:00
|
|
|
}
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
2021-12-02 11:45:32 +08:00
|
|
|
auto json = SearchResultToJson(*sr);
|
2021-01-21 15:29:52 +08:00
|
|
|
std::cout << json.dump(1);
|
2021-01-26 09:38:40 +08:00
|
|
|
|
|
|
|
segment->DropIndex(fakevec_id);
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2021-10-22 13:11:11 +08:00
|
|
|
}
|
|
|
|
|
2024-02-07 14:56:47 +08:00
|
|
|
TEST(Sealed, LoadPkScalarIndex) {
|
|
|
|
size_t N = ROW_COUNT;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto pk_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
schema->set_primary_field_id(pk_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
auto fields = schema->get_fields();
|
|
|
|
for (auto field_data : dataset.raw_->fields_data()) {
|
|
|
|
int64_t field_id = field_data.field_id();
|
|
|
|
|
|
|
|
auto info = FieldDataInfo(field_data.field_id(), N);
|
|
|
|
auto field_meta = fields.at(FieldId(field_id));
|
|
|
|
info.channel->push(
|
|
|
|
CreateFieldDataFromDataArray(N, &field_data, field_meta));
|
|
|
|
info.channel->close();
|
|
|
|
|
|
|
|
segment->LoadFieldData(FieldId(field_id), info);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadIndexInfo pk_index;
|
|
|
|
pk_index.field_id = pk_id.get();
|
|
|
|
pk_index.field_type = DataType::INT64;
|
|
|
|
pk_index.index_params["index_type"] = "sort";
|
|
|
|
auto pk_data = dataset.get_col<int64_t>(pk_id);
|
|
|
|
pk_index.index = GenScalarIndexing<int64_t>(N, pk_data.data());
|
|
|
|
segment->LoadIndex(pk_index);
|
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
TEST(Sealed, LoadScalarIndex) {
|
|
|
|
auto dim = 16;
|
2023-07-06 13:58:27 +08:00
|
|
|
size_t N = ROW_COUNT;
|
2022-06-29 14:20:19 +08:00
|
|
|
auto metric_type = knowhere::metric::L2;
|
2022-04-29 13:35:49 +08:00
|
|
|
auto schema = std::make_shared<Schema>();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto indexing = GenVecIndexing(
|
|
|
|
N, dim, fakevec.data(), knowhere::IndexEnum::INDEX_FAISS_IVFFLAT);
|
2022-04-29 13:35:49 +08:00
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2023-07-04 18:30:25 +08:00
|
|
|
// std::string dsl = R"({
|
|
|
|
// "bool": {
|
|
|
|
// "must": [
|
|
|
|
// {
|
|
|
|
// "range": {
|
|
|
|
// "double": {
|
|
|
|
// "GE": -1,
|
|
|
|
// "LT": 1
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// "vector": {
|
|
|
|
// "fakevec": {
|
|
|
|
// "metric_type": "L2",
|
|
|
|
// "params": {
|
|
|
|
// "nprobe": 10
|
|
|
|
// },
|
|
|
|
// "query": "$0",
|
|
|
|
// "topk": 5,
|
|
|
|
// "round_decimal": 3
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// }
|
|
|
|
// })";
|
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2022-04-29 13:35:49 +08:00
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2022-04-29 13:35:49 +08:00
|
|
|
|
2022-05-26 14:58:01 +08:00
|
|
|
LoadFieldDataInfo row_id_info;
|
2023-03-10 09:47:54 +08:00
|
|
|
FieldMeta row_id_field_meta(
|
|
|
|
FieldName("RowID"), RowFieldID, DataType::INT64);
|
2023-06-25 14:38:44 +08:00
|
|
|
auto field_data =
|
2023-12-18 12:04:42 +08:00
|
|
|
std::make_shared<milvus::FieldData<int64_t>>(DataType::INT64);
|
2023-06-25 14:38:44 +08:00
|
|
|
field_data->FillFieldData(dataset.row_ids_.data(), N);
|
|
|
|
auto field_data_info = FieldDataInfo{
|
2023-12-18 12:04:42 +08:00
|
|
|
RowFieldID.get(), N, std::vector<FieldDataPtr>{field_data}};
|
2023-06-25 14:38:44 +08:00
|
|
|
segment->LoadFieldData(RowFieldID, field_data_info);
|
2022-05-26 14:58:01 +08:00
|
|
|
|
|
|
|
LoadFieldDataInfo ts_info;
|
2023-03-10 09:47:54 +08:00
|
|
|
FieldMeta ts_field_meta(
|
|
|
|
FieldName("Timestamp"), TimestampFieldID, DataType::INT64);
|
2023-12-18 12:04:42 +08:00
|
|
|
field_data = std::make_shared<milvus::FieldData<int64_t>>(DataType::INT64);
|
2023-06-25 14:38:44 +08:00
|
|
|
field_data->FillFieldData(dataset.timestamps_.data(), N);
|
2023-12-18 12:04:42 +08:00
|
|
|
field_data_info = FieldDataInfo{
|
|
|
|
TimestampFieldID.get(), N, std::vector<FieldDataPtr>{field_data}};
|
2023-06-25 14:38:44 +08:00
|
|
|
segment->LoadFieldData(TimestampFieldID, field_data_info);
|
2022-04-29 13:35:49 +08:00
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
vec_info.field_type = DataType::VECTOR_FLOAT;
|
|
|
|
vec_info.index = std::move(indexing);
|
2022-06-24 10:34:18 +08:00
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
2022-04-29 13:35:49 +08:00
|
|
|
segment->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
LoadIndexInfo counter_index;
|
|
|
|
counter_index.field_id = counter_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
counter_index.field_type = DataType::INT64;
|
2022-04-29 13:35:49 +08:00
|
|
|
counter_index.index_params["index_type"] = "sort";
|
|
|
|
auto counter_data = dataset.get_col<int64_t>(counter_id);
|
2023-08-10 18:53:17 +08:00
|
|
|
counter_index.index = GenScalarIndexing<int64_t>(N, counter_data.data());
|
2022-04-29 13:35:49 +08:00
|
|
|
segment->LoadIndex(counter_index);
|
|
|
|
|
|
|
|
LoadIndexInfo double_index;
|
|
|
|
double_index.field_id = double_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
double_index.field_type = DataType::DOUBLE;
|
2022-04-29 13:35:49 +08:00
|
|
|
double_index.index_params["index_type"] = "sort";
|
|
|
|
auto double_data = dataset.get_col<double>(double_id);
|
2023-08-10 18:53:17 +08:00
|
|
|
double_index.index = GenScalarIndexing<double>(N, double_data.data());
|
2022-04-29 13:35:49 +08:00
|
|
|
segment->LoadIndex(double_index);
|
|
|
|
|
|
|
|
LoadIndexInfo nothing_index;
|
|
|
|
nothing_index.field_id = nothing_id.get();
|
2022-09-21 20:16:51 +08:00
|
|
|
nothing_index.field_type = DataType::INT32;
|
2022-04-29 13:35:49 +08:00
|
|
|
nothing_index.index_params["index_type"] = "sort";
|
|
|
|
auto nothing_data = dataset.get_col<int32_t>(nothing_id);
|
2023-08-10 18:53:17 +08:00
|
|
|
nothing_index.index = GenScalarIndexing<int32_t>(N, nothing_data.data());
|
2022-04-29 13:35:49 +08:00
|
|
|
segment->LoadIndex(nothing_index);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto sr = segment->Search(plan.get(), ph_group.get(), timestamp);
|
2022-04-29 13:35:49 +08:00
|
|
|
auto json = SearchResultToJson(*sr);
|
|
|
|
std::cout << json.dump(1);
|
|
|
|
}
|
|
|
|
|
2021-10-22 13:11:11 +08:00
|
|
|
TEST(Sealed, Delete) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = 10;
|
2022-06-29 14:20:19 +08:00
|
|
|
auto metric_type = knowhere::metric::L2;
|
2021-10-22 13:11:11 +08:00
|
|
|
auto schema = std::make_shared<Schema>();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2021-10-22 13:11:11 +08:00
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
2022-04-29 13:35:49 +08:00
|
|
|
schema->set_primary_field_id(counter_id);
|
2021-10-22 13:11:11 +08:00
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
2021-10-22 13:11:11 +08:00
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2023-07-04 18:30:25 +08:00
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2021-10-22 13:11:11 +08:00
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2021-10-22 13:11:11 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2021-10-22 13:11:11 +08:00
|
|
|
|
2022-05-26 14:58:01 +08:00
|
|
|
SealedLoadFieldData(dataset, *segment);
|
2021-10-22 13:11:11 +08:00
|
|
|
|
|
|
|
int64_t row_count = 5;
|
|
|
|
std::vector<idx_t> pks{1, 2, 3, 4, 5};
|
2022-04-29 13:35:49 +08:00
|
|
|
auto ids = std::make_unique<IdArray>();
|
|
|
|
ids->mutable_int_id()->mutable_data()->Add(pks.begin(), pks.end());
|
2021-10-22 13:11:11 +08:00
|
|
|
std::vector<Timestamp> timestamps{10, 10, 10, 10, 10};
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
LoadDeletedRecordInfo info = {timestamps.data(), ids.get(), row_count};
|
2021-10-22 13:11:11 +08:00
|
|
|
segment->LoadDeletedRecord(info);
|
|
|
|
|
2022-04-14 22:37:34 +08:00
|
|
|
BitsetType bitset(N, false);
|
|
|
|
segment->mask_with_delete(bitset, 10, 11);
|
|
|
|
ASSERT_EQ(bitset.count(), pks.size());
|
2021-10-22 23:35:18 +08:00
|
|
|
|
|
|
|
int64_t new_count = 3;
|
|
|
|
std::vector<idx_t> new_pks{6, 7, 8};
|
2022-04-29 13:35:49 +08:00
|
|
|
auto new_ids = std::make_unique<IdArray>();
|
2023-03-10 09:47:54 +08:00
|
|
|
new_ids->mutable_int_id()->mutable_data()->Add(new_pks.begin(),
|
|
|
|
new_pks.end());
|
2021-10-22 23:35:18 +08:00
|
|
|
std::vector<idx_t> new_timestamps{10, 10, 10};
|
2023-06-16 17:16:41 +08:00
|
|
|
auto reserved_offset = segment->get_deleted_count();
|
2021-10-24 14:19:10 +08:00
|
|
|
ASSERT_EQ(reserved_offset, row_count);
|
2023-03-10 09:47:54 +08:00
|
|
|
segment->Delete(reserved_offset,
|
|
|
|
new_count,
|
|
|
|
new_ids.get(),
|
2021-10-24 14:19:10 +08:00
|
|
|
reinterpret_cast<const Timestamp*>(new_timestamps.data()));
|
2021-10-22 13:11:11 +08:00
|
|
|
}
|
2022-07-05 19:48:20 +08:00
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
TEST(Sealed, OverlapDelete) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = 10;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
2023-04-21 11:46:32 +08:00
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2023-03-27 00:42:00 +08:00
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2023-07-04 18:30:25 +08:00
|
|
|
const char* raw_plan = R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
predicates: <
|
|
|
|
binary_range_expr: <
|
|
|
|
column_info: <
|
|
|
|
field_id: 102
|
|
|
|
data_type: Double
|
|
|
|
>
|
|
|
|
lower_inclusive: true,
|
|
|
|
upper_inclusive: false,
|
|
|
|
lower_value: <
|
|
|
|
float_val: -1
|
|
|
|
>
|
|
|
|
upper_value: <
|
|
|
|
float_val: 1
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info: <
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0"
|
|
|
|
>)";
|
2024-01-09 11:38:48 +08:00
|
|
|
Timestamp timestamp = 1000000;
|
2023-07-04 18:30:25 +08:00
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
2023-03-27 00:42:00 +08:00
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
2023-04-21 11:46:32 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
ASSERT_ANY_THROW(segment->Search(plan.get(), ph_group.get(), timestamp));
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
|
|
|
|
|
|
|
int64_t row_count = 5;
|
|
|
|
std::vector<idx_t> pks{1, 2, 3, 4, 5};
|
|
|
|
auto ids = std::make_unique<IdArray>();
|
|
|
|
ids->mutable_int_id()->mutable_data()->Add(pks.begin(), pks.end());
|
|
|
|
std::vector<Timestamp> timestamps{10, 10, 10, 10, 10};
|
|
|
|
|
|
|
|
LoadDeletedRecordInfo info = {timestamps.data(), ids.get(), row_count};
|
|
|
|
segment->LoadDeletedRecord(info);
|
2024-07-16 14:25:39 +08:00
|
|
|
auto deleted_record1 = pks.size();
|
2023-03-27 00:42:00 +08:00
|
|
|
ASSERT_EQ(segment->get_deleted_count(), pks.size())
|
2023-04-21 11:46:32 +08:00
|
|
|
<< "deleted_count=" << segment->get_deleted_count()
|
|
|
|
<< " pks_count=" << pks.size() << std::endl;
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
// Load overlapping delete records
|
|
|
|
row_count += 3;
|
|
|
|
pks.insert(pks.end(), {6, 7, 8});
|
|
|
|
auto new_ids = std::make_unique<IdArray>();
|
|
|
|
new_ids->mutable_int_id()->mutable_data()->Add(pks.begin(), pks.end());
|
|
|
|
timestamps.insert(timestamps.end(), {11, 11, 11});
|
2023-04-21 11:46:32 +08:00
|
|
|
LoadDeletedRecordInfo overlap_info = {
|
|
|
|
timestamps.data(), new_ids.get(), row_count};
|
2023-03-27 00:42:00 +08:00
|
|
|
segment->LoadDeletedRecord(overlap_info);
|
|
|
|
|
|
|
|
BitsetType bitset(N, false);
|
2024-07-16 14:25:39 +08:00
|
|
|
auto deleted_record2 = pks.size();
|
|
|
|
ASSERT_EQ(segment->get_deleted_count(), deleted_record1 + deleted_record2)
|
2023-04-21 11:46:32 +08:00
|
|
|
<< "deleted_count=" << segment->get_deleted_count()
|
2024-07-16 14:25:39 +08:00
|
|
|
<< " pks_count=" << deleted_record1 + deleted_record2 << std::endl;
|
2023-03-27 00:42:00 +08:00
|
|
|
segment->mask_with_delete(bitset, 10, 12);
|
|
|
|
ASSERT_EQ(bitset.count(), pks.size())
|
2023-04-21 11:46:32 +08:00
|
|
|
<< "bitset_count=" << bitset.count() << " pks_count=" << pks.size()
|
|
|
|
<< std::endl;
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 19:48:20 +08:00
|
|
|
auto
|
|
|
|
GenMaxFloatVecs(int N, int dim) {
|
|
|
|
std::vector<float> vecs;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
for (int j = 0; j < dim; j++) {
|
|
|
|
vecs.push_back(std::numeric_limits<float>::max());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vecs;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto
|
|
|
|
GenRandomFloatVecs(int N, int dim) {
|
|
|
|
std::vector<float> vecs;
|
|
|
|
srand(time(NULL));
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
for (int j = 0; j < dim; j++) {
|
2023-03-10 09:47:54 +08:00
|
|
|
vecs.push_back(static_cast<float>(rand()) /
|
|
|
|
static_cast<float>(RAND_MAX));
|
2022-07-05 19:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return vecs;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto
|
|
|
|
GenQueryVecs(int N, int dim) {
|
|
|
|
std::vector<float> vecs;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
for (int j = 0; j < dim; j++) {
|
|
|
|
vecs.push_back(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vecs;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, BF) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 128;
|
|
|
|
auto metric_type = "L2";
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fake_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-07-05 19:48:20 +08:00
|
|
|
auto i64_fid = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(i64_fid);
|
|
|
|
|
2023-07-06 13:58:27 +08:00
|
|
|
size_t N = 100000;
|
2022-07-05 19:48:20 +08:00
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
std::cout << fake_id.get() << std::endl;
|
|
|
|
SealedLoadFieldData(dataset, *segment, {fake_id.get()});
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
auto vec_data = GenRandomFloatVecs(N, dim);
|
|
|
|
auto field_data = storage::CreateFieldData(DataType::VECTOR_FLOAT, dim);
|
|
|
|
field_data->FillFieldData(vec_data.data(), N);
|
2023-12-18 12:04:42 +08:00
|
|
|
auto field_data_info =
|
|
|
|
FieldDataInfo{fake_id.get(), N, std::vector<FieldDataPtr>{field_data}};
|
2023-06-25 14:38:44 +08:00
|
|
|
segment->LoadFieldData(fake_id, field_data_info);
|
2022-07-05 19:48:20 +08:00
|
|
|
|
|
|
|
auto topK = 1;
|
|
|
|
auto fmt = boost::format(R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
query_info: <
|
|
|
|
topk: %1%
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0">
|
|
|
|
output_field_ids: 101)") %
|
|
|
|
topK;
|
|
|
|
auto serialized_expr_plan = fmt.str();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto binary_plan =
|
|
|
|
translate_text_plan_to_binary_plan(serialized_expr_plan.data());
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, binary_plan.data(), binary_plan.size());
|
2022-07-05 19:48:20 +08:00
|
|
|
|
|
|
|
auto num_queries = 10;
|
|
|
|
auto query = GenQueryVecs(num_queries, dim);
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, dim, query);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2022-07-05 19:48:20 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto result = segment->Search(plan.get(), ph_group.get(), MAX_TIMESTAMP);
|
2022-07-05 19:48:20 +08:00
|
|
|
auto ves = SearchResultToVector(*result);
|
|
|
|
// first: offset, second: distance
|
2023-07-25 09:05:00 +08:00
|
|
|
EXPECT_GE(ves[0].first, 0);
|
2022-07-05 19:48:20 +08:00
|
|
|
EXPECT_LE(ves[0].first, N);
|
|
|
|
EXPECT_LE(ves[0].second, dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, BF_Overflow) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 128;
|
|
|
|
auto metric_type = "L2";
|
2023-03-10 09:47:54 +08:00
|
|
|
auto fake_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
2022-07-05 19:48:20 +08:00
|
|
|
auto i64_fid = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(i64_fid);
|
|
|
|
|
2023-07-06 13:58:27 +08:00
|
|
|
size_t N = 10;
|
2023-06-25 14:38:44 +08:00
|
|
|
|
2022-07-05 19:48:20 +08:00
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
2022-07-28 12:36:30 +08:00
|
|
|
std::cout << fake_id.get() << std::endl;
|
2022-07-05 19:48:20 +08:00
|
|
|
SealedLoadFieldData(dataset, *segment, {fake_id.get()});
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
auto vec_data = GenMaxFloatVecs(N, dim);
|
|
|
|
auto field_data = storage::CreateFieldData(DataType::VECTOR_FLOAT, dim);
|
|
|
|
field_data->FillFieldData(vec_data.data(), N);
|
2023-12-18 12:04:42 +08:00
|
|
|
auto field_data_info =
|
|
|
|
FieldDataInfo{fake_id.get(), N, std::vector<FieldDataPtr>{field_data}};
|
2023-06-25 14:38:44 +08:00
|
|
|
segment->LoadFieldData(fake_id, field_data_info);
|
2022-07-05 19:48:20 +08:00
|
|
|
|
|
|
|
auto topK = 1;
|
|
|
|
auto fmt = boost::format(R"(vector_anns: <
|
|
|
|
field_id: 100
|
|
|
|
query_info: <
|
|
|
|
topk: %1%
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
>
|
|
|
|
placeholder_tag: "$0">
|
|
|
|
output_field_ids: 101)") %
|
|
|
|
topK;
|
|
|
|
auto serialized_expr_plan = fmt.str();
|
2023-03-10 09:47:54 +08:00
|
|
|
auto binary_plan =
|
|
|
|
translate_text_plan_to_binary_plan(serialized_expr_plan.data());
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, binary_plan.data(), binary_plan.size());
|
2022-07-05 19:48:20 +08:00
|
|
|
|
|
|
|
auto num_queries = 10;
|
|
|
|
auto query = GenQueryVecs(num_queries, dim);
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, dim, query);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
2022-07-05 19:48:20 +08:00
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto result = segment->Search(plan.get(), ph_group.get(), MAX_TIMESTAMP);
|
2022-07-05 19:48:20 +08:00
|
|
|
auto ves = SearchResultToVector(*result);
|
|
|
|
for (int i = 0; i < num_queries; ++i) {
|
|
|
|
EXPECT_EQ(ves[0].first, -1);
|
|
|
|
}
|
2022-07-18 09:58:28 +08:00
|
|
|
}
|
|
|
|
|
2024-07-16 14:25:39 +08:00
|
|
|
TEST(Sealed, DeleteDuplicatedRecords) {
|
|
|
|
{
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto pk = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(pk);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
auto offset = segment->get_deleted_count();
|
|
|
|
ASSERT_EQ(offset, 0);
|
|
|
|
|
|
|
|
int64_t c = 1000;
|
|
|
|
// generate random pk that may have dupicated records
|
|
|
|
auto dataset = DataGen(schema, c, 42, 0, 1, 10, true);
|
|
|
|
auto pks = dataset.get_col<int64_t>(pk);
|
|
|
|
// current insert record: { pk: random(0 - 999) timestamp: (0 - 999) }
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
|
|
|
|
|
|
|
segment->RemoveDuplicatePkRecords();
|
|
|
|
|
|
|
|
BitsetType bits(c);
|
|
|
|
std::map<int64_t, std::vector<int64_t>> different_pks;
|
|
|
|
for (int i = 0; i < pks.size(); i++) {
|
|
|
|
if (different_pks.find(pks[i]) != different_pks.end()) {
|
|
|
|
different_pks[pks[i]].push_back(i);
|
|
|
|
} else {
|
|
|
|
different_pks[pks[i]] = {i};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& [k, v] : different_pks) {
|
|
|
|
if (v.size() > 1) {
|
|
|
|
for (int i = 0; i < v.size() - 1; i++) {
|
|
|
|
bits.set(v[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_EQ(segment->get_deleted_count(), c - different_pks.size())
|
|
|
|
<< "deleted_count=" << segment->get_deleted_count()
|
|
|
|
<< "duplicate_pks " << c - different_pks.size() << std::endl;
|
|
|
|
|
|
|
|
BitsetType bitset(c);
|
|
|
|
std::cout << "start to search delete" << std::endl;
|
|
|
|
segment->mask_with_delete(bitset, c, 1003);
|
|
|
|
|
|
|
|
for (int i = 0; i < bitset.size(); i++) {
|
|
|
|
ASSERT_EQ(bitset[i], bits[i]) << "index:" << i << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& [k, v] : different_pks) {
|
|
|
|
//std::cout << "k:" << k << "v:" << join(v, ",") << std::endl;
|
|
|
|
auto res = segment->SearchPk(k, Timestamp(1003));
|
|
|
|
ASSERT_EQ(res.size(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
TEST(Sealed, DeleteCount) {
|
2024-04-16 11:17:20 +08:00
|
|
|
{
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto pk = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(pk);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
auto offset = segment->get_deleted_count();
|
|
|
|
ASSERT_EQ(offset, 0);
|
2024-07-16 14:25:39 +08:00
|
|
|
int64_t c = 10;
|
|
|
|
auto dataset = DataGen(schema, c);
|
|
|
|
auto pks = dataset.get_col<int64_t>(pk);
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
2024-04-16 11:17:20 +08:00
|
|
|
|
|
|
|
Timestamp begin_ts = 100;
|
|
|
|
auto tss = GenTss(c, begin_ts);
|
2024-07-16 14:25:39 +08:00
|
|
|
auto delete_pks = GenPKs(c, 0);
|
|
|
|
auto status = segment->Delete(offset, c, delete_pks.get(), tss.data());
|
2024-04-16 11:17:20 +08:00
|
|
|
ASSERT_TRUE(status.ok());
|
|
|
|
|
|
|
|
// shouldn't be filtered for empty segment.
|
|
|
|
auto cnt = segment->get_deleted_count();
|
|
|
|
ASSERT_EQ(cnt, 10);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto pk = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(pk);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
int64_t c = 10;
|
|
|
|
auto dataset = DataGen(schema, c);
|
|
|
|
auto pks = dataset.get_col<int64_t>(pk);
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
|
|
|
|
|
|
|
auto offset = segment->get_deleted_count();
|
|
|
|
ASSERT_EQ(offset, 0);
|
|
|
|
|
|
|
|
auto iter = std::max_element(pks.begin(), pks.end());
|
|
|
|
auto delete_pks = GenPKs(c, *iter);
|
|
|
|
Timestamp begin_ts = 100;
|
|
|
|
auto tss = GenTss(c, begin_ts);
|
|
|
|
auto status = segment->Delete(offset, c, delete_pks.get(), tss.data());
|
|
|
|
ASSERT_TRUE(status.ok());
|
|
|
|
|
|
|
|
// 9 of element should be filtered.
|
|
|
|
auto cnt = segment->get_deleted_count();
|
|
|
|
ASSERT_EQ(cnt, 1);
|
|
|
|
}
|
2022-07-18 09:58:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, RealCount) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto pk = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
schema->set_primary_field_id(pk);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
2023-03-16 19:31:55 +08:00
|
|
|
ASSERT_EQ(0, segment->get_real_count());
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
int64_t c = 10;
|
|
|
|
auto dataset = DataGen(schema, c);
|
|
|
|
auto pks = dataset.get_col<int64_t>(pk);
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
|
|
|
|
|
|
|
// no delete.
|
|
|
|
ASSERT_EQ(c, segment->get_real_count());
|
|
|
|
|
|
|
|
// delete half.
|
|
|
|
auto half = c / 2;
|
2023-06-16 17:16:41 +08:00
|
|
|
auto del_offset1 = segment->get_deleted_count();
|
2022-07-18 09:58:28 +08:00
|
|
|
ASSERT_EQ(del_offset1, 0);
|
|
|
|
auto del_ids1 = GenPKs(pks.begin(), pks.begin() + half);
|
|
|
|
auto del_tss1 = GenTss(half, c);
|
2023-03-10 09:47:54 +08:00
|
|
|
auto status =
|
|
|
|
segment->Delete(del_offset1, half, del_ids1.get(), del_tss1.data());
|
2022-07-18 09:58:28 +08:00
|
|
|
ASSERT_TRUE(status.ok());
|
|
|
|
ASSERT_EQ(c - half, segment->get_real_count());
|
|
|
|
|
|
|
|
// delete duplicate.
|
2023-06-16 17:16:41 +08:00
|
|
|
auto del_offset2 = segment->get_deleted_count();
|
2022-07-18 09:58:28 +08:00
|
|
|
ASSERT_EQ(del_offset2, half);
|
|
|
|
auto del_tss2 = GenTss(half, c + half);
|
2023-03-10 09:47:54 +08:00
|
|
|
status =
|
|
|
|
segment->Delete(del_offset2, half, del_ids1.get(), del_tss2.data());
|
2022-07-18 09:58:28 +08:00
|
|
|
ASSERT_TRUE(status.ok());
|
|
|
|
ASSERT_EQ(c - half, segment->get_real_count());
|
|
|
|
|
|
|
|
// delete all.
|
2023-06-16 17:16:41 +08:00
|
|
|
auto del_offset3 = segment->get_deleted_count();
|
2022-07-18 09:58:28 +08:00
|
|
|
ASSERT_EQ(del_offset3, half * 2);
|
|
|
|
auto del_ids3 = GenPKs(pks.begin(), pks.end());
|
|
|
|
auto del_tss3 = GenTss(c, c + half * 2);
|
|
|
|
status = segment->Delete(del_offset3, c, del_ids3.get(), del_tss3.data());
|
|
|
|
ASSERT_TRUE(status.ok());
|
|
|
|
ASSERT_EQ(0, segment->get_real_count());
|
|
|
|
}
|
2023-04-23 09:00:32 +08:00
|
|
|
|
|
|
|
TEST(Sealed, GetVector) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
|
2024-01-09 11:38:48 +08:00
|
|
|
auto indexing = GenVecIndexing(
|
|
|
|
N, dim, fakevec.data(), knowhere::IndexEnum::INDEX_FAISS_IVFFLAT);
|
2023-04-23 09:00:32 +08:00
|
|
|
|
|
|
|
auto segment_sealed = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
|
|
|
segment_sealed->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
auto segment = dynamic_cast<SegmentSealedImpl*>(segment_sealed.get());
|
|
|
|
|
|
|
|
auto has = segment->HasRawData(vec_info.field_id);
|
|
|
|
EXPECT_TRUE(has);
|
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(N);
|
|
|
|
auto result = segment->get_vector(fakevec_id, ids_ds->GetIds(), N);
|
|
|
|
|
|
|
|
auto vector = result.get()->mutable_vectors()->float_vector().data();
|
|
|
|
EXPECT_TRUE(vector.size() == fakevec.size());
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
auto id = ids_ds->GetIds()[i];
|
|
|
|
for (size_t j = 0; j < dim; ++j) {
|
|
|
|
EXPECT_TRUE(vector[i * dim + j] == fakevec[id * dim + j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 10:21:20 +08:00
|
|
|
|
|
|
|
TEST(Sealed, GetVectorFromChunkCache) {
|
|
|
|
// skip test due to mem leak from AWS::InitSDK
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto index_type = knowhere::IndexEnum::INDEX_FAISS_IVFPQ;
|
|
|
|
|
|
|
|
auto file_name = std::string(
|
|
|
|
"sealed_test_get_vector_from_chunk_cache/insert_log/1/101/1000000");
|
|
|
|
|
|
|
|
auto sc = milvus::storage::StorageConfig{};
|
|
|
|
milvus::storage::RemoteChunkManagerSingleton::GetInstance().Init(sc);
|
|
|
|
auto mcm = std::make_unique<milvus::storage::MinioChunkManager>(sc);
|
2023-11-01 09:00:14 +08:00
|
|
|
// mcm->CreateBucket(sc.bucket_name);
|
2023-09-15 10:21:20 +08:00
|
|
|
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto field_data_meta =
|
|
|
|
milvus::storage::FieldDataMeta{1, 2, 3, fakevec_id.get()};
|
|
|
|
auto field_meta = milvus::FieldMeta(milvus::FieldName("facevec"),
|
|
|
|
fakevec_id,
|
|
|
|
milvus::DataType::VECTOR_FLOAT,
|
|
|
|
dim,
|
|
|
|
metric_type);
|
|
|
|
|
|
|
|
auto rcm = milvus::storage::RemoteChunkManagerSingleton::GetInstance()
|
|
|
|
.GetRemoteChunkManager();
|
|
|
|
auto data = dataset.get_col<float>(fakevec_id);
|
2024-06-12 10:09:55 +08:00
|
|
|
auto data_slices = std::vector<void*>{data.data()};
|
2023-09-15 10:21:20 +08:00
|
|
|
auto slice_sizes = std::vector<int64_t>{static_cast<int64_t>(N)};
|
|
|
|
auto slice_names = std::vector<std::string>{file_name};
|
|
|
|
PutFieldData(rcm.get(),
|
|
|
|
data_slices,
|
|
|
|
slice_sizes,
|
|
|
|
slice_names,
|
|
|
|
field_data_meta,
|
|
|
|
field_meta);
|
|
|
|
|
|
|
|
auto conf = generate_build_conf(index_type, metric_type);
|
2024-06-12 10:09:55 +08:00
|
|
|
auto ds = knowhere::GenDataSet(N, dim, data.data());
|
2023-11-11 13:20:22 +08:00
|
|
|
auto indexing = std::make_unique<index::VectorMemIndex<float>>(
|
2023-09-22 09:59:26 +08:00
|
|
|
index_type,
|
|
|
|
metric_type,
|
2023-09-25 21:39:27 +08:00
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber());
|
2023-09-15 10:21:20 +08:00
|
|
|
indexing->BuildWithDataset(ds, conf);
|
|
|
|
auto segment_sealed = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
|
|
|
segment_sealed->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
auto field_binlog_info =
|
|
|
|
FieldBinlogInfo{fakevec_id.get(),
|
|
|
|
N,
|
|
|
|
std::vector<int64_t>{N},
|
2023-11-02 23:52:16 +08:00
|
|
|
false,
|
2023-09-15 10:21:20 +08:00
|
|
|
std::vector<std::string>{file_name}};
|
2024-06-18 14:42:00 +08:00
|
|
|
segment_sealed->AddFieldDataInfoForSealed(
|
|
|
|
LoadFieldDataInfo{std::map<int64_t, FieldBinlogInfo>{
|
|
|
|
{fakevec_id.get(), field_binlog_info}}});
|
2023-09-15 10:21:20 +08:00
|
|
|
|
|
|
|
auto segment = dynamic_cast<SegmentSealedImpl*>(segment_sealed.get());
|
|
|
|
auto has = segment->HasRawData(vec_info.field_id);
|
|
|
|
EXPECT_FALSE(has);
|
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(N);
|
|
|
|
auto result =
|
|
|
|
segment->get_vector(fakevec_id, ids_ds->GetIds(), ids_ds->GetRows());
|
|
|
|
|
|
|
|
auto vector = result.get()->mutable_vectors()->float_vector().data();
|
2024-06-12 10:09:55 +08:00
|
|
|
EXPECT_TRUE(vector.size() == data.size());
|
2023-09-15 10:21:20 +08:00
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
auto id = ids_ds->GetIds()[i];
|
|
|
|
for (size_t j = 0; j < dim; ++j) {
|
2024-06-12 10:09:55 +08:00
|
|
|
auto expect = data[id * dim + j];
|
2023-09-15 10:21:20 +08:00
|
|
|
auto actual = vector[i * dim + j];
|
|
|
|
AssertInfo(expect == actual,
|
|
|
|
fmt::format("expect {}, actual {}", expect, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rcm->Remove(file_name);
|
|
|
|
auto exist = rcm->Exist(file_name);
|
|
|
|
Assert(!exist);
|
|
|
|
}
|
2023-09-19 14:23:23 +08:00
|
|
|
|
2024-06-12 10:09:55 +08:00
|
|
|
TEST(Sealed, GetSparseVectorFromChunkCache) {
|
|
|
|
// skip test due to mem leak from AWS::InitSDK
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::IP;
|
|
|
|
// TODO: remove SegmentSealedImpl::TEST_skip_index_for_retrieve_ after
|
|
|
|
// we have a type of sparse index that doesn't include raw data.
|
|
|
|
auto index_type = knowhere::IndexEnum::INDEX_SPARSE_INVERTED_INDEX;
|
|
|
|
|
|
|
|
auto file_name = std::string(
|
|
|
|
"sealed_test_get_vector_from_chunk_cache/insert_log/1/101/1000000");
|
|
|
|
|
|
|
|
auto sc = milvus::storage::StorageConfig{};
|
|
|
|
milvus::storage::RemoteChunkManagerSingleton::GetInstance().Init(sc);
|
|
|
|
auto mcm = std::make_unique<milvus::storage::MinioChunkManager>(sc);
|
|
|
|
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_SPARSE_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto field_data_meta =
|
|
|
|
milvus::storage::FieldDataMeta{1, 2, 3, fakevec_id.get()};
|
|
|
|
auto field_meta = milvus::FieldMeta(milvus::FieldName("facevec"),
|
|
|
|
fakevec_id,
|
|
|
|
milvus::DataType::VECTOR_SPARSE_FLOAT,
|
|
|
|
dim,
|
|
|
|
metric_type);
|
|
|
|
|
|
|
|
auto rcm = milvus::storage::RemoteChunkManagerSingleton::GetInstance()
|
|
|
|
.GetRemoteChunkManager();
|
|
|
|
auto data = dataset.get_col<knowhere::sparse::SparseRow<float>>(fakevec_id);
|
|
|
|
auto data_slices = std::vector<void*>{data.data()};
|
|
|
|
auto slice_sizes = std::vector<int64_t>{static_cast<int64_t>(N)};
|
|
|
|
auto slice_names = std::vector<std::string>{file_name};
|
|
|
|
PutFieldData(rcm.get(),
|
|
|
|
data_slices,
|
|
|
|
slice_sizes,
|
|
|
|
slice_names,
|
|
|
|
field_data_meta,
|
|
|
|
field_meta);
|
|
|
|
|
|
|
|
auto conf = generate_build_conf(index_type, metric_type);
|
|
|
|
auto ds = knowhere::GenDataSet(N, dim, data.data());
|
|
|
|
auto indexing = std::make_unique<index::VectorMemIndex<float>>(
|
|
|
|
index_type,
|
|
|
|
metric_type,
|
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber());
|
|
|
|
indexing->BuildWithDataset(ds, conf);
|
|
|
|
auto segment_sealed = CreateSealedSegment(
|
|
|
|
schema, nullptr, -1, SegcoreConfig::default_config(), true);
|
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = metric_type;
|
|
|
|
segment_sealed->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
auto field_binlog_info =
|
|
|
|
FieldBinlogInfo{fakevec_id.get(),
|
|
|
|
N,
|
|
|
|
std::vector<int64_t>{N},
|
|
|
|
false,
|
|
|
|
std::vector<std::string>{file_name}};
|
2024-06-18 14:42:00 +08:00
|
|
|
segment_sealed->AddFieldDataInfoForSealed(
|
|
|
|
LoadFieldDataInfo{std::map<int64_t, FieldBinlogInfo>{
|
|
|
|
{fakevec_id.get(), field_binlog_info}}});
|
2024-06-12 10:09:55 +08:00
|
|
|
|
|
|
|
auto segment = dynamic_cast<SegmentSealedImpl*>(segment_sealed.get());
|
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(N);
|
|
|
|
auto result =
|
|
|
|
segment->get_vector(fakevec_id, ids_ds->GetIds(), ids_ds->GetRows());
|
|
|
|
|
|
|
|
auto vector =
|
|
|
|
result.get()->mutable_vectors()->sparse_float_vector().contents();
|
|
|
|
// number of rows
|
|
|
|
EXPECT_TRUE(vector.size() == data.size());
|
|
|
|
auto sparse_rows = SparseBytesToRows(vector, true);
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
auto expect = data[ids_ds->GetIds()[i]];
|
|
|
|
auto& actual = sparse_rows[i];
|
|
|
|
AssertInfo(
|
|
|
|
expect.size() == actual.size(),
|
|
|
|
fmt::format("expect {}, actual {}", expect.size(), actual.size()));
|
|
|
|
AssertInfo(
|
|
|
|
memcmp(expect.data(), actual.data(), expect.data_byte_size()) == 0,
|
|
|
|
"sparse float vector doesn't match");
|
|
|
|
}
|
|
|
|
|
|
|
|
rcm->Remove(file_name);
|
|
|
|
auto exist = rcm->Exist(file_name);
|
|
|
|
Assert(!exist);
|
|
|
|
}
|
|
|
|
|
2024-01-25 19:55:39 +08:00
|
|
|
TEST(Sealed, WarmupChunkCache) {
|
|
|
|
// skip test due to mem leak from AWS::InitSDK
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto index_type = knowhere::IndexEnum::INDEX_FAISS_IVFPQ;
|
|
|
|
|
|
|
|
auto mmap_dir = "/tmp/mmap";
|
|
|
|
auto file_name = std::string(
|
|
|
|
"sealed_test_get_vector_from_chunk_cache/insert_log/1/101/1000000");
|
|
|
|
|
|
|
|
auto sc = milvus::storage::StorageConfig{};
|
|
|
|
milvus::storage::RemoteChunkManagerSingleton::GetInstance().Init(sc);
|
|
|
|
auto mcm = std::make_unique<milvus::storage::MinioChunkManager>(sc);
|
|
|
|
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto double_id = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto nothing_id = schema->AddDebugField("nothing", DataType::INT32);
|
|
|
|
auto str_id = schema->AddDebugField("str", DataType::VARCHAR);
|
|
|
|
schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto field_data_meta =
|
|
|
|
milvus::storage::FieldDataMeta{1, 2, 3, fakevec_id.get()};
|
|
|
|
auto field_meta = milvus::FieldMeta(milvus::FieldName("facevec"),
|
|
|
|
fakevec_id,
|
|
|
|
milvus::DataType::VECTOR_FLOAT,
|
|
|
|
dim,
|
|
|
|
metric_type);
|
|
|
|
|
|
|
|
auto rcm = milvus::storage::RemoteChunkManagerSingleton::GetInstance()
|
|
|
|
.GetRemoteChunkManager();
|
|
|
|
auto data = dataset.get_col<float>(fakevec_id);
|
2024-06-12 10:09:55 +08:00
|
|
|
auto data_slices = std::vector<void*>{data.data()};
|
2024-01-25 19:55:39 +08:00
|
|
|
auto slice_sizes = std::vector<int64_t>{static_cast<int64_t>(N)};
|
|
|
|
auto slice_names = std::vector<std::string>{file_name};
|
|
|
|
PutFieldData(rcm.get(),
|
|
|
|
data_slices,
|
|
|
|
slice_sizes,
|
|
|
|
slice_names,
|
|
|
|
field_data_meta,
|
|
|
|
field_meta);
|
|
|
|
|
|
|
|
auto conf = generate_build_conf(index_type, metric_type);
|
2024-06-12 10:09:55 +08:00
|
|
|
auto ds = knowhere::GenDataSet(N, dim, data.data());
|
2024-01-25 19:55:39 +08:00
|
|
|
auto indexing = std::make_unique<index::VectorMemIndex<float>>(
|
|
|
|
index_type,
|
|
|
|
metric_type,
|
|
|
|
knowhere::Version::GetCurrentVersion().VersionNumber());
|
|
|
|
indexing->BuildWithDataset(ds, conf);
|
|
|
|
auto segment_sealed = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
LoadIndexInfo vec_info;
|
|
|
|
vec_info.field_id = fakevec_id.get();
|
|
|
|
vec_info.index = std::move(indexing);
|
|
|
|
vec_info.index_params["metric_type"] = knowhere::metric::L2;
|
|
|
|
segment_sealed->LoadIndex(vec_info);
|
|
|
|
|
|
|
|
auto field_binlog_info =
|
|
|
|
FieldBinlogInfo{fakevec_id.get(),
|
|
|
|
N,
|
|
|
|
std::vector<int64_t>{N},
|
|
|
|
false,
|
|
|
|
std::vector<std::string>{file_name}};
|
2024-06-18 14:42:00 +08:00
|
|
|
segment_sealed->AddFieldDataInfoForSealed(
|
|
|
|
LoadFieldDataInfo{std::map<int64_t, FieldBinlogInfo>{
|
|
|
|
{fakevec_id.get(), field_binlog_info}}});
|
2024-01-25 19:55:39 +08:00
|
|
|
|
|
|
|
auto segment = dynamic_cast<SegmentSealedImpl*>(segment_sealed.get());
|
|
|
|
auto has = segment->HasRawData(vec_info.field_id);
|
|
|
|
EXPECT_FALSE(has);
|
|
|
|
|
|
|
|
segment_sealed->WarmupChunkCache(FieldId(vec_info.field_id));
|
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(N);
|
|
|
|
auto result =
|
|
|
|
segment->get_vector(fakevec_id, ids_ds->GetIds(), ids_ds->GetRows());
|
|
|
|
|
|
|
|
auto vector = result.get()->mutable_vectors()->float_vector().data();
|
2024-06-12 10:09:55 +08:00
|
|
|
EXPECT_TRUE(vector.size() == data.size());
|
2024-01-25 19:55:39 +08:00
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
auto id = ids_ds->GetIds()[i];
|
|
|
|
for (size_t j = 0; j < dim; ++j) {
|
2024-06-12 10:09:55 +08:00
|
|
|
auto expect = data[id * dim + j];
|
2024-01-25 19:55:39 +08:00
|
|
|
auto actual = vector[i * dim + j];
|
|
|
|
AssertInfo(expect == actual,
|
|
|
|
fmt::format("expect {}, actual {}", expect, actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rcm->Remove(file_name);
|
|
|
|
std::filesystem::remove_all(mmap_dir);
|
|
|
|
auto exist = rcm->Exist(file_name);
|
|
|
|
Assert(!exist);
|
|
|
|
exist = std::filesystem::exists(mmap_dir);
|
|
|
|
Assert(!exist);
|
|
|
|
}
|
|
|
|
|
2023-09-19 14:23:23 +08:00
|
|
|
TEST(Sealed, LoadArrayFieldData) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = 10;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto array_id =
|
|
|
|
schema->AddDebugField("array", DataType::ARRAY, DataType::INT64);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
const char* raw_plan = R"(vector_anns:<
|
|
|
|
field_id:100
|
|
|
|
predicates:<
|
|
|
|
json_contains_expr:<
|
|
|
|
column_info:<
|
|
|
|
field_id:102
|
|
|
|
data_type:Array
|
|
|
|
element_type:Int64
|
|
|
|
>
|
|
|
|
elements:<int64_val:1 >
|
|
|
|
op:Contains
|
|
|
|
elements_same_type:true
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info:<
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
> placeholder_tag:"$0"
|
|
|
|
>)";
|
|
|
|
|
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
|
|
|
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
2024-01-09 11:38:48 +08:00
|
|
|
segment->Search(plan.get(), ph_group.get(), 1L << 63);
|
2023-09-19 14:23:23 +08:00
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(N);
|
|
|
|
auto s = dynamic_cast<SegmentSealedImpl*>(segment.get());
|
|
|
|
auto int64_result = s->bulk_subscript(array_id, ids_ds->GetIds(), N);
|
|
|
|
auto result_count = int64_result->scalars().array_data().data().size();
|
|
|
|
ASSERT_EQ(result_count, N);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, LoadArrayFieldDataWithMMap) {
|
|
|
|
auto dim = 16;
|
|
|
|
auto topK = 5;
|
|
|
|
auto N = ROW_COUNT;
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto fakevec_id = schema->AddDebugField(
|
|
|
|
"fakevec", DataType::VECTOR_FLOAT, dim, metric_type);
|
|
|
|
auto counter_id = schema->AddDebugField("counter", DataType::INT64);
|
|
|
|
auto array_id =
|
|
|
|
schema->AddDebugField("array", DataType::ARRAY, DataType::INT64);
|
|
|
|
schema->set_primary_field_id(counter_id);
|
|
|
|
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto fakevec = dataset.get_col<float>(fakevec_id);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
const char* raw_plan = R"(vector_anns:<
|
|
|
|
field_id:100
|
|
|
|
predicates:<
|
|
|
|
json_contains_expr:<
|
|
|
|
column_info:<
|
|
|
|
field_id:102
|
|
|
|
data_type:Array
|
|
|
|
element_type:Int64
|
|
|
|
>
|
|
|
|
elements:<int64_val:1 >
|
|
|
|
op:Contains
|
|
|
|
elements_same_type:true
|
|
|
|
>
|
|
|
|
>
|
|
|
|
query_info:<
|
|
|
|
topk: 5
|
|
|
|
round_decimal: 3
|
|
|
|
metric_type: "L2"
|
|
|
|
search_params: "{\"nprobe\": 10}"
|
|
|
|
> placeholder_tag:"$0"
|
|
|
|
>)";
|
|
|
|
|
|
|
|
auto plan_str = translate_text_plan_to_binary_plan(raw_plan);
|
|
|
|
auto plan =
|
|
|
|
CreateSearchPlanByExpr(*schema, plan_str.data(), plan_str.size());
|
|
|
|
auto num_queries = 5;
|
|
|
|
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
|
|
|
auto ph_group =
|
|
|
|
ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
|
|
|
|
|
|
|
SealedLoadFieldData(dataset, *segment, {}, true);
|
2024-01-09 11:38:48 +08:00
|
|
|
segment->Search(plan.get(), ph_group.get(), 1L << 63);
|
2023-09-19 14:23:23 +08:00
|
|
|
}
|
2023-11-15 11:20:19 +08:00
|
|
|
|
|
|
|
TEST(Sealed, SkipIndexSkipUnaryRange) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 128;
|
|
|
|
auto metrics_type = "L2";
|
|
|
|
auto fake_vec_fid = schema->AddDebugField(
|
|
|
|
"fakeVec", DataType::VECTOR_FLOAT, dim, metrics_type);
|
|
|
|
auto pk_fid = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
auto i32_fid = schema->AddDebugField("int32_field", DataType::INT32);
|
|
|
|
auto i16_fid = schema->AddDebugField("int16_field", DataType::INT16);
|
|
|
|
auto i8_fid = schema->AddDebugField("int8_field", DataType::INT8);
|
|
|
|
auto float_fid = schema->AddDebugField("float_field", DataType::FLOAT);
|
|
|
|
auto double_fid = schema->AddDebugField("double_field", DataType::DOUBLE);
|
|
|
|
size_t N = 10;
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
std::cout << "pk_fid:" << pk_fid.get() << std::endl;
|
|
|
|
|
|
|
|
//test for int64
|
|
|
|
std::vector<int64_t> pks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
|
|
auto pk_field_data = storage::CreateFieldData(DataType::INT64, 1, 10);
|
|
|
|
pk_field_data->FillFieldData(pks.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
pk_fid, 0, DataType::INT64, pk_field_data->Data(), N);
|
2023-11-15 11:20:19 +08:00
|
|
|
auto& skip_index = segment->GetSkipIndex();
|
2023-11-15 18:08:20 +08:00
|
|
|
bool equal_5_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::Equal, 5);
|
|
|
|
bool equal_12_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::Equal, 12);
|
|
|
|
bool equal_10_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::Equal, 10);
|
2023-11-15 11:20:19 +08:00
|
|
|
ASSERT_FALSE(equal_5_skip);
|
|
|
|
ASSERT_TRUE(equal_12_skip);
|
|
|
|
ASSERT_FALSE(equal_10_skip);
|
2023-11-15 18:08:20 +08:00
|
|
|
bool less_than_1_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::LessThan, 1);
|
|
|
|
bool less_than_5_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::LessThan, 5);
|
2023-11-15 11:20:19 +08:00
|
|
|
ASSERT_TRUE(less_than_1_skip);
|
|
|
|
ASSERT_FALSE(less_than_5_skip);
|
2023-11-15 18:08:20 +08:00
|
|
|
bool less_equal_than_1_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::LessEqual, 1);
|
|
|
|
bool less_equal_than_15_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int64_t>(pk_fid, 0, OpType::LessThan, 15);
|
2023-11-15 11:20:19 +08:00
|
|
|
ASSERT_FALSE(less_equal_than_1_skip);
|
|
|
|
ASSERT_FALSE(less_equal_than_15_skip);
|
|
|
|
bool greater_than_10_skip = skip_index.CanSkipUnaryRange<int64_t>(
|
|
|
|
pk_fid, 0, OpType::GreaterThan, 10);
|
|
|
|
bool greater_than_5_skip = skip_index.CanSkipUnaryRange<int64_t>(
|
|
|
|
pk_fid, 0, OpType::GreaterThan, 5);
|
|
|
|
ASSERT_TRUE(greater_than_10_skip);
|
|
|
|
ASSERT_FALSE(greater_than_5_skip);
|
|
|
|
bool greater_equal_than_10_skip = skip_index.CanSkipUnaryRange<int64_t>(
|
|
|
|
pk_fid, 0, OpType::GreaterEqual, 10);
|
|
|
|
bool greater_equal_than_5_skip = skip_index.CanSkipUnaryRange<int64_t>(
|
|
|
|
pk_fid, 0, OpType::GreaterEqual, 5);
|
|
|
|
ASSERT_FALSE(greater_equal_than_10_skip);
|
|
|
|
ASSERT_FALSE(greater_equal_than_5_skip);
|
|
|
|
|
|
|
|
//test for int32
|
|
|
|
std::vector<int32_t> int32s = {2, 2, 3, 4, 5, 6, 7, 8, 9, 12};
|
|
|
|
auto int32_field_data = storage::CreateFieldData(DataType::INT32, 1, 10);
|
|
|
|
int32_field_data->FillFieldData(int32s.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
i32_fid, 0, DataType::INT32, int32_field_data->Data(), N);
|
|
|
|
less_than_1_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int32_t>(i32_fid, 0, OpType::LessThan, 1);
|
2023-11-15 11:20:19 +08:00
|
|
|
ASSERT_TRUE(less_than_1_skip);
|
|
|
|
|
|
|
|
//test for int16
|
|
|
|
std::vector<int16_t> int16s = {2, 2, 3, 4, 5, 6, 7, 8, 9, 12};
|
|
|
|
auto int16_field_data = storage::CreateFieldData(DataType::INT16, 1, 10);
|
|
|
|
int16_field_data->FillFieldData(int16s.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
i16_fid, 0, DataType::INT16, int16_field_data->Data(), N);
|
|
|
|
bool less_than_12_skip =
|
|
|
|
skip_index.CanSkipUnaryRange<int16_t>(i16_fid, 0, OpType::LessThan, 12);
|
2023-11-15 11:20:19 +08:00
|
|
|
ASSERT_FALSE(less_than_12_skip);
|
|
|
|
|
|
|
|
//test for int8
|
|
|
|
std::vector<int8_t> int8s = {2, 2, 3, 4, 5, 6, 7, 8, 9, 12};
|
|
|
|
auto int8_field_data = storage::CreateFieldData(DataType::INT8, 1, 10);
|
|
|
|
int8_field_data->FillFieldData(int8s.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
i8_fid, 0, DataType::INT8, int8_field_data->Data(), N);
|
2023-11-15 11:20:19 +08:00
|
|
|
bool greater_than_12_skip = skip_index.CanSkipUnaryRange<int8_t>(
|
|
|
|
i8_fid, 0, OpType::GreaterThan, 12);
|
|
|
|
ASSERT_TRUE(greater_than_12_skip);
|
|
|
|
|
|
|
|
// test for float
|
|
|
|
std::vector<float> floats = {
|
|
|
|
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
|
|
|
|
auto float_field_data = storage::CreateFieldData(DataType::FLOAT, 1, 10);
|
|
|
|
float_field_data->FillFieldData(floats.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
float_fid, 0, DataType::FLOAT, float_field_data->Data(), N);
|
2023-11-15 11:20:19 +08:00
|
|
|
greater_than_10_skip = skip_index.CanSkipUnaryRange<float>(
|
|
|
|
float_fid, 0, OpType::GreaterThan, 10.0);
|
|
|
|
ASSERT_TRUE(greater_than_10_skip);
|
|
|
|
|
|
|
|
// test for double
|
|
|
|
std::vector<double> doubles = {
|
|
|
|
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
|
|
|
|
auto double_field_data = storage::CreateFieldData(DataType::DOUBLE, 1, 10);
|
|
|
|
double_field_data->FillFieldData(doubles.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
double_fid, 0, DataType::DOUBLE, double_field_data->Data(), N);
|
2023-11-15 11:20:19 +08:00
|
|
|
greater_than_10_skip = skip_index.CanSkipUnaryRange<double>(
|
|
|
|
double_fid, 0, OpType::GreaterThan, 10.0);
|
|
|
|
ASSERT_TRUE(greater_than_10_skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, SkipIndexSkipBinaryRange) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 128;
|
|
|
|
auto metrics_type = "L2";
|
|
|
|
auto fake_vec_fid = schema->AddDebugField(
|
|
|
|
"fakeVec", DataType::VECTOR_FLOAT, dim, metrics_type);
|
|
|
|
auto pk_fid = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
size_t N = 10;
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
std::cout << "pk_fid:" << pk_fid.get() << std::endl;
|
|
|
|
|
|
|
|
//test for int64
|
|
|
|
std::vector<int64_t> pks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
|
|
auto pk_field_data = storage::CreateFieldData(DataType::INT64, 1, 10);
|
|
|
|
pk_field_data->FillFieldData(pks.data(), N);
|
|
|
|
segment->LoadPrimitiveSkipIndex(
|
2023-11-15 18:08:20 +08:00
|
|
|
pk_fid, 0, DataType::INT64, pk_field_data->Data(), N);
|
2023-11-15 11:20:19 +08:00
|
|
|
auto& skip_index = segment->GetSkipIndex();
|
2023-11-15 18:08:20 +08:00
|
|
|
ASSERT_FALSE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, -3, 1, true, true));
|
|
|
|
ASSERT_TRUE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, -3, 1, true, false));
|
|
|
|
|
|
|
|
ASSERT_FALSE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, 7, 9, true, true));
|
|
|
|
ASSERT_FALSE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, 8, 12, true, false));
|
|
|
|
|
|
|
|
ASSERT_TRUE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, 10, 12, false, true));
|
|
|
|
ASSERT_FALSE(
|
|
|
|
skip_index.CanSkipBinaryRange<int64_t>(pk_fid, 0, 10, 12, true, true));
|
2023-11-15 11:20:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Sealed, SkipIndexSkipStringRange) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto dim = 128;
|
|
|
|
auto metrics_type = "L2";
|
|
|
|
auto pk_fid = schema->AddDebugField("pk", DataType::INT64);
|
|
|
|
auto string_fid = schema->AddDebugField("string_field", DataType::VARCHAR);
|
|
|
|
auto fake_vec_fid = schema->AddDebugField(
|
2023-11-15 18:08:20 +08:00
|
|
|
"fakeVec", DataType::VECTOR_FLOAT, dim, metrics_type);
|
2023-11-15 11:20:19 +08:00
|
|
|
size_t N = 5;
|
|
|
|
auto dataset = DataGen(schema, N);
|
|
|
|
auto segment = CreateSealedSegment(schema);
|
|
|
|
|
|
|
|
//test for string
|
|
|
|
std::vector<std::string> strings = {"e", "f", "g", "g", "j"};
|
|
|
|
auto string_field_data = storage::CreateFieldData(DataType::VARCHAR, 1, N);
|
|
|
|
string_field_data->FillFieldData(strings.data(), N);
|
2023-12-18 12:04:42 +08:00
|
|
|
auto string_field_data_info = FieldDataInfo{
|
|
|
|
string_fid.get(), N, std::vector<FieldDataPtr>{string_field_data}};
|
2023-11-15 11:20:19 +08:00
|
|
|
segment->LoadFieldData(string_fid, string_field_data_info);
|
|
|
|
auto& skip_index = segment->GetSkipIndex();
|
2023-11-15 18:08:20 +08:00
|
|
|
ASSERT_TRUE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::Equal, "w"));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::Equal, "e"));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::Equal, "j"));
|
|
|
|
|
|
|
|
ASSERT_TRUE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::LessThan, "e"));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::LessEqual, "e"));
|
|
|
|
|
|
|
|
ASSERT_TRUE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::GreaterThan, "j"));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipUnaryRange<std::string>(
|
|
|
|
string_fid, 0, OpType::GreaterEqual, "j"));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipUnaryRange<int64_t>(
|
|
|
|
string_fid, 0, OpType::GreaterEqual, 1));
|
|
|
|
|
|
|
|
ASSERT_TRUE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "a", "c", true, true));
|
|
|
|
ASSERT_TRUE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "c", "e", true, false));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "c", "e", true, true));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "e", "k", false, true));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "j", "k", true, true));
|
|
|
|
ASSERT_TRUE(skip_index.CanSkipBinaryRange<std::string>(
|
|
|
|
string_fid, 0, "j", "k", false, true));
|
|
|
|
ASSERT_FALSE(skip_index.CanSkipBinaryRange<int64_t>(
|
|
|
|
string_fid, 0, 1, 2, false, true));
|
|
|
|
}
|
2023-11-15 11:20:19 +08:00
|
|
|
|
2023-11-15 18:08:20 +08:00
|
|
|
TEST(Sealed, QueryAllFields) {
|
|
|
|
auto schema = std::make_shared<Schema>();
|
|
|
|
auto metric_type = knowhere::metric::L2;
|
|
|
|
auto bool_field = schema->AddDebugField("bool", DataType::BOOL);
|
|
|
|
auto int8_field = schema->AddDebugField("int8", DataType::INT8);
|
|
|
|
auto int16_field = schema->AddDebugField("int16", DataType::INT16);
|
|
|
|
auto int32_field = schema->AddDebugField("int32", DataType::INT32);
|
|
|
|
auto int64_field = schema->AddDebugField("int64", DataType::INT64);
|
|
|
|
auto float_field = schema->AddDebugField("float", DataType::FLOAT);
|
|
|
|
auto double_field = schema->AddDebugField("double", DataType::DOUBLE);
|
|
|
|
auto varchar_field = schema->AddDebugField("varchar", DataType::VARCHAR);
|
|
|
|
auto json_field = schema->AddDebugField("json", DataType::JSON);
|
|
|
|
auto int_array_field =
|
|
|
|
schema->AddDebugField("int_array", DataType::ARRAY, DataType::INT8);
|
|
|
|
auto long_array_field =
|
|
|
|
schema->AddDebugField("long_array", DataType::ARRAY, DataType::INT64);
|
|
|
|
auto bool_array_field =
|
|
|
|
schema->AddDebugField("bool_array", DataType::ARRAY, DataType::BOOL);
|
|
|
|
auto string_array_field = schema->AddDebugField(
|
|
|
|
"string_array", DataType::ARRAY, DataType::VARCHAR);
|
|
|
|
auto double_array_field = schema->AddDebugField(
|
|
|
|
"double_array", DataType::ARRAY, DataType::DOUBLE);
|
|
|
|
auto float_array_field =
|
|
|
|
schema->AddDebugField("float_array", DataType::ARRAY, DataType::FLOAT);
|
|
|
|
auto vec = schema->AddDebugField(
|
|
|
|
"embeddings", DataType::VECTOR_FLOAT, 128, metric_type);
|
2024-01-11 15:48:51 +08:00
|
|
|
auto float16_vec = schema->AddDebugField(
|
|
|
|
"float16_vec", DataType::VECTOR_FLOAT16, 128, metric_type);
|
|
|
|
auto bfloat16_vec = schema->AddDebugField(
|
|
|
|
"bfloat16_vec", DataType::VECTOR_BFLOAT16, 128, metric_type);
|
2023-11-15 18:08:20 +08:00
|
|
|
schema->set_primary_field_id(int64_field);
|
|
|
|
|
|
|
|
std::map<std::string, std::string> index_params = {
|
|
|
|
{"index_type", "IVF_FLAT"},
|
|
|
|
{"metric_type", metric_type},
|
|
|
|
{"nlist", "128"}};
|
|
|
|
std::map<std::string, std::string> type_params = {{"dim", "128"}};
|
|
|
|
FieldIndexMeta fieldIndexMeta(
|
|
|
|
vec, std::move(index_params), std::move(type_params));
|
|
|
|
std::map<FieldId, FieldIndexMeta> filedMap = {{vec, fieldIndexMeta}};
|
|
|
|
IndexMetaPtr metaPtr =
|
|
|
|
std::make_shared<CollectionIndexMeta>(100000, std::move(filedMap));
|
|
|
|
auto segment_sealed = CreateSealedSegment(schema, metaPtr);
|
|
|
|
auto segment = dynamic_cast<SegmentSealedImpl*>(segment_sealed.get());
|
2023-11-15 11:20:19 +08:00
|
|
|
|
2023-11-15 18:08:20 +08:00
|
|
|
int64_t dataset_size = 1000;
|
|
|
|
int64_t dim = 128;
|
|
|
|
auto dataset = DataGen(schema, dataset_size);
|
|
|
|
SealedLoadFieldData(dataset, *segment);
|
2023-11-15 11:20:19 +08:00
|
|
|
|
2023-11-15 18:08:20 +08:00
|
|
|
auto bool_values = dataset.get_col<bool>(bool_field);
|
|
|
|
auto int8_values = dataset.get_col<int8_t>(int8_field);
|
|
|
|
auto int16_values = dataset.get_col<int16_t>(int16_field);
|
|
|
|
auto int32_values = dataset.get_col<int32_t>(int32_field);
|
|
|
|
auto int64_values = dataset.get_col<int64_t>(int64_field);
|
|
|
|
auto float_values = dataset.get_col<float>(float_field);
|
|
|
|
auto double_values = dataset.get_col<double>(double_field);
|
|
|
|
auto varchar_values = dataset.get_col<std::string>(varchar_field);
|
|
|
|
auto json_values = dataset.get_col<std::string>(json_field);
|
|
|
|
auto int_array_values = dataset.get_col<ScalarArray>(int_array_field);
|
|
|
|
auto long_array_values = dataset.get_col<ScalarArray>(long_array_field);
|
|
|
|
auto bool_array_values = dataset.get_col<ScalarArray>(bool_array_field);
|
|
|
|
auto string_array_values = dataset.get_col<ScalarArray>(string_array_field);
|
|
|
|
auto double_array_values = dataset.get_col<ScalarArray>(double_array_field);
|
|
|
|
auto float_array_values = dataset.get_col<ScalarArray>(float_array_field);
|
|
|
|
auto vector_values = dataset.get_col<float>(vec);
|
2024-01-11 15:48:51 +08:00
|
|
|
auto float16_vector_values = dataset.get_col<uint8_t>(float16_vec);
|
|
|
|
auto bfloat16_vector_values = dataset.get_col<uint8_t>(bfloat16_vec);
|
2023-11-15 18:08:20 +08:00
|
|
|
|
|
|
|
auto ids_ds = GenRandomIds(dataset_size);
|
|
|
|
auto bool_result =
|
|
|
|
segment->bulk_subscript(bool_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto int8_result =
|
|
|
|
segment->bulk_subscript(int8_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto int16_result =
|
|
|
|
segment->bulk_subscript(int16_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto int32_result =
|
|
|
|
segment->bulk_subscript(int32_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto int64_result =
|
|
|
|
segment->bulk_subscript(int64_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto float_result =
|
|
|
|
segment->bulk_subscript(float_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto double_result =
|
|
|
|
segment->bulk_subscript(double_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto varchar_result =
|
|
|
|
segment->bulk_subscript(varchar_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto json_result =
|
|
|
|
segment->bulk_subscript(json_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto int_array_result = segment->bulk_subscript(
|
|
|
|
int_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto long_array_result = segment->bulk_subscript(
|
|
|
|
long_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto bool_array_result = segment->bulk_subscript(
|
|
|
|
bool_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto string_array_result = segment->bulk_subscript(
|
|
|
|
string_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto double_array_result = segment->bulk_subscript(
|
|
|
|
double_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto float_array_result = segment->bulk_subscript(
|
|
|
|
float_array_field, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto vec_result =
|
|
|
|
segment->bulk_subscript(vec, ids_ds->GetIds(), dataset_size);
|
2024-01-11 15:48:51 +08:00
|
|
|
auto float16_vec_result =
|
|
|
|
segment->bulk_subscript(float16_vec, ids_ds->GetIds(), dataset_size);
|
|
|
|
auto bfloat16_vec_result =
|
|
|
|
segment->bulk_subscript(bfloat16_vec, ids_ds->GetIds(), dataset_size);
|
2023-11-15 18:08:20 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(bool_result->scalars().bool_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(int8_result->scalars().int_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(int16_result->scalars().int_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(int32_result->scalars().int_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(int64_result->scalars().long_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(float_result->scalars().float_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(double_result->scalars().double_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(varchar_result->scalars().string_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(json_result->scalars().json_data().data_size(), dataset_size);
|
|
|
|
EXPECT_EQ(vec_result->vectors().float_vector().data_size(),
|
|
|
|
dataset_size * dim);
|
2024-01-11 15:48:51 +08:00
|
|
|
EXPECT_EQ(float16_vec_result->vectors().float16_vector().size(),
|
|
|
|
dataset_size * dim * 2);
|
|
|
|
EXPECT_EQ(bfloat16_vec_result->vectors().bfloat16_vector().size(),
|
|
|
|
dataset_size * dim * 2);
|
2023-11-15 18:08:20 +08:00
|
|
|
EXPECT_EQ(int_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(long_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(bool_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(string_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(double_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
|
|
|
EXPECT_EQ(float_array_result->scalars().array_data().data_size(),
|
|
|
|
dataset_size);
|
2023-12-18 12:04:42 +08:00
|
|
|
}
|