mirror of https://github.com/milvus-io/milvus.git
Unify the usage of query and search (#6467)
Unify the usage of query and search Signed-off-by: yudong.cai <yudong.cai@zilliz.com>pull/6489/head
parent
b66157358c
commit
724f10b9a0
|
@ -55,22 +55,22 @@ using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, 64>
|
|||
struct EntityResult {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
struct QueryResult {
|
||||
QueryResult() = default;
|
||||
QueryResult(int64_t num_queries, int64_t topK) : topK_(topK), num_queries_(num_queries) {
|
||||
struct SearchResult {
|
||||
SearchResult() = default;
|
||||
SearchResult(int64_t num_queries, int64_t topk) : topk_(topk), num_queries_(num_queries) {
|
||||
auto count = get_row_count();
|
||||
result_distances_.resize(count);
|
||||
internal_seg_offsets_.resize(count);
|
||||
}
|
||||
|
||||
[[nodiscard]] int64_t
|
||||
int64_t
|
||||
get_row_count() const {
|
||||
return topK_ * num_queries_;
|
||||
return topk_ * num_queries_;
|
||||
}
|
||||
|
||||
public:
|
||||
int64_t num_queries_;
|
||||
int64_t topK_;
|
||||
int64_t topk_;
|
||||
std::vector<float> result_distances_;
|
||||
|
||||
public:
|
||||
|
@ -80,7 +80,7 @@ struct QueryResult {
|
|||
std::vector<std::vector<char>> row_data_;
|
||||
};
|
||||
|
||||
using QueryResultPtr = std::shared_ptr<QueryResult>;
|
||||
using SearchResultPtr = std::shared_ptr<SearchResult>;
|
||||
|
||||
struct EntityResults {
|
||||
// use protobuf results to simplify
|
||||
|
|
|
@ -26,7 +26,7 @@ set(MILVUS_QUERY_SRCS
|
|||
SearchOnSealed.cpp
|
||||
SearchOnIndex.cpp
|
||||
SearchBruteForce.cpp
|
||||
SubQueryResult.cpp
|
||||
SubSearchResult.cpp
|
||||
PlanProto.cpp
|
||||
)
|
||||
add_library(milvus_query ${MILVUS_QUERY_SRCS})
|
||||
|
|
|
@ -219,9 +219,9 @@ Parser::ParseVecNode(const Json& out_body) {
|
|||
|
||||
auto& vec_info = iter.value();
|
||||
Assert(vec_info.is_object());
|
||||
auto topK = vec_info["topk"];
|
||||
AssertInfo(topK > 0, "topK must greater than 0");
|
||||
AssertInfo(topK < 16384, "topK is too large");
|
||||
auto topk = vec_info["topk"];
|
||||
AssertInfo(topk > 0, "topk must greater than 0");
|
||||
AssertInfo(topk < 16384, "topk is too large");
|
||||
|
||||
auto field_offset = schema.get_offset(field_name);
|
||||
|
||||
|
@ -234,10 +234,10 @@ Parser::ParseVecNode(const Json& out_body) {
|
|||
return std::make_unique<BinaryVectorANNS>();
|
||||
}
|
||||
}();
|
||||
vec_node->query_info_.topK_ = topK;
|
||||
vec_node->query_info_.metric_type_ = GetMetricType(vec_info.at("metric_type"));
|
||||
vec_node->query_info_.search_params_ = vec_info.at("params");
|
||||
vec_node->query_info_.field_offset_ = field_offset;
|
||||
vec_node->search_info_.topk_ = topk;
|
||||
vec_node->search_info_.metric_type_ = GetMetricType(vec_info.at("metric_type"));
|
||||
vec_node->search_info_.search_params_ = vec_info.at("params");
|
||||
vec_node->search_info_.field_offset_ = field_offset;
|
||||
vec_node->placeholder_tag_ = vec_info.at("query");
|
||||
auto tag = vec_node->placeholder_tag_;
|
||||
AssertInfo(!tag2field_.count(tag), "duplicated placeholder tag");
|
||||
|
@ -492,7 +492,7 @@ Parser::ParseMustNotNode(const Json& body) {
|
|||
|
||||
int64_t
|
||||
GetTopK(const Plan* plan) {
|
||||
return plan->plan_node_->query_info_.topK_;
|
||||
return plan->plan_node_->search_info_.topk_;
|
||||
}
|
||||
|
||||
int64_t
|
||||
|
|
|
@ -30,17 +30,16 @@ struct PlanNode {
|
|||
|
||||
using PlanNodePtr = std::unique_ptr<PlanNode>;
|
||||
|
||||
struct QueryInfo {
|
||||
int64_t topK_;
|
||||
struct SearchInfo {
|
||||
int64_t topk_;
|
||||
FieldOffset field_offset_;
|
||||
MetricType metric_type_;
|
||||
std::string deprecated_metric_type_; // TODO: use enum
|
||||
nlohmann::json search_params_;
|
||||
};
|
||||
|
||||
struct VectorPlanNode : PlanNode {
|
||||
std::optional<ExprPtr> predicate_;
|
||||
QueryInfo query_info_;
|
||||
SearchInfo search_info_;
|
||||
std::string placeholder_tag_;
|
||||
};
|
||||
|
||||
|
|
|
@ -91,14 +91,14 @@ ProtoParser::PlanNodeFromProto(const planpb::PlanNode& plan_node_proto) {
|
|||
|
||||
auto& query_info_proto = anns_proto.query_info();
|
||||
|
||||
QueryInfo query_info;
|
||||
SearchInfo search_info;
|
||||
auto field_id = FieldId(anns_proto.field_id());
|
||||
auto field_offset = schema.get_offset(field_id);
|
||||
query_info.field_offset_ = field_offset;
|
||||
search_info.field_offset_ = field_offset;
|
||||
|
||||
query_info.metric_type_ = GetMetricType(query_info_proto.metric_type());
|
||||
query_info.topK_ = query_info_proto.topk();
|
||||
query_info.search_params_ = json::parse(query_info_proto.search_params());
|
||||
search_info.metric_type_ = GetMetricType(query_info_proto.metric_type());
|
||||
search_info.topk_ = query_info_proto.topk();
|
||||
search_info.search_params_ = json::parse(query_info_proto.search_params());
|
||||
|
||||
auto plan_node = [&]() -> std::unique_ptr<VectorPlanNode> {
|
||||
if (anns_proto.is_binary()) {
|
||||
|
@ -109,7 +109,7 @@ ProtoParser::PlanNodeFromProto(const planpb::PlanNode& plan_node_proto) {
|
|||
}();
|
||||
plan_node->placeholder_tag_ = anns_proto.placeholder_tag();
|
||||
plan_node->predicate_ = std::move(expr_opt);
|
||||
plan_node->query_info_ = std::move(query_info);
|
||||
plan_node->search_info_ = std::move(search_info);
|
||||
return plan_node;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ ProtoParser::CreatePlan(const proto::plan::PlanNode& plan_node_proto) {
|
|||
ExtractInfoPlanNodeVisitor extractor(plan_info);
|
||||
plan_node->accept(extractor);
|
||||
|
||||
plan->tag2field_["$0"] = plan_node->query_info_.field_offset_;
|
||||
plan->tag2field_["$0"] = plan_node->search_info_.field_offset_;
|
||||
plan->plan_node_ = std::move(plan_node);
|
||||
plan->extra_info_opt_ = std::move(plan_info);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <common/Types.h>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include <queue>
|
||||
#include "SubQueryResult.h"
|
||||
#include "SubSearchResult.h"
|
||||
|
||||
#include <faiss/utils/distances.h>
|
||||
#include <faiss/utils/BinaryDistance.h>
|
||||
|
@ -61,7 +61,7 @@ raw_search(MetricType metric_type,
|
|||
}
|
||||
}
|
||||
|
||||
SubQueryResult
|
||||
SubSearchResult
|
||||
BinarySearchBruteForceFast(MetricType metric_type,
|
||||
int64_t dim,
|
||||
const uint8_t* binary_chunk,
|
||||
|
@ -70,7 +70,7 @@ BinarySearchBruteForceFast(MetricType metric_type,
|
|||
int64_t num_queries,
|
||||
const uint8_t* query_data,
|
||||
const faiss::BitsetView& bitset) {
|
||||
SubQueryResult sub_result(num_queries, topk, metric_type);
|
||||
SubSearchResult sub_result(num_queries, topk, metric_type);
|
||||
float* result_distances = sub_result.get_values();
|
||||
idx_t* result_labels = sub_result.get_labels();
|
||||
|
||||
|
@ -83,17 +83,17 @@ BinarySearchBruteForceFast(MetricType metric_type,
|
|||
return sub_result;
|
||||
}
|
||||
|
||||
SubQueryResult
|
||||
FloatSearchBruteForce(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
FloatSearchBruteForce(const dataset::SearchDataset& dataset,
|
||||
const void* chunk_data_raw,
|
||||
int64_t size_per_chunk,
|
||||
const faiss::BitsetView& bitset) {
|
||||
auto metric_type = query_dataset.metric_type;
|
||||
auto num_queries = query_dataset.num_queries;
|
||||
auto topk = query_dataset.topk;
|
||||
auto dim = query_dataset.dim;
|
||||
SubQueryResult sub_qr(num_queries, topk, metric_type);
|
||||
auto query_data = reinterpret_cast<const float*>(query_dataset.query_data);
|
||||
auto metric_type = dataset.metric_type;
|
||||
auto num_queries = dataset.num_queries;
|
||||
auto topk = dataset.topk;
|
||||
auto dim = dataset.dim;
|
||||
SubSearchResult sub_qr(num_queries, topk, metric_type);
|
||||
auto query_data = reinterpret_cast<const float*>(dataset.query_data);
|
||||
auto chunk_data = reinterpret_cast<const float*>(chunk_data_raw);
|
||||
|
||||
if (metric_type == MetricType::METRIC_L2) {
|
||||
|
@ -107,15 +107,15 @@ FloatSearchBruteForce(const dataset::QueryDataset& query_dataset,
|
|||
}
|
||||
}
|
||||
|
||||
SubQueryResult
|
||||
BinarySearchBruteForce(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
BinarySearchBruteForce(const dataset::SearchDataset& dataset,
|
||||
const void* chunk_data_raw,
|
||||
int64_t size_per_chunk,
|
||||
const faiss::BitsetView& bitset) {
|
||||
// TODO: refactor the internal function
|
||||
auto query_data = reinterpret_cast<const uint8_t*>(query_dataset.query_data);
|
||||
auto query_data = reinterpret_cast<const uint8_t*>(dataset.query_data);
|
||||
auto chunk_data = reinterpret_cast<const uint8_t*>(chunk_data_raw);
|
||||
return BinarySearchBruteForceFast(query_dataset.metric_type, query_dataset.dim, chunk_data, size_per_chunk,
|
||||
query_dataset.topk, query_dataset.num_queries, query_data, bitset);
|
||||
return BinarySearchBruteForceFast(dataset.metric_type, dataset.dim, chunk_data, size_per_chunk, dataset.topk,
|
||||
dataset.num_queries, query_data, bitset);
|
||||
}
|
||||
} // namespace milvus::query
|
||||
|
|
|
@ -13,19 +13,19 @@
|
|||
#include <faiss/utils/BinaryDistance.h>
|
||||
#include "segcore/ConcurrentVector.h"
|
||||
#include "common/Schema.h"
|
||||
#include "query/SubQueryResult.h"
|
||||
#include "query/SubSearchResult.h"
|
||||
#include "query/helper.h"
|
||||
|
||||
namespace milvus::query {
|
||||
|
||||
SubQueryResult
|
||||
BinarySearchBruteForce(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
BinarySearchBruteForce(const dataset::SearchDataset& dataset,
|
||||
const void* chunk_data_raw,
|
||||
int64_t size_per_chunk,
|
||||
const faiss::BitsetView& bitset);
|
||||
|
||||
SubQueryResult
|
||||
FloatSearchBruteForce(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
FloatSearchBruteForce(const dataset::SearchDataset& dataset,
|
||||
const void* chunk_data_raw,
|
||||
int64_t size_per_chunk,
|
||||
const faiss::BitsetView& bitset);
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
namespace milvus::query {
|
||||
Status
|
||||
FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
||||
const query::QueryInfo& info,
|
||||
const query::SearchInfo& info,
|
||||
const float* query_data,
|
||||
int64_t num_queries,
|
||||
int64_t ins_barrier,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& results) {
|
||||
SearchResult& results) {
|
||||
auto& schema = segment.get_schema();
|
||||
auto& indexing_record = segment.get_indexing_record();
|
||||
auto& record = segment.get_insert_record();
|
||||
|
@ -47,15 +47,15 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
Assert(field.get_data_type() == DataType::VECTOR_FLOAT);
|
||||
auto dim = field.get_dim();
|
||||
auto topK = info.topK_;
|
||||
auto total_count = topK * num_queries;
|
||||
auto topk = info.topk_;
|
||||
auto total_count = topk * num_queries;
|
||||
auto metric_type = info.metric_type_;
|
||||
|
||||
// step 3: small indexing search
|
||||
// std::vector<int64_t> final_uids(total_count, -1);
|
||||
// std::vector<float> final_dis(total_count, std::numeric_limits<float>::max());
|
||||
SubQueryResult final_qr(num_queries, topK, metric_type);
|
||||
dataset::QueryDataset query_dataset{metric_type, num_queries, topK, dim, query_data};
|
||||
SubSearchResult final_qr(num_queries, topk, metric_type);
|
||||
dataset::SearchDataset search_dataset{metric_type, num_queries, topk, dim, query_data};
|
||||
auto vec_ptr = record.get_field_data<FloatVector>(vecfield_offset);
|
||||
|
||||
int current_chunk_id = 0;
|
||||
|
@ -63,7 +63,7 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
if (indexing_record.is_in(vecfield_offset)) {
|
||||
auto max_indexed_id = indexing_record.get_finished_ack();
|
||||
const auto& field_indexing = indexing_record.get_vec_field_indexing(vecfield_offset);
|
||||
auto search_conf = field_indexing.get_search_params(topK);
|
||||
auto search_conf = field_indexing.get_search_params(topk);
|
||||
Assert(vec_ptr->get_size_per_chunk() == field_indexing.get_size_per_chunk());
|
||||
|
||||
for (int chunk_id = current_chunk_id; chunk_id < max_indexed_id; ++chunk_id) {
|
||||
|
@ -71,7 +71,7 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
auto indexing = field_indexing.get_chunk_indexing(chunk_id);
|
||||
|
||||
auto sub_view = BitsetSubView(bitset, chunk_id * size_per_chunk, size_per_chunk);
|
||||
auto sub_qr = SearchOnIndex(query_dataset, *indexing, search_conf, sub_view);
|
||||
auto sub_qr = SearchOnIndex(search_dataset, *indexing, search_conf, sub_view);
|
||||
|
||||
// convert chunk uid to segment uid
|
||||
for (auto& x : sub_qr.mutable_labels()) {
|
||||
|
@ -97,7 +97,7 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
auto size_per_chunk = element_end - element_begin;
|
||||
|
||||
auto sub_view = BitsetSubView(bitset, element_begin, size_per_chunk);
|
||||
auto sub_qr = FloatSearchBruteForce(query_dataset, chunk.data(), size_per_chunk, sub_view);
|
||||
auto sub_qr = FloatSearchBruteForce(search_dataset, chunk.data(), size_per_chunk, sub_view);
|
||||
|
||||
// convert chunk uid to segment uid
|
||||
for (auto& x : sub_qr.mutable_labels()) {
|
||||
|
@ -111,7 +111,7 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
results.result_distances_ = std::move(final_qr.mutable_values());
|
||||
results.internal_seg_offsets_ = std::move(final_qr.mutable_labels());
|
||||
results.topK_ = topK;
|
||||
results.topk_ = topk;
|
||||
results.num_queries_ = num_queries;
|
||||
|
||||
return Status::OK();
|
||||
|
@ -119,12 +119,12 @@ FloatSearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
Status
|
||||
BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
||||
const query::QueryInfo& info,
|
||||
const query::SearchInfo& info,
|
||||
const uint8_t* query_data,
|
||||
int64_t num_queries,
|
||||
int64_t ins_barrier,
|
||||
const faiss::BitsetView& bitset,
|
||||
QueryResult& results) {
|
||||
SearchResult& results) {
|
||||
auto& schema = segment.get_schema();
|
||||
auto& indexing_record = segment.get_indexing_record();
|
||||
auto& record = segment.get_insert_record();
|
||||
|
@ -146,11 +146,11 @@ BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
Assert(field.get_data_type() == DataType::VECTOR_BINARY);
|
||||
auto dim = field.get_dim();
|
||||
auto topK = info.topK_;
|
||||
auto total_count = topK * num_queries;
|
||||
auto topk = info.topk_;
|
||||
auto total_count = topk * num_queries;
|
||||
|
||||
// step 3: small indexing search
|
||||
query::dataset::QueryDataset query_dataset{metric_type, num_queries, topK, dim, query_data};
|
||||
query::dataset::SearchDataset search_dataset{metric_type, num_queries, topk, dim, query_data};
|
||||
|
||||
auto vec_ptr = record.get_field_data<BinaryVector>(vecfield_offset);
|
||||
|
||||
|
@ -159,7 +159,7 @@ BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
auto vec_size_per_chunk = vec_ptr->get_size_per_chunk();
|
||||
auto max_chunk = upper_div(ins_barrier, vec_size_per_chunk);
|
||||
SubQueryResult final_result(num_queries, topK, metric_type);
|
||||
SubSearchResult final_result(num_queries, topk, metric_type);
|
||||
for (int chunk_id = max_indexed_id; chunk_id < max_chunk; ++chunk_id) {
|
||||
auto& chunk = vec_ptr->get_chunk(chunk_id);
|
||||
auto element_begin = chunk_id * vec_size_per_chunk;
|
||||
|
@ -167,7 +167,7 @@ BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
|||
auto nsize = element_end - element_begin;
|
||||
|
||||
auto sub_view = BitsetSubView(bitset, element_begin, nsize);
|
||||
auto sub_result = BinarySearchBruteForce(query_dataset, chunk.data(), nsize, sub_view);
|
||||
auto sub_result = BinarySearchBruteForce(search_dataset, chunk.data(), nsize, sub_view);
|
||||
|
||||
// convert chunk uid to segment uid
|
||||
for (auto& x : sub_result.mutable_labels()) {
|
||||
|
@ -180,7 +180,7 @@ BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
|||
|
||||
results.result_distances_ = std::move(final_result.mutable_values());
|
||||
results.internal_seg_offsets_ = std::move(final_result.mutable_labels());
|
||||
results.topK_ = topK;
|
||||
results.topk_ = topk;
|
||||
results.num_queries_ = num_queries;
|
||||
|
||||
return Status::OK();
|
||||
|
@ -190,11 +190,11 @@ BinarySearch(const segcore::SegmentGrowingImpl& segment,
|
|||
void
|
||||
SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
|
||||
int64_t ins_barrier,
|
||||
const query::QueryInfo& info,
|
||||
const query::SearchInfo& info,
|
||||
const void* query_data,
|
||||
int64_t num_queries,
|
||||
const faiss::BitsetView& bitset,
|
||||
QueryResult& results) {
|
||||
SearchResult& results) {
|
||||
// TODO: add data_type to info
|
||||
auto data_type = segment.get_schema()[info.field_offset_].get_data_type();
|
||||
Assert(datatype_is_vector(data_type));
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "segcore/SegmentGrowingImpl.h"
|
||||
#include <deque>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include "query/SubQueryResult.h"
|
||||
#include "query/SubSearchResult.h"
|
||||
|
||||
namespace milvus::query {
|
||||
using BitsetChunk = boost::dynamic_bitset<>;
|
||||
|
@ -23,9 +23,9 @@ using BitsetSimple = std::deque<BitsetChunk>;
|
|||
void
|
||||
SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
|
||||
int64_t ins_barrier,
|
||||
const query::QueryInfo& info,
|
||||
const query::SearchInfo& info,
|
||||
const void* query_data,
|
||||
int64_t num_queries,
|
||||
const faiss::BitsetView& bitset,
|
||||
QueryResult& results);
|
||||
SearchResult& results);
|
||||
} // namespace milvus::query
|
||||
|
|
|
@ -11,17 +11,17 @@
|
|||
|
||||
#include "SearchOnIndex.h"
|
||||
namespace milvus::query {
|
||||
SubQueryResult
|
||||
SearchOnIndex(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
SearchOnIndex(const dataset::SearchDataset& search_dataset,
|
||||
const knowhere::VecIndex& indexing,
|
||||
const knowhere::Config& search_conf,
|
||||
const faiss::BitsetView& bitset) {
|
||||
auto num_queries = query_dataset.num_queries;
|
||||
auto topK = query_dataset.topk;
|
||||
auto dim = query_dataset.dim;
|
||||
auto metric_type = query_dataset.metric_type;
|
||||
auto num_queries = search_dataset.num_queries;
|
||||
auto topK = search_dataset.topk;
|
||||
auto dim = search_dataset.dim;
|
||||
auto metric_type = search_dataset.metric_type;
|
||||
|
||||
auto dataset = knowhere::GenDataset(num_queries, dim, query_dataset.query_data);
|
||||
auto dataset = knowhere::GenDataset(num_queries, dim, search_dataset.query_data);
|
||||
|
||||
// NOTE: VecIndex Query API forget to add const qualifier
|
||||
// NOTE: use const_cast as a workaround
|
||||
|
@ -31,7 +31,7 @@ SearchOnIndex(const dataset::QueryDataset& query_dataset,
|
|||
auto dis = ans->Get<float*>(milvus::knowhere::meta::DISTANCE);
|
||||
auto uids = ans->Get<int64_t*>(milvus::knowhere::meta::IDS);
|
||||
|
||||
SubQueryResult sub_qr(num_queries, topK, metric_type);
|
||||
SubSearchResult sub_qr(num_queries, topK, metric_type);
|
||||
std::copy_n(dis, num_queries * topK, sub_qr.get_values());
|
||||
std::copy_n(uids, num_queries * topK, sub_qr.get_labels());
|
||||
return sub_qr;
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "query/SubQueryResult.h"
|
||||
#include "query/SubSearchResult.h"
|
||||
#include "query/helper.h"
|
||||
#include "knowhere/index/vector_index/VecIndex.h"
|
||||
#include <knowhere/index/vector_index/adapter/VectorAdapter.h>
|
||||
#include "utils/Json.h"
|
||||
|
||||
namespace milvus::query {
|
||||
SubQueryResult
|
||||
SearchOnIndex(const dataset::QueryDataset& query_dataset,
|
||||
SubSearchResult
|
||||
SearchOnIndex(const dataset::SearchDataset& search_dataset,
|
||||
const knowhere::VecIndex& indexing,
|
||||
const knowhere::Config& search_conf,
|
||||
const faiss::BitsetView& bitset);
|
||||
|
|
|
@ -70,27 +70,27 @@ ReleaseQueryResult(const knowhere::DatasetPtr& result) {
|
|||
void
|
||||
SearchOnSealed(const Schema& schema,
|
||||
const segcore::SealedIndexingRecord& record,
|
||||
const QueryInfo& query_info,
|
||||
const SearchInfo& search_info,
|
||||
const void* query_data,
|
||||
int64_t num_queries,
|
||||
const faiss::BitsetView& bitset,
|
||||
QueryResult& result) {
|
||||
auto topK = query_info.topK_;
|
||||
SearchResult& result) {
|
||||
auto topk = search_info.topk_;
|
||||
|
||||
auto field_offset = query_info.field_offset_;
|
||||
auto field_offset = search_info.field_offset_;
|
||||
auto& field = schema[field_offset];
|
||||
// Assert(field.get_data_type() == DataType::VECTOR_FLOAT);
|
||||
auto dim = field.get_dim();
|
||||
|
||||
Assert(record.is_ready(field_offset));
|
||||
auto field_indexing = record.get_field_indexing(field_offset);
|
||||
Assert(field_indexing->metric_type_ == query_info.metric_type_);
|
||||
Assert(field_indexing->metric_type_ == search_info.metric_type_);
|
||||
|
||||
auto final = [&] {
|
||||
auto ds = knowhere::GenDataset(num_queries, dim, query_data);
|
||||
|
||||
auto conf = query_info.search_params_;
|
||||
conf[milvus::knowhere::meta::TOPK] = query_info.topK_;
|
||||
auto conf = search_info.search_params_;
|
||||
conf[milvus::knowhere::meta::TOPK] = search_info.topk_;
|
||||
conf[milvus::knowhere::Metric::TYPE] = MetricTypeToName(field_indexing->metric_type_);
|
||||
return field_indexing->indexing_->Query(ds, conf, bitset);
|
||||
}();
|
||||
|
@ -98,11 +98,11 @@ SearchOnSealed(const Schema& schema,
|
|||
auto ids = final->Get<idx_t*>(knowhere::meta::IDS);
|
||||
auto distances = final->Get<float*>(knowhere::meta::DISTANCE);
|
||||
|
||||
auto total_num = num_queries * topK;
|
||||
auto total_num = num_queries * topk;
|
||||
result.internal_seg_offsets_.resize(total_num);
|
||||
result.result_distances_.resize(total_num);
|
||||
result.num_queries_ = num_queries;
|
||||
result.topK_ = topK;
|
||||
result.topk_ = topk;
|
||||
|
||||
std::copy_n(ids, total_num, result.internal_seg_offsets_.data());
|
||||
std::copy_n(distances, total_num, result.result_distances_.data());
|
||||
|
|
|
@ -23,10 +23,10 @@ AssembleNegBitset(const BitsetSimple& bitmap_simple);
|
|||
void
|
||||
SearchOnSealed(const Schema& schema,
|
||||
const segcore::SealedIndexingRecord& record,
|
||||
const QueryInfo& query_info,
|
||||
const SearchInfo& search_info,
|
||||
const void* query_data,
|
||||
int64_t num_queries,
|
||||
const faiss::BitsetView& view,
|
||||
QueryResult& result);
|
||||
SearchResult& result);
|
||||
|
||||
} // namespace milvus::query
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include "exceptions/EasyAssert.h"
|
||||
#include "query/SubQueryResult.h"
|
||||
#include "query/SubSearchResult.h"
|
||||
#include "segcore/Reduce.h"
|
||||
|
||||
namespace milvus::query {
|
||||
|
||||
template <bool is_desc>
|
||||
void
|
||||
SubQueryResult::merge_impl(const SubQueryResult& right) {
|
||||
SubSearchResult::merge_impl(const SubSearchResult& right) {
|
||||
Assert(num_queries_ == right.num_queries_);
|
||||
Assert(topk_ == right.topk_);
|
||||
Assert(metric_type_ == right.metric_type_);
|
||||
|
@ -58,7 +58,7 @@ SubQueryResult::merge_impl(const SubQueryResult& right) {
|
|||
}
|
||||
|
||||
void
|
||||
SubQueryResult::merge(const SubQueryResult& sub_result) {
|
||||
SubSearchResult::merge(const SubSearchResult& sub_result) {
|
||||
Assert(metric_type_ == sub_result.metric_type_);
|
||||
if (is_descending(metric_type_)) {
|
||||
this->merge_impl<true>(sub_result);
|
||||
|
@ -67,8 +67,8 @@ SubQueryResult::merge(const SubQueryResult& sub_result) {
|
|||
}
|
||||
}
|
||||
|
||||
SubQueryResult
|
||||
SubQueryResult::merge(const SubQueryResult& left, const SubQueryResult& right) {
|
||||
SubSearchResult
|
||||
SubSearchResult::merge(const SubSearchResult& left, const SubSearchResult& right) {
|
||||
auto left_copy = left;
|
||||
left_copy.merge(right);
|
||||
return left_copy;
|
|
@ -15,9 +15,9 @@
|
|||
#include <vector>
|
||||
namespace milvus::query {
|
||||
|
||||
class SubQueryResult {
|
||||
class SubSearchResult {
|
||||
public:
|
||||
SubQueryResult(int64_t num_queries, int64_t topk, MetricType metric_type)
|
||||
SubSearchResult(int64_t num_queries, int64_t topk, MetricType metric_type)
|
||||
: metric_type_(metric_type),
|
||||
num_queries_(num_queries),
|
||||
topk_(topk),
|
||||
|
@ -76,16 +76,16 @@ class SubQueryResult {
|
|||
return values_;
|
||||
}
|
||||
|
||||
static SubQueryResult
|
||||
merge(const SubQueryResult& left, const SubQueryResult& right);
|
||||
static SubSearchResult
|
||||
merge(const SubSearchResult& left, const SubSearchResult& right);
|
||||
|
||||
void
|
||||
merge(const SubQueryResult& sub_result);
|
||||
merge(const SubSearchResult& sub_result);
|
||||
|
||||
private:
|
||||
template <bool is_desc>
|
||||
void
|
||||
merge_impl(const SubQueryResult& sub_result);
|
||||
merge_impl(const SubSearchResult& sub_result);
|
||||
|
||||
private:
|
||||
int64_t num_queries_;
|
|
@ -28,7 +28,7 @@ class ExecPlanNodeVisitor : public PlanNodeVisitor {
|
|||
visit(BinaryVectorANNS& node) override;
|
||||
|
||||
public:
|
||||
using RetType = QueryResult;
|
||||
using RetType = SearchResult;
|
||||
ExecPlanNodeVisitor(const segcore::SegmentInterface& segment,
|
||||
Timestamp timestamp,
|
||||
const PlaceholderGroup& placeholder_group)
|
||||
|
|
|
@ -28,7 +28,7 @@ class VerifyPlanNodeVisitor : public PlanNodeVisitor {
|
|||
visit(BinaryVectorANNS& node) override;
|
||||
|
||||
public:
|
||||
using RetType = QueryResult;
|
||||
using RetType = SearchResult;
|
||||
VerifyPlanNodeVisitor() = default;
|
||||
|
||||
private:
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace milvus::query {
|
||||
namespace dataset {
|
||||
|
||||
struct QueryDataset {
|
||||
struct SearchDataset {
|
||||
MetricType metric_type;
|
||||
int64_t num_queries;
|
||||
int64_t topk;
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace impl {
|
|||
// WILL BE USED BY GENERATOR UNDER suvlim/core_gen/
|
||||
class ExecPlanNodeVisitor : PlanNodeVisitor {
|
||||
public:
|
||||
using RetType = QueryResult;
|
||||
using RetType = SearchResult;
|
||||
ExecPlanNodeVisitor(const segcore::SegmentInterface& segment,
|
||||
Timestamp timestamp,
|
||||
const PlaceholderGroup& placeholder_group)
|
||||
|
@ -61,12 +61,12 @@ class ExecPlanNodeVisitor : PlanNodeVisitor {
|
|||
} // namespace impl
|
||||
#endif
|
||||
|
||||
static QueryResult
|
||||
empty_query_result(int64_t num_queries, int64_t topk, MetricType metric_type) {
|
||||
QueryResult final_result;
|
||||
SubQueryResult result(num_queries, topk, metric_type);
|
||||
static SearchResult
|
||||
empty_search_result(int64_t num_queries, int64_t topk, MetricType metric_type) {
|
||||
SearchResult final_result;
|
||||
SubSearchResult result(num_queries, topk, metric_type);
|
||||
final_result.num_queries_ = num_queries;
|
||||
final_result.topK_ = topk;
|
||||
final_result.topk_ = topk;
|
||||
final_result.internal_seg_offsets_ = std::move(result.mutable_labels());
|
||||
final_result.result_distances_ = std::move(result.mutable_values());
|
||||
return final_result;
|
||||
|
@ -92,7 +92,7 @@ ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) {
|
|||
|
||||
// skip all calculation
|
||||
if (active_count == 0) {
|
||||
ret_ = empty_query_result(num_queries, node.query_info_.topK_, node.query_info_.metric_type_);
|
||||
ret_ = empty_search_result(num_queries, node.search_info_.topk_, node.search_info_.metric_type_);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) {
|
|||
view = BitsetView(bitset_holder.data(), bitset_holder.size() * 8);
|
||||
}
|
||||
|
||||
segment->vector_search(active_count, node.query_info_, src_data, num_queries, MAX_TIMESTAMP, view, ret);
|
||||
segment->vector_search(active_count, node.search_info_, src_data, num_queries, MAX_TIMESTAMP, view, ret);
|
||||
|
||||
ret_ = ret;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class ExtractInfoPlanNodeVisitor : PlanNodeVisitor {
|
|||
|
||||
void
|
||||
ExtractInfoPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
||||
plan_info_.add_involved_field(node.query_info_.field_offset_);
|
||||
plan_info_.add_involved_field(node.search_info_.field_offset_);
|
||||
if (node.predicate_.has_value()) {
|
||||
ExtractInfoExprVisitor expr_visitor(plan_info_);
|
||||
node.predicate_.value()->accept(expr_visitor);
|
||||
|
@ -41,7 +41,7 @@ ExtractInfoPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
|||
|
||||
void
|
||||
ExtractInfoPlanNodeVisitor::visit(BinaryVectorANNS& node) {
|
||||
plan_info_.add_involved_field(node.query_info_.field_offset_);
|
||||
plan_info_.add_involved_field(node.search_info_.field_offset_);
|
||||
if (node.predicate_.has_value()) {
|
||||
ExtractInfoExprVisitor expr_visitor(plan_info_);
|
||||
node.predicate_.value()->accept(expr_visitor);
|
||||
|
|
|
@ -52,12 +52,12 @@ void
|
|||
ShowPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
||||
// std::vector<float> data(node.data_.get(), node.data_.get() + node.num_queries_ * node.dim_);
|
||||
assert(!ret_);
|
||||
auto& info = node.query_info_;
|
||||
auto& info = node.search_info_;
|
||||
Json json_body{
|
||||
{"node_type", "FloatVectorANNS"}, //
|
||||
{"metric_type", MetricTypeToName(info.metric_type_)}, //
|
||||
{"field_offset_", info.field_offset_.get()}, //
|
||||
{"topK", info.topK_}, //
|
||||
{"topk", info.topk_}, //
|
||||
{"search_params", info.search_params_}, //
|
||||
{"placeholder_tag", node.placeholder_tag_}, //
|
||||
};
|
||||
|
@ -74,12 +74,12 @@ ShowPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
|||
void
|
||||
ShowPlanNodeVisitor::visit(BinaryVectorANNS& node) {
|
||||
assert(!ret_);
|
||||
auto& info = node.query_info_;
|
||||
auto& info = node.search_info_;
|
||||
Json json_body{
|
||||
{"node_type", "BinaryVectorANNS"}, //
|
||||
{"metric_type", MetricTypeToName(info.metric_type_)}, //
|
||||
{"field_offset_", info.field_offset_.get()}, //
|
||||
{"topK", info.topK_}, //
|
||||
{"topk", info.topk_}, //
|
||||
{"search_params", info.search_params_}, //
|
||||
{"placeholder_tag", node.placeholder_tag_}, //
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace impl {
|
|||
// WILL BE USED BY GENERATOR UNDER suvlim/core_gen/
|
||||
class VerifyPlanNodeVisitor : PlanNodeVisitor {
|
||||
public:
|
||||
using RetType = QueryResult;
|
||||
using RetType = SearchResult;
|
||||
VerifyPlanNodeVisitor() = default;
|
||||
|
||||
private:
|
||||
|
@ -74,7 +74,7 @@ InferBinaryIndexType(const Json& search_params) {
|
|||
|
||||
void
|
||||
VerifyPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
||||
auto& search_params = node.query_info_.search_params_;
|
||||
auto& search_params = node.search_info_.search_params_;
|
||||
auto inferred_type = InferIndexType(search_params);
|
||||
auto adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(inferred_type);
|
||||
auto index_mode = knowhere::IndexMode::MODE_CPU;
|
||||
|
@ -92,7 +92,7 @@ VerifyPlanNodeVisitor::visit(FloatVectorANNS& node) {
|
|||
|
||||
void
|
||||
VerifyPlanNodeVisitor::visit(BinaryVectorANNS& node) {
|
||||
auto& search_params = node.query_info_.search_params_;
|
||||
auto& search_params = node.search_info_.search_params_;
|
||||
auto inferred_type = InferBinaryIndexType(search_params);
|
||||
auto adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(inferred_type);
|
||||
auto index_mode = knowhere::IndexMode::MODE_CPU;
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace milvus {
|
|||
namespace segcore {
|
||||
// using engine::DataChunk;
|
||||
// using engine::DataChunkPtr;
|
||||
using QueryResult = milvus::QueryResult;
|
||||
using SearchResult = milvus::SearchResult;
|
||||
struct RowBasedRawData {
|
||||
void* raw_data; // schema
|
||||
int sizeof_per_row; // alignment
|
||||
|
|
|
@ -285,21 +285,24 @@ SegmentGrowingImpl::num_chunk() const {
|
|||
auto size = get_insert_record().ack_responder_.GetAck();
|
||||
return upper_div(size, segcore_config_.get_size_per_chunk());
|
||||
}
|
||||
|
||||
void
|
||||
SegmentGrowingImpl::vector_search(int64_t vec_count,
|
||||
query::QueryInfo query_info,
|
||||
query::SearchInfo search_info,
|
||||
const void* query_data,
|
||||
int64_t query_count,
|
||||
Timestamp timestamp,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& output) const {
|
||||
SearchResult& output) const {
|
||||
auto& sealed_indexing = this->get_sealed_indexing_record();
|
||||
if (sealed_indexing.is_ready(query_info.field_offset_)) {
|
||||
query::SearchOnSealed(this->get_schema(), sealed_indexing, query_info, query_data, query_count, bitset, output);
|
||||
if (sealed_indexing.is_ready(search_info.field_offset_)) {
|
||||
query::SearchOnSealed(this->get_schema(), sealed_indexing, search_info, query_data, query_count, bitset,
|
||||
output);
|
||||
} else {
|
||||
SearchOnGrowing(*this, vec_count, query_info, query_data, query_count, bitset, output);
|
||||
SearchOnGrowing(*this, vec_count, search_info, query_data, query_count, bitset, output);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SegmentGrowingImpl::bulk_subscript(FieldOffset field_offset,
|
||||
const int64_t* seg_offsets,
|
||||
|
|
|
@ -179,12 +179,12 @@ class SegmentGrowingImpl : public SegmentGrowing {
|
|||
|
||||
void
|
||||
vector_search(int64_t vec_count,
|
||||
query::QueryInfo query_info,
|
||||
query::SearchInfo search_info,
|
||||
const void* query_data,
|
||||
int64_t query_count,
|
||||
Timestamp timestamp,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& output) const override;
|
||||
SearchResult& output) const override;
|
||||
|
||||
public:
|
||||
std::shared_ptr<DeletedRecord::TmpBitmap>
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace milvus::segcore {
|
|||
class Naive;
|
||||
|
||||
void
|
||||
SegmentInternalInterface::FillTargetEntry(const query::Plan* plan, QueryResult& results) const {
|
||||
SegmentInternalInterface::FillTargetEntry(const query::Plan* plan, SearchResult& results) const {
|
||||
std::shared_lock lck(mutex_);
|
||||
AssertInfo(plan, "empty plan");
|
||||
auto size = results.result_distances_.size();
|
||||
|
@ -71,7 +71,7 @@ SegmentInternalInterface::FillTargetEntry(const query::Plan* plan, QueryResult&
|
|||
}
|
||||
}
|
||||
|
||||
QueryResult
|
||||
SearchResult
|
||||
SegmentInternalInterface::Search(const query::Plan* plan,
|
||||
const query::PlaceholderGroup& placeholder_group,
|
||||
Timestamp timestamp) const {
|
||||
|
|
|
@ -34,9 +34,9 @@ class SegmentInterface {
|
|||
public:
|
||||
// fill results according to target_entries in plan
|
||||
virtual void
|
||||
FillTargetEntry(const query::Plan* plan, QueryResult& results) const = 0;
|
||||
FillTargetEntry(const query::Plan* plan, SearchResult& results) const = 0;
|
||||
|
||||
virtual QueryResult
|
||||
virtual SearchResult
|
||||
Search(const query::Plan* Plan, const query::PlaceholderGroup& placeholder_group, Timestamp timestamp) const = 0;
|
||||
|
||||
virtual std::unique_ptr<proto::segcore::RetrieveResults>
|
||||
|
@ -79,13 +79,13 @@ class SegmentInternalInterface : public SegmentInterface {
|
|||
return *ptr;
|
||||
}
|
||||
|
||||
QueryResult
|
||||
SearchResult
|
||||
Search(const query::Plan* Plan,
|
||||
const query::PlaceholderGroup& placeholder_group,
|
||||
Timestamp timestamp) const override;
|
||||
|
||||
void
|
||||
FillTargetEntry(const query::Plan* plan, QueryResult& results) const override;
|
||||
FillTargetEntry(const query::Plan* plan, SearchResult& results) const override;
|
||||
|
||||
std::unique_ptr<proto::segcore::RetrieveResults>
|
||||
GetEntityById(const std::vector<FieldOffset>& field_offsets,
|
||||
|
@ -98,12 +98,12 @@ class SegmentInternalInterface : public SegmentInterface {
|
|||
public:
|
||||
virtual void
|
||||
vector_search(int64_t vec_count,
|
||||
query::QueryInfo query_info,
|
||||
query::SearchInfo search_info,
|
||||
const void* query_data,
|
||||
int64_t query_count,
|
||||
Timestamp timestamp,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& output) const = 0;
|
||||
SearchResult& output) const = 0;
|
||||
|
||||
// count of chunk that has index available
|
||||
virtual int64_t
|
||||
|
|
|
@ -213,31 +213,31 @@ SegmentSealedImpl::get_schema() const {
|
|||
|
||||
void
|
||||
SegmentSealedImpl::vector_search(int64_t vec_count,
|
||||
query::QueryInfo query_info,
|
||||
query::SearchInfo search_info,
|
||||
const void* query_data,
|
||||
int64_t query_count,
|
||||
Timestamp timestamp,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& output) const {
|
||||
SearchResult& output) const {
|
||||
Assert(is_system_field_ready());
|
||||
auto field_offset = query_info.field_offset_;
|
||||
auto field_offset = search_info.field_offset_;
|
||||
auto& field_meta = schema_->operator[](field_offset);
|
||||
|
||||
Assert(field_meta.is_vector());
|
||||
if (get_bit(vecindex_ready_bitset_, field_offset)) {
|
||||
Assert(vecindexs_.is_ready(field_offset));
|
||||
query::SearchOnSealed(*schema_, vecindexs_, query_info, query_data, query_count, bitset, output);
|
||||
query::SearchOnSealed(*schema_, vecindexs_, search_info, query_data, query_count, bitset, output);
|
||||
return;
|
||||
} else if (!get_bit(field_data_ready_bitset_, field_offset)) {
|
||||
PanicInfo("Field Data is not loaded");
|
||||
}
|
||||
|
||||
query::dataset::QueryDataset dataset;
|
||||
query::dataset::SearchDataset dataset;
|
||||
dataset.query_data = query_data;
|
||||
dataset.num_queries = query_count;
|
||||
// if(field_meta.is)
|
||||
dataset.metric_type = query_info.metric_type_;
|
||||
dataset.topk = query_info.topK_;
|
||||
dataset.metric_type = search_info.metric_type_;
|
||||
dataset.topk = search_info.topk_;
|
||||
dataset.dim = field_meta.get_dim();
|
||||
|
||||
Assert(get_bit(field_data_ready_bitset_, field_offset));
|
||||
|
@ -253,10 +253,10 @@ SegmentSealedImpl::vector_search(int64_t vec_count,
|
|||
}
|
||||
}();
|
||||
|
||||
QueryResult results;
|
||||
SearchResult results;
|
||||
results.result_distances_ = std::move(sub_qr.mutable_values());
|
||||
results.internal_seg_offsets_ = std::move(sub_qr.mutable_labels());
|
||||
results.topK_ = dataset.topk;
|
||||
results.topk_ = dataset.topk;
|
||||
results.num_queries_ = dataset.num_queries;
|
||||
|
||||
output = std::move(results);
|
||||
|
|
|
@ -111,12 +111,12 @@ class SegmentSealedImpl : public SegmentSealed {
|
|||
|
||||
void
|
||||
vector_search(int64_t vec_count,
|
||||
query::QueryInfo query_info,
|
||||
query::SearchInfo search_info,
|
||||
const void* query_data,
|
||||
int64_t query_count,
|
||||
Timestamp timestamp,
|
||||
const BitsetView& bitset,
|
||||
QueryResult& output) const override;
|
||||
SearchResult& output) const override;
|
||||
|
||||
bool
|
||||
is_system_field_ready() const {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "pb/segcore.pb.h"
|
||||
|
||||
CStatus
|
||||
CreatePlan(CCollection c_col, const char* dsl, CPlan* res_plan) {
|
||||
CreateSearchPlan(CCollection c_col, const char* dsl, CSearchPlan* res_plan) {
|
||||
auto col = (milvus::segcore::Collection*)c_col;
|
||||
|
||||
try {
|
||||
|
@ -24,7 +24,7 @@ CreatePlan(CCollection c_col, const char* dsl, CPlan* res_plan) {
|
|||
auto status = CStatus();
|
||||
status.error_code = Success;
|
||||
status.error_msg = "";
|
||||
auto plan = (CPlan)res.release();
|
||||
auto plan = (CSearchPlan)res.release();
|
||||
*res_plan = plan;
|
||||
return status;
|
||||
} catch (milvus::SegcoreError& e) {
|
||||
|
@ -44,7 +44,7 @@ CreatePlan(CCollection c_col, const char* dsl, CPlan* res_plan) {
|
|||
|
||||
// Note: serialized_expr_plan is of binary format
|
||||
CStatus
|
||||
CreatePlanByExpr(CCollection c_col, const char* serialized_expr_plan, int64_t size, CPlan* res_plan) {
|
||||
CreateSearchPlanByExpr(CCollection c_col, const char* serialized_expr_plan, int64_t size, CSearchPlan* res_plan) {
|
||||
auto col = (milvus::segcore::Collection*)c_col;
|
||||
|
||||
try {
|
||||
|
@ -53,7 +53,7 @@ CreatePlanByExpr(CCollection c_col, const char* serialized_expr_plan, int64_t si
|
|||
auto status = CStatus();
|
||||
status.error_code = Success;
|
||||
status.error_msg = "";
|
||||
auto plan = (CPlan)res.release();
|
||||
auto plan = (CSearchPlan)res.release();
|
||||
*res_plan = plan;
|
||||
return status;
|
||||
} catch (milvus::SegcoreError& e) {
|
||||
|
@ -72,7 +72,7 @@ CreatePlanByExpr(CCollection c_col, const char* serialized_expr_plan, int64_t si
|
|||
}
|
||||
|
||||
CStatus
|
||||
ParsePlaceholderGroup(CPlan c_plan,
|
||||
ParsePlaceholderGroup(CSearchPlan c_plan,
|
||||
void* placeholder_group_blob,
|
||||
int64_t blob_size,
|
||||
CPlaceholderGroup* res_placeholder_group) {
|
||||
|
@ -100,26 +100,24 @@ ParsePlaceholderGroup(CPlan c_plan,
|
|||
int64_t
|
||||
GetNumOfQueries(CPlaceholderGroup placeholder_group) {
|
||||
auto res = milvus::query::GetNumOfQueries((milvus::query::PlaceholderGroup*)placeholder_group);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int64_t
|
||||
GetTopK(CPlan plan) {
|
||||
GetTopK(CSearchPlan plan) {
|
||||
auto res = milvus::query::GetTopK((milvus::query::Plan*)plan);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const char*
|
||||
GetMetricType(CPlan plan) {
|
||||
auto query_plan = static_cast<milvus::query::Plan*>(plan);
|
||||
auto metric_str = milvus::MetricTypeToName(query_plan->plan_node_->query_info_.metric_type_);
|
||||
GetMetricType(CSearchPlan plan) {
|
||||
auto search_plan = static_cast<milvus::query::Plan*>(plan);
|
||||
auto metric_str = milvus::MetricTypeToName(search_plan->plan_node_->search_info_.metric_type_);
|
||||
return strdup(metric_str.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
DeletePlan(CPlan cPlan) {
|
||||
DeleteSearchPlan(CSearchPlan cPlan) {
|
||||
auto plan = (milvus::query::Plan*)cPlan;
|
||||
delete plan;
|
||||
// std::cout << "delete plan" << std::endl;
|
||||
|
|
|
@ -18,19 +18,19 @@ extern "C" {
|
|||
#include "segcore/collection_c.h"
|
||||
#include "common/type_c.h"
|
||||
|
||||
typedef void* CPlan;
|
||||
typedef void* CSearchPlan;
|
||||
typedef void* CPlaceholderGroup;
|
||||
typedef void* CRetrievePlan;
|
||||
|
||||
CStatus
|
||||
CreatePlan(CCollection col, const char* dsl, CPlan* res_plan);
|
||||
CreateSearchPlan(CCollection col, const char* dsl, CSearchPlan* res_plan);
|
||||
|
||||
// Note: serialized_expr_plan is of binary format
|
||||
CStatus
|
||||
CreatePlanByExpr(CCollection col, const char* serialized_expr_plan, int64_t size, CPlan* res_plan);
|
||||
CreateSearchPlanByExpr(CCollection col, const char* serialized_expr_plan, int64_t size, CSearchPlan* res_plan);
|
||||
|
||||
CStatus
|
||||
ParsePlaceholderGroup(CPlan plan,
|
||||
ParsePlaceholderGroup(CSearchPlan plan,
|
||||
void* placeholder_group_blob,
|
||||
int64_t blob_size,
|
||||
CPlaceholderGroup* res_placeholder_group);
|
||||
|
@ -39,13 +39,13 @@ int64_t
|
|||
GetNumOfQueries(CPlaceholderGroup placeholder_group);
|
||||
|
||||
int64_t
|
||||
GetTopK(CPlan plan);
|
||||
GetTopK(CSearchPlan plan);
|
||||
|
||||
const char*
|
||||
GetMetricType(CPlan plan);
|
||||
GetMetricType(CSearchPlan plan);
|
||||
|
||||
void
|
||||
DeletePlan(CPlan plan);
|
||||
DeleteSearchPlan(CSearchPlan plan);
|
||||
|
||||
void
|
||||
DeletePlaceholderGroup(CPlaceholderGroup placeholder_group);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "common/Types.h"
|
||||
#include "pb/milvus.pb.h"
|
||||
|
||||
using SearchResult = milvus::QueryResult;
|
||||
using SearchResult = milvus::SearchResult;
|
||||
|
||||
int
|
||||
MergeInto(int64_t num_queries, int64_t topk, float* distances, int64_t* uids, float* new_distances, int64_t* new_uids) {
|
||||
|
@ -91,7 +91,7 @@ GetResultData(std::vector<std::vector<int64_t>>& search_records,
|
|||
result_pairs.push_back(SearchResultPair(distance, search_result, query_offset, j));
|
||||
}
|
||||
int64_t loc_offset = query_offset;
|
||||
AssertInfo(topk > 0, "topK must greater than 0");
|
||||
AssertInfo(topk > 0, "topk must greater than 0");
|
||||
for (int i = 0; i < topk; ++i) {
|
||||
result_pairs[0].reset_distance();
|
||||
std::sort(result_pairs.begin(), result_pairs.end(), std::greater<>());
|
||||
|
@ -133,13 +133,13 @@ ResetSearchResult(std::vector<std::vector<int64_t>>& search_records,
|
|||
}
|
||||
|
||||
CStatus
|
||||
ReduceQueryResults(CQueryResult* c_search_results, int64_t num_segments, bool* is_selected) {
|
||||
ReduceSearchResults(CSearchResult* c_search_results, int64_t num_segments, bool* is_selected) {
|
||||
try {
|
||||
std::vector<SearchResult*> search_results;
|
||||
for (int i = 0; i < num_segments; ++i) {
|
||||
search_results.push_back((SearchResult*)c_search_results[i]);
|
||||
}
|
||||
auto topk = search_results[0]->topK_;
|
||||
auto topk = search_results[0]->topk_;
|
||||
auto num_queries = search_results[0]->num_queries_;
|
||||
std::vector<std::vector<int64_t>> search_records(num_segments);
|
||||
|
||||
|
@ -162,13 +162,13 @@ ReduceQueryResults(CQueryResult* c_search_results, int64_t num_segments, bool* i
|
|||
}
|
||||
|
||||
CStatus
|
||||
ReorganizeQueryResults(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CQueryResult* c_search_results,
|
||||
bool* is_selected,
|
||||
int64_t num_segments,
|
||||
CPlan c_plan) {
|
||||
ReorganizeSearchResults(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CSearchResult* c_search_results,
|
||||
bool* is_selected,
|
||||
int64_t num_segments,
|
||||
CSearchPlan c_plan) {
|
||||
try {
|
||||
auto marshaledHits = std::make_unique<MarshaledHits>(num_groups);
|
||||
auto topk = GetTopK(c_plan);
|
||||
|
@ -252,11 +252,11 @@ ReorganizeQueryResults(CMarshaledHits* c_marshaled_hits,
|
|||
}
|
||||
|
||||
CStatus
|
||||
ReorganizeSingleQueryResult(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CQueryResult c_search_result,
|
||||
CPlan c_plan) {
|
||||
ReorganizeSingleSearchResult(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CSearchResult c_search_result,
|
||||
CSearchPlan c_plan) {
|
||||
try {
|
||||
auto marshaledHits = std::make_unique<MarshaledHits>(num_groups);
|
||||
auto search_result = (SearchResult*)c_search_result;
|
||||
|
|
|
@ -27,23 +27,23 @@ int
|
|||
MergeInto(int64_t num_queries, int64_t topk, float* distances, int64_t* uids, float* new_distances, int64_t* new_uids);
|
||||
|
||||
CStatus
|
||||
ReduceQueryResults(CQueryResult* query_results, int64_t num_segments, bool* is_selected);
|
||||
ReduceSearchResults(CSearchResult* search_results, int64_t num_segments, bool* is_selected);
|
||||
|
||||
CStatus
|
||||
ReorganizeQueryResults(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CQueryResult* c_search_results,
|
||||
bool* is_selected,
|
||||
int64_t num_segments,
|
||||
CPlan c_plan);
|
||||
ReorganizeSearchResults(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CSearchResult* c_search_results,
|
||||
bool* is_selected,
|
||||
int64_t num_segments,
|
||||
CSearchPlan c_plan);
|
||||
|
||||
CStatus
|
||||
ReorganizeSingleQueryResult(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CQueryResult c_search_result,
|
||||
CPlan c_plan);
|
||||
ReorganizeSingleSearchResult(CMarshaledHits* c_marshaled_hits,
|
||||
CPlaceholderGroup* c_placeholder_groups,
|
||||
int64_t num_groups,
|
||||
CSearchResult c_search_result,
|
||||
CSearchPlan c_plan);
|
||||
|
||||
int64_t
|
||||
GetHitsBlobSize(CMarshaledHits c_marshaled_hits);
|
||||
|
|
|
@ -59,29 +59,29 @@ DeleteSegment(CSegmentInterface c_segment) {
|
|||
}
|
||||
|
||||
void
|
||||
DeleteQueryResult(CQueryResult query_result) {
|
||||
auto res = (milvus::QueryResult*)query_result;
|
||||
DeleteSearchResult(CSearchResult search_result) {
|
||||
auto res = (milvus::SearchResult*)search_result;
|
||||
delete res;
|
||||
}
|
||||
|
||||
CStatus
|
||||
Search(CSegmentInterface c_segment,
|
||||
CPlan c_plan,
|
||||
CSearchPlan c_plan,
|
||||
CPlaceholderGroup c_placeholder_group,
|
||||
uint64_t timestamp,
|
||||
CQueryResult* result) {
|
||||
auto query_result = std::make_unique<milvus::QueryResult>();
|
||||
CSearchResult* result) {
|
||||
auto search_result = std::make_unique<milvus::SearchResult>();
|
||||
try {
|
||||
auto segment = (milvus::segcore::SegmentInterface*)c_segment;
|
||||
auto plan = (milvus::query::Plan*)c_plan;
|
||||
auto phg_ptr = reinterpret_cast<const milvus::query::PlaceholderGroup*>(c_placeholder_group);
|
||||
*query_result = segment->Search(plan, *phg_ptr, timestamp);
|
||||
if (plan->plan_node_->query_info_.metric_type_ != milvus::MetricType::METRIC_INNER_PRODUCT) {
|
||||
for (auto& dis : query_result->result_distances_) {
|
||||
*search_result = segment->Search(plan, *phg_ptr, timestamp);
|
||||
if (plan->plan_node_->search_info_.metric_type_ != milvus::MetricType::METRIC_INNER_PRODUCT) {
|
||||
for (auto& dis : search_result->result_distances_) {
|
||||
dis *= -1;
|
||||
}
|
||||
}
|
||||
*result = query_result.release();
|
||||
*result = search_result.release();
|
||||
return milvus::SuccessCStatus();
|
||||
} catch (std::exception& e) {
|
||||
return milvus::FailureCStatus(UnexpectedError, e.what());
|
||||
|
@ -89,10 +89,10 @@ Search(CSegmentInterface c_segment,
|
|||
}
|
||||
|
||||
CStatus
|
||||
FillTargetEntry(CSegmentInterface c_segment, CPlan c_plan, CQueryResult c_result) {
|
||||
FillTargetEntry(CSegmentInterface c_segment, CSearchPlan c_plan, CSearchResult c_result) {
|
||||
auto segment = (milvus::segcore::SegmentInterface*)c_segment;
|
||||
auto plan = (milvus::query::Plan*)c_plan;
|
||||
auto result = (milvus::QueryResult*)c_result;
|
||||
auto result = (milvus::SearchResult*)c_result;
|
||||
|
||||
try {
|
||||
segment->FillTargetEntry(plan, *result);
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#include "segcore/load_index_c.h"
|
||||
|
||||
typedef void* CSegmentInterface;
|
||||
typedef void* CQueryResult;
|
||||
typedef void* CSearchResult;
|
||||
|
||||
////////////////////////////// common interfaces //////////////////////////////
|
||||
CSegmentInterface
|
||||
|
@ -34,20 +34,20 @@ void
|
|||
DeleteSegment(CSegmentInterface c_segment);
|
||||
|
||||
void
|
||||
DeleteQueryResult(CQueryResult query_result);
|
||||
DeleteSearchResult(CSearchResult search_result);
|
||||
|
||||
CStatus
|
||||
Search(CSegmentInterface c_segment,
|
||||
CPlan c_plan,
|
||||
CSearchPlan c_plan,
|
||||
CPlaceholderGroup c_placeholder_group,
|
||||
uint64_t timestamp,
|
||||
CQueryResult* result);
|
||||
CSearchResult* result);
|
||||
|
||||
CProtoResult
|
||||
GetEntityByIds(CSegmentInterface c_segment, CRetrievePlan plan, uint64_t timestamp);
|
||||
GetEntityByIds(CSegmentInterface c_segment, CRetrievePlan c_plan, uint64_t timestamp);
|
||||
|
||||
CStatus
|
||||
FillTargetEntry(CSegmentInterface c_segment, CPlan c_plan, CQueryResult result);
|
||||
FillTargetEntry(CSegmentInterface c_segment, CSearchPlan c_plan, CSearchResult result);
|
||||
|
||||
int64_t
|
||||
GetMemoryUsageInBytes(CSegmentInterface c_segment);
|
||||
|
|
|
@ -16,26 +16,26 @@ include_directories(${CMAKE_HOME_DIRECTORY}/src/thirdparty)
|
|||
add_definitions(-DMILVUS_TEST_SEGCORE_YAML_PATH="${CMAKE_SOURCE_DIR}/unittest/test_utils/test_segcore.yaml")
|
||||
|
||||
set(MILVUS_TEST_FILES
|
||||
test_naive.cpp
|
||||
test_segcore.cpp
|
||||
init_gtest.cpp
|
||||
test_binary.cpp
|
||||
test_bitmap.cpp
|
||||
test_common.cpp
|
||||
test_concurrent_vector.cpp
|
||||
test_c_api.cpp
|
||||
test_indexing.cpp
|
||||
test_query.cpp
|
||||
test_expr.cpp
|
||||
test_bitmap.cpp
|
||||
test_binary.cpp
|
||||
test_index_wrapper.cpp
|
||||
test_common.cpp
|
||||
test_sealed.cpp
|
||||
test_reduce.cpp
|
||||
test_interface.cpp
|
||||
test_span.cpp
|
||||
test_load.cpp
|
||||
init_gtest.cpp
|
||||
test_init.cpp
|
||||
test_plan_proto.cpp
|
||||
test_get_entity_by_ids.cpp
|
||||
test_indexing.cpp
|
||||
test_index_wrapper.cpp
|
||||
test_init.cpp
|
||||
test_interface.cpp
|
||||
test_load.cpp
|
||||
test_naive.cpp
|
||||
test_plan_proto.cpp
|
||||
test_query.cpp
|
||||
test_reduce.cpp
|
||||
test_sealed.cpp
|
||||
test_segcore.cpp
|
||||
test_span.cpp
|
||||
test_timestamp_index.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ TEST(CApiTest, SearchTest) {
|
|||
|
||||
void* plan = nullptr;
|
||||
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
ASSERT_EQ(status.error_code, Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -226,13 +226,13 @@ TEST(CApiTest, SearchTest) {
|
|||
timestamps.clear();
|
||||
timestamps.push_back(1);
|
||||
|
||||
CQueryResult search_result;
|
||||
CSearchResult search_result;
|
||||
auto res = Search(segment, plan, placeholderGroup, timestamps[0], &search_result);
|
||||
ASSERT_EQ(res.error_code, Success);
|
||||
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(search_result);
|
||||
DeleteSearchResult(search_result);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ TEST(CApiTest, SearchTestWithExpr) {
|
|||
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
ASSERT_EQ(status.error_code, Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -309,13 +309,13 @@ TEST(CApiTest, SearchTestWithExpr) {
|
|||
timestamps.clear();
|
||||
timestamps.push_back(1);
|
||||
|
||||
CQueryResult search_result;
|
||||
CSearchResult search_result;
|
||||
auto res = Search(segment, plan, placeholderGroup, timestamps[0], &search_result);
|
||||
ASSERT_EQ(res.error_code, Success);
|
||||
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(search_result);
|
||||
DeleteSearchResult(search_result);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ TEST(CApiTest, Reduce) {
|
|||
|
||||
void* plan = nullptr;
|
||||
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -623,9 +623,9 @@ TEST(CApiTest, Reduce) {
|
|||
timestamps.clear();
|
||||
timestamps.push_back(1);
|
||||
|
||||
std::vector<CQueryResult> results;
|
||||
CQueryResult res1;
|
||||
CQueryResult res2;
|
||||
std::vector<CSearchResult> results;
|
||||
CSearchResult res1;
|
||||
CSearchResult res2;
|
||||
auto res = Search(segment, plan, placeholderGroup, timestamps[0], &res1);
|
||||
assert(res.error_code == Success);
|
||||
res = Search(segment, plan, placeholderGroup, timestamps[0], &res2);
|
||||
|
@ -634,12 +634,12 @@ TEST(CApiTest, Reduce) {
|
|||
results.push_back(res2);
|
||||
|
||||
bool is_selected[1] = {false};
|
||||
status = ReduceQueryResults(results.data(), 1, is_selected);
|
||||
status = ReduceSearchResults(results.data(), 1, is_selected);
|
||||
assert(status.error_code == Success);
|
||||
FillTargetEntry(segment, plan, res1);
|
||||
void* reorganize_search_result = nullptr;
|
||||
status = ReorganizeQueryResults(&reorganize_search_result, placeholderGroups.data(), 1, results.data(), is_selected,
|
||||
1, plan);
|
||||
status = ReorganizeSearchResults(&reorganize_search_result, placeholderGroups.data(), 1, results.data(),
|
||||
is_selected, 1, plan);
|
||||
assert(status.error_code == Success);
|
||||
auto hits_blob_size = GetHitsBlobSize(reorganize_search_result);
|
||||
assert(hits_blob_size > 0);
|
||||
|
@ -654,10 +654,10 @@ TEST(CApiTest, Reduce) {
|
|||
GetHitSizePeerQueries(reorganize_search_result, 0, hit_size_peer_query.data());
|
||||
assert(hit_size_peer_query[0] > 0);
|
||||
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(res1);
|
||||
DeleteQueryResult(res2);
|
||||
DeleteSearchResult(res1);
|
||||
DeleteSearchResult(res2);
|
||||
DeleteMarshaledHits(reorganize_search_result);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
|
@ -723,7 +723,7 @@ TEST(CApiTest, ReduceSearchWithExpr) {
|
|||
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -735,9 +735,9 @@ TEST(CApiTest, ReduceSearchWithExpr) {
|
|||
timestamps.clear();
|
||||
timestamps.push_back(1);
|
||||
|
||||
std::vector<CQueryResult> results;
|
||||
CQueryResult res1;
|
||||
CQueryResult res2;
|
||||
std::vector<CSearchResult> results;
|
||||
CSearchResult res1;
|
||||
CSearchResult res2;
|
||||
auto res = Search(segment, plan, placeholderGroup, timestamps[0], &res1);
|
||||
assert(res.error_code == Success);
|
||||
res = Search(segment, plan, placeholderGroup, timestamps[0], &res2);
|
||||
|
@ -746,12 +746,12 @@ TEST(CApiTest, ReduceSearchWithExpr) {
|
|||
results.push_back(res2);
|
||||
|
||||
bool is_selected[1] = {false};
|
||||
status = ReduceQueryResults(results.data(), 1, is_selected);
|
||||
status = ReduceSearchResults(results.data(), 1, is_selected);
|
||||
assert(status.error_code == Success);
|
||||
FillTargetEntry(segment, plan, res1);
|
||||
void* reorganize_search_result = nullptr;
|
||||
status = ReorganizeQueryResults(&reorganize_search_result, placeholderGroups.data(), 1, results.data(), is_selected,
|
||||
1, plan);
|
||||
status = ReorganizeSearchResults(&reorganize_search_result, placeholderGroups.data(), 1, results.data(),
|
||||
is_selected, 1, plan);
|
||||
assert(status.error_code == Success);
|
||||
auto hits_blob_size = GetHitsBlobSize(reorganize_search_result);
|
||||
assert(hits_blob_size > 0);
|
||||
|
@ -766,10 +766,10 @@ TEST(CApiTest, ReduceSearchWithExpr) {
|
|||
GetHitSizePeerQueries(reorganize_search_result, 0, hit_size_peer_query.data());
|
||||
assert(hit_size_peer_query[0] > 0);
|
||||
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(res1);
|
||||
DeleteQueryResult(res2);
|
||||
DeleteSearchResult(res1);
|
||||
DeleteSearchResult(res2);
|
||||
DeleteMarshaledHits(reorganize_search_result);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
|
@ -912,7 +912,7 @@ TEST(CApiTest, UpdateSegmentIndex_Without_Predicate) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -923,7 +923,7 @@ TEST(CApiTest, UpdateSegmentIndex_Without_Predicate) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -949,7 +949,7 @@ TEST(CApiTest, UpdateSegmentIndex_Without_Predicate) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -973,22 +973,22 @@ TEST(CApiTest, UpdateSegmentIndex_Without_Predicate) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_raw_index_json = QueryResultToJson(*search_result_on_raw_index);
|
||||
auto search_result_on_bigIndex_json = QueryResultToJson((*(QueryResult*)c_search_result_on_bigIndex));
|
||||
auto search_result_on_raw_index_json = SearchResultToJson(*search_result_on_raw_index);
|
||||
auto search_result_on_bigIndex_json = SearchResultToJson((*(SearchResult*)c_search_result_on_bigIndex));
|
||||
std::cout << search_result_on_raw_index_json.dump(1) << std::endl;
|
||||
std::cout << search_result_on_bigIndex_json.dump(1) << std::endl;
|
||||
|
||||
ASSERT_EQ(search_result_on_raw_index_json.dump(1), search_result_on_bigIndex_json.dump(1));
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1032,7 +1032,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_Without_Predicate) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1043,7 +1043,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_Without_Predicate) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1069,7 +1069,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_Without_Predicate) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1093,22 +1093,22 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_Without_Predicate) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_raw_index_json = QueryResultToJson(*search_result_on_raw_index);
|
||||
auto search_result_on_bigIndex_json = QueryResultToJson((*(QueryResult*)c_search_result_on_bigIndex));
|
||||
auto search_result_on_raw_index_json = SearchResultToJson(*search_result_on_raw_index);
|
||||
auto search_result_on_bigIndex_json = SearchResultToJson((*(SearchResult*)c_search_result_on_bigIndex));
|
||||
std::cout << search_result_on_raw_index_json.dump(1) << std::endl;
|
||||
std::cout << search_result_on_bigIndex_json.dump(1) << std::endl;
|
||||
|
||||
ASSERT_EQ(search_result_on_raw_index_json.dump(1), search_result_on_bigIndex_json.dump(1));
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1168,7 +1168,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Range) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1179,7 +1179,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Range) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1206,7 +1206,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Range) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1230,11 +1230,11 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Range) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -1243,10 +1243,10 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Range) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1319,7 +1319,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Range) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1330,7 +1330,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Range) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1357,7 +1357,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Range) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1381,11 +1381,11 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Range) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -1394,10 +1394,10 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Range) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1456,7 +1456,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Term) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1467,7 +1467,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Term) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1494,7 +1494,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Term) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1518,11 +1518,11 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Term) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -1531,10 +1531,10 @@ TEST(CApiTest, UpdateSegmentIndex_With_float_Predicate_Term) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1658,7 +1658,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Term) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1669,7 +1669,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Term) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1696,7 +1696,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Term) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1720,11 +1720,11 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Term) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -1733,10 +1733,10 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_float_Predicate_Term) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1796,7 +1796,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Range) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1807,7 +1807,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Range) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -1835,7 +1835,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Range) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -1859,11 +1859,11 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Range) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -1872,10 +1872,10 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Range) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -1948,7 +1948,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Range) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -1959,7 +1959,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Range) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
ASSERT_TRUE(res_before_load_index.error_code == Success) << res_before_load_index.error_msg;
|
||||
|
||||
|
@ -1987,7 +1987,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Range) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -2011,11 +2011,11 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Range) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -2024,10 +2024,10 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Range) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -2086,7 +2086,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Term) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -2097,7 +2097,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Term) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -2125,7 +2125,7 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Term) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -2149,18 +2149,18 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Term) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
std::vector<CQueryResult> results;
|
||||
std::vector<CSearchResult> results;
|
||||
results.push_back(c_search_result_on_bigIndex);
|
||||
bool is_selected[1] = {false};
|
||||
status = ReduceQueryResults(results.data(), 1, is_selected);
|
||||
status = ReduceSearchResults(results.data(), 1, is_selected);
|
||||
assert(status.error_code == Success);
|
||||
FillTargetEntry(segment, plan, c_search_result_on_bigIndex);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -2169,10 +2169,10 @@ TEST(CApiTest, UpdateSegmentIndex_With_binary_Predicate_Term) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -2296,7 +2296,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Term) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -2307,7 +2307,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Term) {
|
|||
placeholderGroups.push_back(placeholderGroup);
|
||||
Timestamp time = 10000000;
|
||||
|
||||
CQueryResult c_search_result_on_smallIndex;
|
||||
CSearchResult c_search_result_on_smallIndex;
|
||||
auto res_before_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_smallIndex);
|
||||
assert(res_before_load_index.error_code == Success);
|
||||
|
||||
|
@ -2335,7 +2335,7 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Term) {
|
|||
vec_dis.push_back(dis[j] * -1);
|
||||
}
|
||||
|
||||
auto search_result_on_raw_index = (QueryResult*)c_search_result_on_smallIndex;
|
||||
auto search_result_on_raw_index = (SearchResult*)c_search_result_on_smallIndex;
|
||||
search_result_on_raw_index->internal_seg_offsets_ = vec_ids;
|
||||
search_result_on_raw_index->result_distances_ = vec_dis;
|
||||
|
||||
|
@ -2359,18 +2359,18 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Term) {
|
|||
status = UpdateSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
std::vector<CQueryResult> results;
|
||||
std::vector<CSearchResult> results;
|
||||
results.push_back(c_search_result_on_bigIndex);
|
||||
bool is_selected[1] = {false};
|
||||
status = ReduceQueryResults(results.data(), 1, is_selected);
|
||||
status = ReduceSearchResults(results.data(), 1, is_selected);
|
||||
assert(status.error_code == Success);
|
||||
FillTargetEntry(segment, plan, c_search_result_on_bigIndex);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
|
@ -2379,10 +2379,10 @@ TEST(CApiTest, UpdateSegmentIndex_Expr_With_binary_Predicate_Term) {
|
|||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_smallIndex);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_smallIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -2483,7 +2483,7 @@ TEST(CApiTest, SealedSegment_search_float_Predicate_Range) {
|
|||
|
||||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto status = CreatePlan(collection, dsl_string, &plan);
|
||||
auto status = CreateSearchPlan(collection, dsl_string, &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -2570,20 +2570,20 @@ TEST(CApiTest, SealedSegment_search_float_Predicate_Range) {
|
|||
status = UpdateSealedSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
@ -2650,7 +2650,7 @@ TEST(CApiTest, SealedSegment_search_float_With_Expr_Predicate_Range) {
|
|||
// search on segment's small index
|
||||
void* plan = nullptr;
|
||||
auto binary_plan = translate_text_plan_to_binary_plan(serialized_expr_plan);
|
||||
auto status = CreatePlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
auto status = CreateSearchPlanByExpr(collection, binary_plan.data(), binary_plan.size(), &plan);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
void* placeholderGroup = nullptr;
|
||||
|
@ -2737,20 +2737,20 @@ TEST(CApiTest, SealedSegment_search_float_With_Expr_Predicate_Range) {
|
|||
status = UpdateSealedSegmentIndex(segment, c_load_index_info);
|
||||
assert(status.error_code == Success);
|
||||
|
||||
CQueryResult c_search_result_on_bigIndex;
|
||||
CSearchResult c_search_result_on_bigIndex;
|
||||
auto res_after_load_index = Search(segment, plan, placeholderGroup, time, &c_search_result_on_bigIndex);
|
||||
assert(res_after_load_index.error_code == Success);
|
||||
|
||||
auto search_result_on_bigIndex = (*(QueryResult*)c_search_result_on_bigIndex);
|
||||
auto search_result_on_bigIndex = (*(SearchResult*)c_search_result_on_bigIndex);
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * K;
|
||||
ASSERT_EQ(search_result_on_bigIndex.internal_seg_offsets_[offset], 420000 + i);
|
||||
}
|
||||
|
||||
DeleteLoadIndexInfo(c_load_index_info);
|
||||
DeletePlan(plan);
|
||||
DeleteSearchPlan(plan);
|
||||
DeletePlaceholderGroup(placeholderGroup);
|
||||
DeleteQueryResult(c_search_result_on_bigIndex);
|
||||
DeleteSearchResult(c_search_result_on_bigIndex);
|
||||
DeleteCollection(collection);
|
||||
DeleteSegment(segment);
|
||||
}
|
||||
|
|
|
@ -235,10 +235,10 @@ TEST(Expr, ShowExecutor) {
|
|||
schema->AddDebugField("fakevec", DataType::VECTOR_FLOAT, 16, MetricType::METRIC_L2);
|
||||
int64_t num_queries = 100L;
|
||||
auto raw_data = DataGen(schema, num_queries);
|
||||
auto& info = node->query_info_;
|
||||
auto& info = node->search_info_;
|
||||
|
||||
info.metric_type_ = MetricType::METRIC_L2;
|
||||
info.topK_ = 20;
|
||||
info.topk_ = 20;
|
||||
info.field_offset_ = FieldOffset(0);
|
||||
node->predicate_ = std::nullopt;
|
||||
ShowPlanNodeVisitor show_visitor;
|
||||
|
|
|
@ -223,9 +223,9 @@ TEST(Indexing, IVFFlatNM) {
|
|||
|
||||
EXPECT_EQ(indexing->Count(), N);
|
||||
EXPECT_EQ(indexing->Dim(), DIM);
|
||||
auto query_dataset = knowhere::GenDataset(num_query, DIM, raw_data.data() + DIM * 4200);
|
||||
auto dataset = knowhere::GenDataset(num_query, DIM, raw_data.data() + DIM * 4200);
|
||||
|
||||
auto result = indexing->Query(query_dataset, conf, nullptr);
|
||||
auto result = indexing->Query(dataset, conf, nullptr);
|
||||
std::cout << "query ivf " << timer.get_step_seconds() << " seconds" << endl;
|
||||
|
||||
auto ids = result->Get<int64_t*>(milvus::knowhere::meta::IDS);
|
||||
|
@ -247,7 +247,7 @@ TEST(Indexing, BinaryBruteForce) {
|
|||
auto dataset = DataGen(schema, N, 10);
|
||||
auto bin_vec = dataset.get_col<uint8_t>(0);
|
||||
auto query_data = 1024 * dim / 8 + bin_vec.data();
|
||||
query::dataset::QueryDataset query_dataset{
|
||||
query::dataset::SearchDataset search_dataset{
|
||||
faiss::MetricType::METRIC_Jaccard, //
|
||||
num_queries, //
|
||||
topk, //
|
||||
|
@ -255,15 +255,15 @@ TEST(Indexing, BinaryBruteForce) {
|
|||
query_data //
|
||||
};
|
||||
|
||||
auto sub_result = query::BinarySearchBruteForce(query_dataset, bin_vec.data(), N, nullptr);
|
||||
auto sub_result = query::BinarySearchBruteForce(search_dataset, bin_vec.data(), N, nullptr);
|
||||
|
||||
QueryResult qr;
|
||||
qr.num_queries_ = num_queries;
|
||||
qr.topK_ = topk;
|
||||
qr.internal_seg_offsets_ = std::move(sub_result.mutable_labels());
|
||||
qr.result_distances_ = std::move(sub_result.mutable_values());
|
||||
SearchResult sr;
|
||||
sr.num_queries_ = num_queries;
|
||||
sr.topk_ = topk;
|
||||
sr.internal_seg_offsets_ = std::move(sub_result.mutable_labels());
|
||||
sr.result_distances_ = std::move(sub_result.mutable_values());
|
||||
|
||||
auto json = QueryResultToJson(qr);
|
||||
auto json = SearchResultToJson(sr);
|
||||
cout << json.dump(2);
|
||||
auto ref = json::parse(R"(
|
||||
[
|
||||
|
|
|
@ -36,9 +36,9 @@ TEST(Query, ShowExecutor) {
|
|||
schema->AddDebugField("fakevec", DataType::VECTOR_FLOAT, 16, MetricType::METRIC_L2);
|
||||
int64_t num_queries = 100L;
|
||||
auto raw_data = DataGen(schema, num_queries);
|
||||
auto& info = node->query_info_;
|
||||
auto& info = node->search_info_;
|
||||
info.metric_type_ = MetricType::METRIC_L2;
|
||||
info.topK_ = 20;
|
||||
info.topk_ = 20;
|
||||
info.field_offset_ = FieldOffset(1000);
|
||||
node->predicate_ = std::nullopt;
|
||||
ShowPlanNodeVisitor show_visitor;
|
||||
|
@ -176,10 +176,10 @@ TEST(Query, ExecWithPredicateLoader) {
|
|||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
Timestamp time = 1000000;
|
||||
|
||||
auto qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto sr = segment->Search(plan.get(), *ph_group, time);
|
||||
int topk = 5;
|
||||
|
||||
Json json = QueryResultToJson(qr);
|
||||
Json json = SearchResultToJson(sr);
|
||||
auto ref = json::parse(R"(
|
||||
[
|
||||
[
|
||||
|
@ -268,10 +268,10 @@ TEST(Query, ExecWithPredicateSmallN) {
|
|||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
Timestamp time = 1000000;
|
||||
|
||||
auto qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto sr = segment->Search(plan.get(), *ph_group, time);
|
||||
int topk = 5;
|
||||
|
||||
Json json = QueryResultToJson(qr);
|
||||
Json json = SearchResultToJson(sr);
|
||||
std::cout << json.dump(2);
|
||||
}
|
||||
|
||||
|
@ -319,10 +319,10 @@ TEST(Query, ExecWithPredicate) {
|
|||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
Timestamp time = 1000000;
|
||||
|
||||
auto qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto sr = segment->Search(plan.get(), *ph_group, time);
|
||||
int topk = 5;
|
||||
|
||||
Json json = QueryResultToJson(qr);
|
||||
Json json = SearchResultToJson(sr);
|
||||
auto ref = json::parse(R"(
|
||||
[
|
||||
[
|
||||
|
@ -408,15 +408,15 @@ TEST(Query, ExecTerm) {
|
|||
auto num_queries = 3;
|
||||
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 1000000;
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
std::vector<std::vector<std::string>> results;
|
||||
int topk = 5;
|
||||
auto json = QueryResultToJson(qr);
|
||||
ASSERT_EQ(qr.num_queries_, num_queries);
|
||||
ASSERT_EQ(qr.topK_, topk);
|
||||
auto json = SearchResultToJson(sr);
|
||||
ASSERT_EQ(sr.num_queries_, num_queries);
|
||||
ASSERT_EQ(sr.topk_, topk);
|
||||
// for(auto x: )
|
||||
}
|
||||
|
||||
|
@ -452,14 +452,14 @@ TEST(Query, ExecEmpty) {
|
|||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
Timestamp time = 1000000;
|
||||
|
||||
auto qr = segment->Search(plan.get(), *ph_group, time);
|
||||
std::cout << QueryResultToJson(qr);
|
||||
auto sr = segment->Search(plan.get(), *ph_group, time);
|
||||
std::cout << SearchResultToJson(sr);
|
||||
|
||||
for (auto i : qr.internal_seg_offsets_) {
|
||||
for (auto i : sr.internal_seg_offsets_) {
|
||||
ASSERT_EQ(i, -1);
|
||||
}
|
||||
|
||||
for (auto v : qr.result_distances_) {
|
||||
for (auto v : sr.result_distances_) {
|
||||
ASSERT_EQ(v, std::numeric_limits<float>::max());
|
||||
}
|
||||
}
|
||||
|
@ -498,13 +498,13 @@ TEST(Query, ExecWithoutPredicateFlat) {
|
|||
auto num_queries = 5;
|
||||
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 1000000;
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
std::vector<std::vector<std::string>> results;
|
||||
int topk = 5;
|
||||
auto json = QueryResultToJson(qr);
|
||||
auto json = SearchResultToJson(sr);
|
||||
std::cout << json.dump(2);
|
||||
}
|
||||
|
||||
|
@ -542,13 +542,13 @@ TEST(Query, ExecWithoutPredicate) {
|
|||
auto num_queries = 5;
|
||||
auto ph_group_raw = CreatePlaceholderGroup(num_queries, 16, 1024);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 1000000;
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
std::vector<std::vector<std::string>> results;
|
||||
int topk = 5;
|
||||
auto json = QueryResultToJson(qr);
|
||||
auto json = SearchResultToJson(sr);
|
||||
auto ref = json::parse(R"(
|
||||
[
|
||||
[
|
||||
|
@ -629,9 +629,9 @@ TEST(Indexing, InnerProduct) {
|
|||
auto ph_group_raw = CreatePlaceholderGroupFromBlob(num_queries, 16, col.data());
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
Timestamp ts = N * 2;
|
||||
QueryResult qr;
|
||||
qr = segment->Search(plan.get(), *ph_group, ts);
|
||||
std::cout << QueryResultToJson(qr).dump(2);
|
||||
SearchResult sr;
|
||||
sr = segment->Search(plan.get(), *ph_group, ts);
|
||||
std::cout << SearchResultToJson(sr).dump(2);
|
||||
}
|
||||
|
||||
TEST(Query, FillSegment) {
|
||||
|
@ -738,8 +738,8 @@ TEST(Query, FillSegment) {
|
|||
plan->target_entries_.clear();
|
||||
plan->target_entries_.push_back(schema->get_offset(FieldName("fakevec")));
|
||||
plan->target_entries_.push_back(schema->get_offset(FieldName("the_value")));
|
||||
QueryResult result = segment->Search(plan.get(), *ph, ts);
|
||||
// std::cout << QueryResultToJson(result).dump(2);
|
||||
SearchResult result = segment->Search(plan.get(), *ph, ts);
|
||||
// std::cout << SearchResultToJson(result).dump(2);
|
||||
result.result_offsets_.resize(topk * num_queries);
|
||||
segment->FillTargetEntry(plan.get(), result);
|
||||
|
||||
|
@ -815,13 +815,13 @@ TEST(Query, ExecWithPredicateBinary) {
|
|||
auto num_queries = 5;
|
||||
auto ph_group_raw = CreateBinaryPlaceholderGroupFromBlob(num_queries, 512, vec_ptr.data() + 1024 * 512 / 8);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 1000000;
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
int topk = 5;
|
||||
|
||||
Json json = QueryResultToJson(qr);
|
||||
Json json = SearchResultToJson(sr);
|
||||
std::cout << json.dump(2);
|
||||
// ASSERT_EQ(json.dump(2), ref.dump(2));
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "query/SubQueryResult.h"
|
||||
#include "query/SubSearchResult.h"
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
|
@ -33,7 +33,7 @@ TEST(Reduce, SubQueryResult) {
|
|||
}
|
||||
}
|
||||
std::default_random_engine e(42);
|
||||
SubQueryResult final_result(num_queries, topk, metric_type);
|
||||
SubSearchResult final_result(num_queries, topk, metric_type);
|
||||
for (int i = 0; i < iteration; ++i) {
|
||||
std::vector<int64_t> labels;
|
||||
std::vector<float> values;
|
||||
|
@ -48,7 +48,7 @@ TEST(Reduce, SubQueryResult) {
|
|||
std::sort(labels.begin() + n * topk, labels.begin() + n * topk + topk);
|
||||
std::sort(values.begin() + n * topk, values.begin() + n * topk + topk);
|
||||
}
|
||||
SubQueryResult sub_result(num_queries, topk, metric_type);
|
||||
SubSearchResult sub_result(num_queries, topk, metric_type);
|
||||
sub_result.mutable_values() = values;
|
||||
sub_result.mutable_labels() = labels;
|
||||
final_result.merge(sub_result);
|
||||
|
@ -68,7 +68,7 @@ TEST(Reduce, SubQueryResult) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(Reduce, SubQueryResultDesc) {
|
||||
TEST(Reduce, SubSearchResultDesc) {
|
||||
int64_t num_queries = 512;
|
||||
int64_t topk = 32;
|
||||
int64_t iteration = 50;
|
||||
|
@ -84,7 +84,7 @@ TEST(Reduce, SubQueryResultDesc) {
|
|||
}
|
||||
}
|
||||
std::default_random_engine e(42);
|
||||
SubQueryResult final_result(num_queries, topk, metric_type);
|
||||
SubSearchResult final_result(num_queries, topk, metric_type);
|
||||
for (int i = 0; i < iteration; ++i) {
|
||||
std::vector<int64_t> labels;
|
||||
std::vector<float> values;
|
||||
|
@ -99,7 +99,7 @@ TEST(Reduce, SubQueryResultDesc) {
|
|||
std::sort(labels.begin() + n * topk, labels.begin() + n * topk + topk, std::greater<int64_t>());
|
||||
std::sort(values.begin() + n * topk, values.begin() + n * topk + topk, std::greater<float>());
|
||||
}
|
||||
SubQueryResult sub_result(num_queries, topk, metric_type);
|
||||
SubSearchResult sub_result(num_queries, topk, metric_type);
|
||||
sub_result.mutable_values() = values;
|
||||
sub_result.mutable_labels() = labels;
|
||||
final_result.merge(sub_result);
|
||||
|
|
|
@ -69,12 +69,12 @@ TEST(Sealed, without_predicate) {
|
|||
auto ph_group_raw = CreatePlaceholderGroupFromBlob(num_queries, 16, query_ptr);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 1000000;
|
||||
std::vector<const PlaceholderGroup*> ph_group_arr = {ph_group.get()};
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto pre_result = QueryResultToJson(qr);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto pre_result = SearchResultToJson(sr);
|
||||
auto indexing = std::make_shared<knowhere::IVF>();
|
||||
|
||||
auto conf = knowhere::Config{{knowhere::meta::DIM, dim},
|
||||
|
@ -100,9 +100,9 @@ TEST(Sealed, without_predicate) {
|
|||
std::vector<int64_t> vec_ids(ids, ids + topK * num_queries);
|
||||
std::vector<float> vec_dis(dis, dis + topK * num_queries);
|
||||
|
||||
qr.internal_seg_offsets_ = vec_ids;
|
||||
qr.result_distances_ = vec_dis;
|
||||
auto ref_result = QueryResultToJson(qr);
|
||||
sr.internal_seg_offsets_ = vec_ids;
|
||||
sr.result_distances_ = vec_dis;
|
||||
auto ref_result = SearchResultToJson(sr);
|
||||
|
||||
LoadIndexInfo load_info;
|
||||
load_info.field_id = fake_id.get();
|
||||
|
@ -110,11 +110,11 @@ TEST(Sealed, without_predicate) {
|
|||
load_info.index_params["metric_type"] = "L2";
|
||||
|
||||
segment->LoadIndexing(load_info);
|
||||
qr = QueryResult();
|
||||
sr = SearchResult();
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
|
||||
auto post_result = QueryResultToJson(qr);
|
||||
auto post_result = SearchResultToJson(sr);
|
||||
std::cout << ref_result.dump(1);
|
||||
std::cout << post_result.dump(1);
|
||||
ASSERT_EQ(ref_result.dump(2), post_result.dump(2));
|
||||
|
@ -170,12 +170,12 @@ TEST(Sealed, with_predicate) {
|
|||
auto ph_group_raw = CreatePlaceholderGroupFromBlob(num_queries, 16, query_ptr);
|
||||
auto ph_group = ParsePlaceholderGroup(plan.get(), ph_group_raw.SerializeAsString());
|
||||
|
||||
QueryResult qr;
|
||||
SearchResult sr;
|
||||
Timestamp time = 10000000;
|
||||
std::vector<const PlaceholderGroup*> ph_group_arr = {ph_group.get()};
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto pre_qr = qr;
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto pre_sr = sr;
|
||||
auto indexing = std::make_shared<knowhere::IVF>();
|
||||
|
||||
auto conf = knowhere::Config{{knowhere::meta::DIM, dim},
|
||||
|
@ -202,15 +202,15 @@ TEST(Sealed, with_predicate) {
|
|||
load_info.index_params["metric_type"] = "L2";
|
||||
|
||||
segment->LoadIndexing(load_info);
|
||||
qr = QueryResult();
|
||||
sr = SearchResult();
|
||||
|
||||
qr = segment->Search(plan.get(), *ph_group, time);
|
||||
sr = segment->Search(plan.get(), *ph_group, time);
|
||||
|
||||
auto post_qr = qr;
|
||||
auto post_sr = sr;
|
||||
for (int i = 0; i < num_queries; ++i) {
|
||||
auto offset = i * topK;
|
||||
ASSERT_EQ(post_qr.internal_seg_offsets_[offset], 420000 + i);
|
||||
ASSERT_EQ(post_qr.result_distances_[offset], 0.0);
|
||||
ASSERT_EQ(post_sr.internal_seg_offsets_[offset], 420000 + i);
|
||||
ASSERT_EQ(post_sr.result_distances_[offset], 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,15 +290,15 @@ TEST(Sealed, LoadFieldData) {
|
|||
ASSERT_EQ(chunk_span2[i], ref2[i]);
|
||||
}
|
||||
|
||||
auto qr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto json = QueryResultToJson(qr);
|
||||
auto sr = segment->Search(plan.get(), *ph_group, time);
|
||||
auto json = SearchResultToJson(sr);
|
||||
std::cout << json.dump(1);
|
||||
|
||||
segment->DropIndex(fakevec_id);
|
||||
ASSERT_ANY_THROW(segment->Search(plan.get(), *ph_group, time));
|
||||
segment->LoadIndex(vec_info);
|
||||
auto qr2 = segment->Search(plan.get(), *ph_group, time);
|
||||
auto json2 = QueryResultToJson(qr);
|
||||
auto sr2 = segment->Search(plan.get(), *ph_group, time);
|
||||
auto json2 = SearchResultToJson(sr);
|
||||
ASSERT_EQ(json.dump(-2), json2.dump(-2));
|
||||
segment->DropFieldData(double_id);
|
||||
ASSERT_ANY_THROW(segment->Search(plan.get(), *ph_group, time));
|
||||
|
|
|
@ -105,10 +105,10 @@ TEST(SegmentCoreTest, MockTest) {
|
|||
RowBasedRawData data_chunk{raw_data.data(), (int)line_sizeof, N};
|
||||
auto offset = segment->PreInsert(N);
|
||||
segment->Insert(offset, N, uids.data(), timestamps.data(), data_chunk);
|
||||
QueryResult query_result;
|
||||
// segment->Query(nullptr, 0, query_result);
|
||||
SearchResult search_result;
|
||||
// segment->Query(nullptr, 0, query_result);
|
||||
segment->Close();
|
||||
// segment->BuildIndex();
|
||||
// segment->BuildIndex();
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -276,16 +276,16 @@ CreateBinaryPlaceholderGroupFromBlob(int64_t num_queries, int64_t dim, const uin
|
|||
}
|
||||
|
||||
inline json
|
||||
QueryResultToJson(const QueryResult& qr) {
|
||||
int64_t num_queries = qr.num_queries_;
|
||||
int64_t topk = qr.topK_;
|
||||
SearchResultToJson(const SearchResult& sr) {
|
||||
int64_t num_queries = sr.num_queries_;
|
||||
int64_t topk = sr.topk_;
|
||||
std::vector<std::vector<std::string>> results;
|
||||
for (int q = 0; q < num_queries; ++q) {
|
||||
std::vector<std::string> result;
|
||||
for (int k = 0; k < topk; ++k) {
|
||||
int index = q * topk + k;
|
||||
result.emplace_back(std::to_string(qr.internal_seg_offsets_[index]) + "->" +
|
||||
std::to_string(qr.result_distances_[index]));
|
||||
result.emplace_back(std::to_string(sr.internal_seg_offsets_[index]) + "->" +
|
||||
std::to_string(sr.result_distances_[index]));
|
||||
}
|
||||
results.emplace_back(std::move(result));
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func (h *historical) close() {
|
|||
func (h *historical) search(searchReqs []*searchRequest,
|
||||
collID UniqueID,
|
||||
partIDs []UniqueID,
|
||||
plan *Plan,
|
||||
plan *SearchPlan,
|
||||
searchTs Timestamp) ([]*SearchResult, []*Segment, error) {
|
||||
|
||||
searchResults := make([]*SearchResult, 0)
|
||||
|
@ -137,7 +137,7 @@ func (h *historical) search(searchReqs []*searchRequest,
|
|||
if !seg.getOnService() {
|
||||
continue
|
||||
}
|
||||
searchResult, err := seg.segmentSearch(plan, searchReqs, []Timestamp{searchTs})
|
||||
searchResult, err := seg.search(plan, searchReqs, []Timestamp{searchTs})
|
||||
if err != nil {
|
||||
return searchResults, segmentResults, err
|
||||
}
|
||||
|
|
|
@ -27,66 +27,66 @@ import (
|
|||
"github.com/milvus-io/milvus/internal/proto/segcorepb"
|
||||
)
|
||||
|
||||
type Plan struct {
|
||||
cPlan C.CPlan
|
||||
type SearchPlan struct {
|
||||
cSearchPlan C.CSearchPlan
|
||||
}
|
||||
|
||||
func createPlan(col *Collection, dsl string) (*Plan, error) {
|
||||
func createSearchPlan(col *Collection, dsl string) (*SearchPlan, error) {
|
||||
cDsl := C.CString(dsl)
|
||||
defer C.free(unsafe.Pointer(cDsl))
|
||||
var cPlan C.CPlan
|
||||
status := C.CreatePlan(col.collectionPtr, cDsl, &cPlan)
|
||||
var cPlan C.CSearchPlan
|
||||
status := C.CreateSearchPlan(col.collectionPtr, cDsl, &cPlan)
|
||||
|
||||
err1 := HandleCStatus(&status, "Create Plan failed")
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
|
||||
var newPlan = &Plan{cPlan: cPlan}
|
||||
var newPlan = &SearchPlan{cSearchPlan: cPlan}
|
||||
return newPlan, nil
|
||||
}
|
||||
|
||||
func createPlanByExpr(col *Collection, expr []byte) (*Plan, error) {
|
||||
var cPlan C.CPlan
|
||||
status := C.CreatePlanByExpr(col.collectionPtr, (*C.char)(unsafe.Pointer(&expr[0])), (C.int64_t)(len(expr)), &cPlan)
|
||||
func createSearchPlanByExpr(col *Collection, expr []byte) (*SearchPlan, error) {
|
||||
var cPlan C.CSearchPlan
|
||||
status := C.CreateSearchPlanByExpr(col.collectionPtr, (*C.char)(unsafe.Pointer(&expr[0])), (C.int64_t)(len(expr)), &cPlan)
|
||||
|
||||
err1 := HandleCStatus(&status, "Create Plan by expr failed")
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
|
||||
var newPlan = &Plan{cPlan: cPlan}
|
||||
var newPlan = &SearchPlan{cSearchPlan: cPlan}
|
||||
return newPlan, nil
|
||||
}
|
||||
|
||||
func (plan *Plan) getTopK() int64 {
|
||||
topK := C.GetTopK(plan.cPlan)
|
||||
func (plan *SearchPlan) getTopK() int64 {
|
||||
topK := C.GetTopK(plan.cSearchPlan)
|
||||
return int64(topK)
|
||||
}
|
||||
|
||||
func (plan *Plan) getMetricType() string {
|
||||
cMetricType := C.GetMetricType(plan.cPlan)
|
||||
func (plan *SearchPlan) getMetricType() string {
|
||||
cMetricType := C.GetMetricType(plan.cSearchPlan)
|
||||
defer C.free(unsafe.Pointer(cMetricType))
|
||||
metricType := C.GoString(cMetricType)
|
||||
return metricType
|
||||
}
|
||||
|
||||
func (plan *Plan) delete() {
|
||||
C.DeletePlan(plan.cPlan)
|
||||
func (plan *SearchPlan) delete() {
|
||||
C.DeleteSearchPlan(plan.cSearchPlan)
|
||||
}
|
||||
|
||||
type searchRequest struct {
|
||||
cPlaceholderGroup C.CPlaceholderGroup
|
||||
}
|
||||
|
||||
func parseSearchRequest(plan *Plan, searchRequestBlob []byte) (*searchRequest, error) {
|
||||
func parseSearchRequest(plan *SearchPlan, searchRequestBlob []byte) (*searchRequest, error) {
|
||||
if len(searchRequestBlob) == 0 {
|
||||
return nil, errors.New("empty search request")
|
||||
}
|
||||
var blobPtr = unsafe.Pointer(&searchRequestBlob[0])
|
||||
blobSize := C.long(len(searchRequestBlob))
|
||||
var cPlaceholderGroup C.CPlaceholderGroup
|
||||
status := C.ParsePlaceholderGroup(plan.cPlan, blobPtr, blobSize, &cPlaceholderGroup)
|
||||
status := C.ParsePlaceholderGroup(plan.cSearchPlan, blobPtr, blobSize, &cPlaceholderGroup)
|
||||
|
||||
if err := HandleCStatus(&status, "parser searchRequest failed"); err != nil {
|
||||
return nil, err
|
||||
|
@ -106,8 +106,8 @@ func (pg *searchRequest) delete() {
|
|||
}
|
||||
|
||||
type RetrievePlan struct {
|
||||
RetrievePlanPtr C.CRetrievePlan
|
||||
Timestamp uint64
|
||||
cRetrievePlan C.CRetrievePlan
|
||||
Timestamp uint64
|
||||
}
|
||||
|
||||
func createRetrievePlan(col *Collection, msg *segcorepb.RetrieveRequest, timestamp uint64) (*RetrievePlan, error) {
|
||||
|
@ -117,7 +117,7 @@ func createRetrievePlan(col *Collection, msg *segcorepb.RetrieveRequest, timesta
|
|||
}
|
||||
plan := new(RetrievePlan)
|
||||
plan.Timestamp = timestamp
|
||||
status := C.CreateRetrievePlan(col.collectionPtr, protoCGo.CProto, &plan.RetrievePlanPtr)
|
||||
status := C.CreateRetrievePlan(col.collectionPtr, protoCGo.CProto, &plan.cRetrievePlan)
|
||||
err2 := HandleCStatus(&status, "create retrieve plan failed")
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
|
@ -126,5 +126,5 @@ func createRetrievePlan(col *Collection, msg *segcorepb.RetrieveRequest, timesta
|
|||
}
|
||||
|
||||
func (plan *RetrievePlan) delete() {
|
||||
C.DeleteRetrievePlan(plan.RetrievePlanPtr)
|
||||
C.DeleteRetrievePlan(plan.cRetrievePlan)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestPlan_Plan(t *testing.T) {
|
|||
|
||||
dslString := "{\"bool\": { \n\"vector\": {\n \"vec\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\"topk\": 10 \n } \n } \n } \n }"
|
||||
|
||||
plan, err := createPlan(collection, dslString)
|
||||
plan, err := createSearchPlan(collection, dslString)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, plan, nil)
|
||||
topk := plan.getTopK()
|
||||
|
@ -49,7 +49,7 @@ func TestPlan_PlaceholderGroup(t *testing.T) {
|
|||
|
||||
dslString := "{\"bool\": { \n\"vector\": {\n \"vec\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\"topk\": 10 \n } \n } \n } \n }"
|
||||
|
||||
plan, err := createPlan(collection, dslString)
|
||||
plan, err := createSearchPlan(collection, dslString)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, plan)
|
||||
|
||||
|
|
|
@ -781,16 +781,16 @@ func (q *queryCollection) search(msg queryMsg) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var plan *Plan
|
||||
var plan *SearchPlan
|
||||
if searchMsg.GetDslType() == commonpb.DslType_BoolExprV1 {
|
||||
expr := searchMsg.SerializedExprPlan
|
||||
plan, err = createPlanByExpr(collection, expr)
|
||||
plan, err = createSearchPlanByExpr(collection, expr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
dsl := searchMsg.Dsl
|
||||
plan, err = createPlan(collection, dsl)
|
||||
plan, err = createSearchPlan(collection, dsl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -931,8 +931,8 @@ func (q *queryCollection) search(msg queryMsg) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
marshaledHits, err = reorganizeSingleQueryResult(plan, searchRequests, searchResults[0])
|
||||
sp.LogFields(oplog.String("statistical time", "reorganizeSingleQueryResult end"))
|
||||
marshaledHits, err = reorganizeSingleSearchResult(plan, searchRequests, searchResults[0])
|
||||
sp.LogFields(oplog.String("statistical time", "reorganizeSingleSearchResult end"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -947,8 +947,8 @@ func (q *queryCollection) search(msg queryMsg) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
marshaledHits, err = reorganizeQueryResults(plan, searchRequests, searchResults, numSegment, inReduced)
|
||||
sp.LogFields(oplog.String("statistical time", "reorganizeQueryResults end"))
|
||||
marshaledHits, err = reorganizeSearchResults(plan, searchRequests, searchResults, numSegment, inReduced)
|
||||
sp.LogFields(oplog.String("statistical time", "reorganizeSearchResults end"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1121,7 +1121,7 @@ func (q *queryCollection) retrieve(msg queryMsg) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := segment.segmentGetEntityByIds(plan)
|
||||
result, err := segment.getEntityByIds(plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1141,7 +1141,7 @@ func (q *queryCollection) retrieve(msg queryMsg) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := segment.segmentGetEntityByIds(plan)
|
||||
result, err := segment.getEntityByIds(plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
)
|
||||
|
||||
type SearchResult struct {
|
||||
cQueryResult C.CQueryResult
|
||||
cSearchResult C.CSearchResult
|
||||
}
|
||||
|
||||
type MarshaledHits struct {
|
||||
|
@ -39,15 +39,15 @@ type MarshaledHits struct {
|
|||
}
|
||||
|
||||
func reduceSearchResults(searchResults []*SearchResult, numSegments int64, inReduced []bool) error {
|
||||
cSearchResults := make([]C.CQueryResult, 0)
|
||||
cSearchResults := make([]C.CSearchResult, 0)
|
||||
for _, res := range searchResults {
|
||||
cSearchResults = append(cSearchResults, res.cQueryResult)
|
||||
cSearchResults = append(cSearchResults, res.cSearchResult)
|
||||
}
|
||||
cSearchResultPtr := (*C.CQueryResult)(&cSearchResults[0])
|
||||
cSearchResultPtr := (*C.CSearchResult)(&cSearchResults[0])
|
||||
cNumSegments := C.long(numSegments)
|
||||
cInReduced := (*C.bool)(&inReduced[0])
|
||||
|
||||
status := C.ReduceQueryResults(cSearchResultPtr, cNumSegments, cInReduced)
|
||||
status := C.ReduceSearchResults(cSearchResultPtr, cNumSegments, cInReduced)
|
||||
|
||||
errorCode := status.error_code
|
||||
|
||||
|
@ -59,7 +59,7 @@ func reduceSearchResults(searchResults []*SearchResult, numSegments int64, inRed
|
|||
return nil
|
||||
}
|
||||
|
||||
func fillTargetEntry(plan *Plan, searchResults []*SearchResult, matchedSegments []*Segment, inReduced []bool) error {
|
||||
func fillTargetEntry(plan *SearchPlan, searchResults []*SearchResult, matchedSegments []*Segment, inReduced []bool) error {
|
||||
wg := &sync.WaitGroup{}
|
||||
fmt.Println(inReduced)
|
||||
for i := range inReduced {
|
||||
|
@ -78,7 +78,7 @@ func fillTargetEntry(plan *Plan, searchResults []*SearchResult, matchedSegments
|
|||
return nil
|
||||
}
|
||||
|
||||
func reorganizeQueryResults(plan *Plan, searchRequests []*searchRequest, searchResults []*SearchResult, numSegments int64, inReduced []bool) (*MarshaledHits, error) {
|
||||
func reorganizeSearchResults(plan *SearchPlan, searchRequests []*searchRequest, searchResults []*SearchResult, numSegments int64, inReduced []bool) (*MarshaledHits, error) {
|
||||
cPlaceholderGroups := make([]C.CPlaceholderGroup, 0)
|
||||
for _, pg := range searchRequests {
|
||||
cPlaceholderGroups = append(cPlaceholderGroups, (*pg).cPlaceholderGroup)
|
||||
|
@ -86,28 +86,28 @@ func reorganizeQueryResults(plan *Plan, searchRequests []*searchRequest, searchR
|
|||
var cPlaceHolderGroupPtr = (*C.CPlaceholderGroup)(&cPlaceholderGroups[0])
|
||||
var cNumGroup = (C.long)(len(searchRequests))
|
||||
|
||||
cSearchResults := make([]C.CQueryResult, 0)
|
||||
cSearchResults := make([]C.CSearchResult, 0)
|
||||
for _, res := range searchResults {
|
||||
cSearchResults = append(cSearchResults, res.cQueryResult)
|
||||
cSearchResults = append(cSearchResults, res.cSearchResult)
|
||||
}
|
||||
cSearchResultPtr := (*C.CQueryResult)(&cSearchResults[0])
|
||||
cSearchResultPtr := (*C.CSearchResult)(&cSearchResults[0])
|
||||
|
||||
var cNumSegments = C.long(numSegments)
|
||||
var cInReduced = (*C.bool)(&inReduced[0])
|
||||
var cMarshaledHits C.CMarshaledHits
|
||||
|
||||
status := C.ReorganizeQueryResults(&cMarshaledHits, cPlaceHolderGroupPtr, cNumGroup, cSearchResultPtr, cInReduced, cNumSegments, plan.cPlan)
|
||||
status := C.ReorganizeSearchResults(&cMarshaledHits, cPlaceHolderGroupPtr, cNumGroup, cSearchResultPtr, cInReduced, cNumSegments, plan.cSearchPlan)
|
||||
errorCode := status.error_code
|
||||
|
||||
if errorCode != 0 {
|
||||
errorMsg := C.GoString(status.error_msg)
|
||||
defer C.free(unsafe.Pointer(status.error_msg))
|
||||
return nil, errors.New("reorganizeQueryResults failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
||||
return nil, errors.New("reorganizeSearchResults failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
||||
}
|
||||
return &MarshaledHits{cMarshaledHits: cMarshaledHits}, nil
|
||||
}
|
||||
|
||||
func reorganizeSingleQueryResult(plan *Plan, placeholderGroups []*searchRequest, searchResult *SearchResult) (*MarshaledHits, error) {
|
||||
func reorganizeSingleSearchResult(plan *SearchPlan, placeholderGroups []*searchRequest, searchResult *SearchResult) (*MarshaledHits, error) {
|
||||
cPlaceholderGroups := make([]C.CPlaceholderGroup, 0)
|
||||
for _, pg := range placeholderGroups {
|
||||
cPlaceholderGroups = append(cPlaceholderGroups, (*pg).cPlaceholderGroup)
|
||||
|
@ -115,16 +115,16 @@ func reorganizeSingleQueryResult(plan *Plan, placeholderGroups []*searchRequest,
|
|||
var cPlaceHolderGroupPtr = (*C.CPlaceholderGroup)(&cPlaceholderGroups[0])
|
||||
var cNumGroup = (C.long)(len(placeholderGroups))
|
||||
|
||||
cSearchResult := searchResult.cQueryResult
|
||||
cSearchResult := searchResult.cSearchResult
|
||||
var cMarshaledHits C.CMarshaledHits
|
||||
|
||||
status := C.ReorganizeSingleQueryResult(&cMarshaledHits, cPlaceHolderGroupPtr, cNumGroup, cSearchResult, plan.cPlan)
|
||||
status := C.ReorganizeSingleSearchResult(&cMarshaledHits, cPlaceHolderGroupPtr, cNumGroup, cSearchResult, plan.cSearchPlan)
|
||||
errorCode := status.error_code
|
||||
|
||||
if errorCode != 0 {
|
||||
errorMsg := C.GoString(status.error_msg)
|
||||
defer C.free(unsafe.Pointer(status.error_msg))
|
||||
return nil, errors.New("reorganizeQueryResults failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
||||
return nil, errors.New("reorganizeSearchResults failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
||||
}
|
||||
return &MarshaledHits{cMarshaledHits: cMarshaledHits}, nil
|
||||
}
|
||||
|
@ -157,6 +157,6 @@ func deleteMarshaledHits(hits *MarshaledHits) {
|
|||
|
||||
func deleteSearchResults(results []*SearchResult) {
|
||||
for _, result := range results {
|
||||
C.DeleteQueryResult(result.cQueryResult)
|
||||
C.DeleteSearchResult(result.cSearchResult)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestReduce_AllFunc(t *testing.T) {
|
|||
log.Print("marshal placeholderGroup failed")
|
||||
}
|
||||
|
||||
plan, err := createPlan(collection, dslString)
|
||||
plan, err := createSearchPlan(collection, dslString)
|
||||
assert.NoError(t, err)
|
||||
holder, err := parseSearchRequest(plan, placeGroupByte)
|
||||
assert.NoError(t, err)
|
||||
|
@ -72,7 +72,7 @@ func TestReduce_AllFunc(t *testing.T) {
|
|||
|
||||
searchResults := make([]*SearchResult, 0)
|
||||
matchedSegment := make([]*Segment, 0)
|
||||
searchResult, err := segment.segmentSearch(plan, placeholderGroups, []Timestamp{0})
|
||||
searchResult, err := segment.search(plan, placeholderGroups, []Timestamp{0})
|
||||
assert.Nil(t, err)
|
||||
searchResults = append(searchResults, searchResult)
|
||||
matchedSegment = append(matchedSegment, segment)
|
||||
|
@ -83,7 +83,7 @@ func TestReduce_AllFunc(t *testing.T) {
|
|||
err = fillTargetEntry(plan, searchResults, matchedSegment, testReduce)
|
||||
assert.Nil(t, err)
|
||||
|
||||
marshaledHits, err := reorganizeQueryResults(plan, placeholderGroups, searchResults, 1, testReduce)
|
||||
marshaledHits, err := reorganizeSearchResults(plan, placeholderGroups, searchResults, 1, testReduce)
|
||||
assert.NotNil(t, marshaledHits)
|
||||
assert.Nil(t, err)
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ func (s *Segment) getMemSize() int64 {
|
|||
return int64(memoryUsageInBytes)
|
||||
}
|
||||
|
||||
func (s *Segment) segmentSearch(plan *Plan,
|
||||
func (s *Segment) search(plan *SearchPlan,
|
||||
searchRequests []*searchRequest,
|
||||
timestamp []Timestamp) (*SearchResult, error) {
|
||||
/*
|
||||
|
@ -236,7 +236,7 @@ func (s *Segment) segmentSearch(plan *Plan,
|
|||
cPlaceHolderGroup := cPlaceholderGroups[0]
|
||||
|
||||
log.Debug("do search on segment", zap.Int64("segmentID", s.segmentID), zap.Int32("segmentType", int32(s.segmentType)))
|
||||
var status = C.Search(s.segmentPtr, plan.cPlan, cPlaceHolderGroup, ts, &searchResult.cQueryResult)
|
||||
var status = C.Search(s.segmentPtr, plan.cSearchPlan, cPlaceHolderGroup, ts, &searchResult.cSearchResult)
|
||||
errorCode := status.error_code
|
||||
|
||||
if errorCode != 0 {
|
||||
|
@ -248,8 +248,8 @@ func (s *Segment) segmentSearch(plan *Plan,
|
|||
return &searchResult, nil
|
||||
}
|
||||
|
||||
func (s *Segment) segmentGetEntityByIds(plan *RetrievePlan) (*segcorepb.RetrieveResults, error) {
|
||||
resProto := C.GetEntityByIds(s.segmentPtr, plan.RetrievePlanPtr, C.uint64_t(plan.Timestamp))
|
||||
func (s *Segment) getEntityByIds(plan *RetrievePlan) (*segcorepb.RetrieveResults, error) {
|
||||
resProto := C.GetEntityByIds(s.segmentPtr, plan.cRetrievePlan, C.uint64_t(plan.Timestamp))
|
||||
result := new(segcorepb.RetrieveResults)
|
||||
err := HandleCProtoResult(&resProto, result)
|
||||
if err != nil {
|
||||
|
@ -258,14 +258,13 @@ func (s *Segment) segmentGetEntityByIds(plan *RetrievePlan) (*segcorepb.Retrieve
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Segment) fillTargetEntry(plan *Plan,
|
||||
result *SearchResult) error {
|
||||
func (s *Segment) fillTargetEntry(plan *SearchPlan, result *SearchResult) error {
|
||||
if s.segmentPtr == nil {
|
||||
return errors.New("null seg core pointer")
|
||||
}
|
||||
|
||||
log.Debug("segment fill target entry, ", zap.Int64("segment ID = ", s.segmentID))
|
||||
var status = C.FillTargetEntry(s.segmentPtr, plan.cPlan, result.cQueryResult)
|
||||
var status = C.FillTargetEntry(s.segmentPtr, plan.cSearchPlan, result.cSearchResult)
|
||||
errorCode := status.error_code
|
||||
|
||||
if errorCode != 0 {
|
||||
|
|
|
@ -159,7 +159,7 @@ func TestSegment_retrieve(t *testing.T) {
|
|||
defer plan.delete()
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := segment.segmentGetEntityByIds(plan)
|
||||
res, err := segment.getEntityByIds(plan)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, res.Ids.GetIntId().Data, []int64{2, 3, 1})
|
||||
|
@ -426,7 +426,7 @@ func TestSegment_segmentSearch(t *testing.T) {
|
|||
}
|
||||
|
||||
travelTimestamp := Timestamp(1020)
|
||||
plan, err := createPlan(collection, dslString)
|
||||
plan, err := createSearchPlan(collection, dslString)
|
||||
assert.NoError(t, err)
|
||||
holder, err := parseSearchRequest(plan, placeHolderGroupBlob)
|
||||
assert.NoError(t, err)
|
||||
|
@ -436,7 +436,7 @@ func TestSegment_segmentSearch(t *testing.T) {
|
|||
searchResults := make([]*SearchResult, 0)
|
||||
matchedSegments := make([]*Segment, 0)
|
||||
|
||||
searchResult, err := segment.segmentSearch(plan, placeholderGroups, []Timestamp{travelTimestamp})
|
||||
searchResult, err := segment.search(plan, placeholderGroups, []Timestamp{travelTimestamp})
|
||||
assert.Nil(t, err)
|
||||
|
||||
searchResults = append(searchResults, searchResult)
|
||||
|
@ -449,7 +449,7 @@ func TestSegment_segmentSearch(t *testing.T) {
|
|||
assert.NoError(t, err2)
|
||||
err = fillTargetEntry(plan, searchResults, matchedSegments, inReduced)
|
||||
assert.NoError(t, err)
|
||||
marshaledHits, err := reorganizeQueryResults(plan, placeholderGroups, searchResults, numSegment, inReduced)
|
||||
marshaledHits, err := reorganizeSearchResults(plan, placeholderGroups, searchResults, numSegment, inReduced)
|
||||
assert.NoError(t, err)
|
||||
hitsBlob, err := marshaledHits.getHitsBlob()
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -65,7 +65,7 @@ func (s *streaming) search(searchReqs []*searchRequest,
|
|||
collID UniqueID,
|
||||
partIDs []UniqueID,
|
||||
vChannel Channel,
|
||||
plan *Plan,
|
||||
plan *SearchPlan,
|
||||
searchTs Timestamp) ([]*SearchResult, []*Segment, error) {
|
||||
|
||||
searchResults := make([]*SearchResult, 0)
|
||||
|
@ -173,7 +173,7 @@ func (s *streaming) search(searchReqs []*searchRequest,
|
|||
continue
|
||||
}
|
||||
|
||||
searchResult, err := seg.segmentSearch(plan, searchReqs, []Timestamp{searchTs})
|
||||
searchResult, err := seg.search(plan, searchReqs, []Timestamp{searchTs})
|
||||
if err != nil {
|
||||
return searchResults, segmentResults, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue