Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit fbf2b6e

Browse files
authored
Update GetVectorByIds interface (#868)
Signed-off-by: Yudong Cai <[email protected]>
1 parent a77607d commit fbf2b6e

File tree

13 files changed

+21
-35
lines changed

13 files changed

+21
-35
lines changed

include/knowhere/index.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,8 @@ class Index {
204204
}
205205

206206
expected<DataSetPtr, Status>
207-
GetVectorByIds(const DataSet& dataset, const Json& json) const {
208-
Json json_(json);
209-
auto cfg = this->node->CreateConfig();
210-
{
211-
auto res = Config::FormatAndCheck(*cfg, json_);
212-
LOG_KNOWHERE_DEBUG_ << "GetVectorByIds config dump: " << json_.dump();
213-
if (res != Status::success) {
214-
return unexpected(res);
215-
}
216-
}
217-
auto res = Config::Load(*cfg, json_, knowhere::SEARCH);
218-
if (res != Status::success) {
219-
return unexpected(res);
220-
}
221-
return this->node->GetVectorByIds(dataset, *cfg);
207+
GetVectorByIds(const DataSet& dataset) const {
208+
return this->node->GetVectorByIds(dataset);
222209
}
223210

224211
bool

include/knowhere/index_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class IndexNode : public Object {
3939
RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const = 0;
4040

4141
virtual expected<DataSetPtr, Status>
42-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const = 0;
42+
GetVectorByIds(const DataSet& dataset) const = 0;
4343

4444
virtual bool
4545
HasRawData(const std::string& metric_type) const = 0;

include/knowhere/index_node_thread_pool_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class IndexNodeThreadPoolWrapper : public IndexNode {
5353
}
5454

5555
expected<DataSetPtr, Status>
56-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const {
57-
return index_node_->GetVectorByIds(dataset, cfg);
56+
GetVectorByIds(const DataSet& dataset) const {
57+
return index_node_->GetVectorByIds(dataset);
5858
}
5959

6060
bool

python/knowhere/knowhere.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class IndexWrap {
141141
}
142142

143143
knowhere::DataSetPtr
144-
GetVectorByIds(knowhere::DataSetPtr dataset, const std::string& json, knowhere::Status& status) {
145-
auto res = idx.GetVectorByIds(*dataset, knowhere::Json::parse(json));
144+
GetVectorByIds(knowhere::DataSetPtr dataset, knowhere::Status& status) {
145+
auto res = idx.GetVectorByIds(*dataset);
146146
if (res.has_value()) {
147147
status = knowhere::Status::success;
148148
return res.value();

src/index/diskann/diskann.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DiskANNIndexNode : public IndexNode {
6161
RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override;
6262

6363
expected<DataSetPtr, Status>
64-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override;
64+
GetVectorByIds(const DataSet& dataset) const override;
6565

6666
bool
6767
HasRawData(const std::string& metric_type) const override {
@@ -625,10 +625,7 @@ DiskANNIndexNode<T>::RangeSearch(const DataSet& dataset, const Config& cfg, cons
625625

626626
template <typename T>
627627
expected<DataSetPtr, Status>
628-
DiskANNIndexNode<T>::GetVectorByIds(const DataSet& dataset, const Config& cfg) const {
629-
if (!is_prepared_.load()) {
630-
const_cast<DiskANNIndexNode<T>*>(this)->Prepare(cfg);
631-
}
628+
DiskANNIndexNode<T>::GetVectorByIds(const DataSet& dataset) const {
632629
if (!is_prepared_.load() || !pq_flash_index_) {
633630
LOG_KNOWHERE_ERROR_ << "Failed to load diskann.";
634631
return unexpected(Status::empty_index);

src/index/flat/flat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class FlatIndexNode : public IndexNode {
201201
}
202202

203203
expected<DataSetPtr, Status>
204-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override {
204+
GetVectorByIds(const DataSet& dataset) const override {
205205
auto dim = Dim();
206206
auto rows = dataset.GetRows();
207207
auto ids = dataset.GetIds();

src/index/gpu/flat_gpu/flat_gpu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class GpuFlatIndexNode : public IndexNode {
9595
}
9696

9797
virtual expected<DataSetPtr, Status>
98-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override {
98+
GetVectorByIds(const DataSet& dataset) const override {
9999
DataSetPtr results = std::make_shared<DataSet>();
100100
auto nq = dataset.GetRows();
101101
auto dim = dataset.GetDim();

src/index/gpu/ivf_gpu/ivf_gpu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class GpuIvfIndexNode : public IndexNode {
170170
}
171171

172172
virtual expected<DataSetPtr, Status>
173-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override {
173+
GetVectorByIds(const DataSet& dataset) const override {
174174
return unexpected(Status::not_implemented);
175175
}
176176

src/index/hnsw/hnsw.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class HnswIndexNode : public IndexNode {
251251
}
252252

253253
expected<DataSetPtr, Status>
254-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override {
254+
GetVectorByIds(const DataSet& dataset) const override {
255255
if (!index_) {
256256
return unexpected(Status::empty_index);
257257
}

src/index/ivf/ivf.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class IvfIndexNode : public IndexNode {
6161
expected<DataSetPtr, Status>
6262
RangeSearch(const DataSet& dataset, const Config& cfg, const BitsetView& bitset) const override;
6363
expected<DataSetPtr, Status>
64-
GetVectorByIds(const DataSet& dataset, const Config& cfg) const override;
64+
GetVectorByIds(const DataSet& dataset) const override;
6565
bool
6666
HasRawData(const std::string& metric_type) const override {
6767
if constexpr (std::is_same<faiss::IndexIVFFlat, T>::value) {
@@ -525,7 +525,7 @@ IvfIndexNode<T>::RangeSearch(const DataSet& dataset, const Config& cfg, const Bi
525525

526526
template <typename T>
527527
expected<DataSetPtr, Status>
528-
IvfIndexNode<T>::GetVectorByIds(const DataSet& dataset, const Config& cfg) const {
528+
IvfIndexNode<T>::GetVectorByIds(const DataSet& dataset) const {
529529
if (!this->index_) {
530530
return unexpected(Status::empty_index);
531531
}

0 commit comments

Comments
 (0)