fix retrieve bug (#5727)

Signed-off-by: fluorinedog <fluorinedog@gmail.com>
pull/5728/head^2
FluorineDog 2021-06-11 00:06:55 +08:00 committed by GitHub
parent faf5752096
commit 006dae35c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#include <memory>
#include <vector>
#include <string>
#include <utility>
namespace milvus::segcore {
@ -25,6 +26,8 @@ class ScalarIndexBase {
virtual std::pair<std::unique_ptr<IdArray>, std::vector<SegOffset>>
do_search_ids(const IdArray& ids) const = 0;
virtual ~ScalarIndexBase() = default;
virtual std::string
debug() const = 0;
};
class ScalarIndexVector : public ScalarIndexBase {
@ -41,6 +44,15 @@ class ScalarIndexVector : public ScalarIndexBase {
std::pair<std::unique_ptr<IdArray>, std::vector<SegOffset>>
do_search_ids(const IdArray& ids) const override;
std::string
debug() const override {
std::string dbg_str;
for (auto pr : mapping_) {
dbg_str += "<" + std::to_string(pr.first) + "->" + std::to_string(pr.second.get()) + ">";
}
return dbg_str;
}
private:
std::vector<std::pair<T, SegOffset>> mapping_;
};

View File

@ -20,6 +20,7 @@
#include <knowhere/index/vector_index/VecIndexFactory.h>
#include <faiss/utils/distances.h>
#include <query/SearchOnSealed.h>
#include <iostream>
#include "query/generated/ExecPlanNodeVisitor.h"
#include "segcore/SegmentGrowingImpl.h"
#include "query/PlanNode.h"
@ -486,4 +487,9 @@ SegmentGrowingImpl::search_ids(const IdArray& id_array, Timestamp timestamp) con
return {std::move(res_id_arr), std::move(res_offsets)};
}
std::string
SegmentGrowingImpl::debug() const {
return "Growing\n";
}
} // namespace milvus::segcore

View File

@ -31,6 +31,7 @@
#include "InsertRecord.h"
#include <utility>
#include <memory>
#include <string>
#include <vector>
namespace milvus::segcore {
@ -69,6 +70,9 @@ class SegmentGrowingImpl : public SegmentGrowing {
int64_t
GetMemoryUsageInBytes() const override;
std::string
debug() const override;
public:
const InsertRecord&
get_insert_record() const {

View File

@ -197,6 +197,13 @@ SegmentInternalInterface::GetEntityById(const std::vector<FieldOffset>& field_of
auto results = std::make_unique<proto::plan::RetrieveResults>();
auto [ids_, seg_offsets] = search_ids(id_array, timestamp);
// std::string dbg_log;
// dbg_log += "id_array:" + id_array.DebugString() + "\n";
// dbg_log += "ids:" + ids_->DebugString() + "\n";
// dbg_log += "segment_info:" + this->debug();
// std::cout << dbg_log << std::endl;
results->set_allocated_ids(ids_.release());
auto fields_data = results->mutable_fields_data();

View File

@ -22,6 +22,7 @@
#include <memory>
#include <vector>
#include <utility>
#include <string>
namespace milvus::segcore {
@ -93,6 +94,9 @@ class SegmentInternalInterface : public SegmentInterface {
const IdArray& id_array,
Timestamp timestamp) const override;
virtual std::string
debug() const = 0;
public:
virtual void
vector_search(int64_t vec_count,

View File

@ -74,14 +74,23 @@ SegmentSealedImpl::LoadFieldData(const LoadFieldDataInfo& info) {
// prepare data
aligned_vector<idx_t> vec_data(info.row_count);
std::copy_n(src_ptr, info.row_count, vec_data.data());
auto pk_index = create_index(vec_data.data(), vec_data.size());
std::unique_ptr<ScalarIndexBase> pk_index_;
// fix unintentional index update
if (schema_->get_is_auto_id()) {
pk_index_ = create_index(vec_data.data(), vec_data.size());
}
// write data under lock
std::unique_lock lck(mutex_);
update_row_count(info.row_count);
AssertInfo(row_ids_.empty(), "already exists");
row_ids_ = std::move(vec_data);
primary_key_index_ = std::move(pk_index);
if (schema_->get_is_auto_id()) {
primary_key_index_ = std::move(pk_index_);
}
++system_ready_count_;
} else {
// prepare data
@ -118,6 +127,7 @@ SegmentSealedImpl::LoadFieldData(const LoadFieldDataInfo& info) {
field_datas_[field_offset.get()] = std::move(vec_data);
scalar_indexings_[field_offset.get()] = std::move(index);
}
if (schema_->get_primary_key_offset() == field_offset) {
primary_key_index_ = std::move(pk_index_);
}
@ -410,6 +420,15 @@ SegmentSealedImpl::search_ids(const IdArray& id_array, Timestamp timestamp) cons
return primary_key_index_->do_search_ids(id_array);
}
std::string
SegmentSealedImpl::debug() const {
std::string log_str;
log_str += "Sealed\n";
log_str += "Index:" + primary_key_index_->debug();
log_str += "\n";
return log_str;
}
SegmentSealedPtr
CreateSealedSegment(SchemaPtr schema) {
return std::make_unique<SegmentSealedImpl>(schema);

View File

@ -17,6 +17,7 @@
#include <vector>
#include <memory>
#include <utility>
#include <string>
namespace milvus::segcore {
class SegmentSealedImpl : public SegmentSealed {
@ -57,6 +58,9 @@ class SegmentSealedImpl : public SegmentSealed {
int64_t
size_per_chunk() const override;
std::string
debug() const override;
protected:
// blob and row_count
SpanBase

View File

@ -22,6 +22,7 @@
#include <knowhere/index/vector_index/adapter/VectorAdapter.h>
#include "common/Types.h"
#include "common/CGoHelper.h"
#include <iostream>
////////////////////////////// common interfaces //////////////////////////////
CSegmentInterface