Skip to content

Commit

Permalink
set keep_max for InvertedListScanner child classes (facebookresearch#…
Browse files Browse the repository at this point in the history
…3169)

Summary:
Pull Request resolved: facebookresearch#3169

InvertedListScanner.keep_max is used in iterate_codes method, this field is not set to true when metric is IP, causing problems when using InvertedListsIterator interface.

Reviewed By: algoriddle

Differential Revision: D52006595

fbshipit-source-id: 6adbe377c0b9f198c9fd8704869133407ef845e5
  • Loading branch information
bladepan authored and facebook-github-bot committed Dec 11, 2023
1 parent 9f8f238 commit 79f558f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion faiss/IndexIVFFlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ struct IVFFlatScanner : InvertedListScanner {
size_t d;

IVFFlatScanner(size_t d, bool store_pairs, const IDSelector* sel)
: InvertedListScanner(store_pairs, sel), d(d) {}
: InvertedListScanner(store_pairs, sel), d(d) {
keep_max = is_similarity_metric(metric);
}

const float* xi;
void set_query(const float* query) override {
Expand Down
1 change: 1 addition & 0 deletions faiss/IndexIVFPQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ struct IVFPQScanner : IVFPQScannerT<idx_t, METRIC_TYPE, PQDecoder>,
precompute_mode(precompute_mode),
sel(sel) {
this->store_pairs = store_pairs;
this->keep_max = is_similarity_metric(METRIC_TYPE);
}

void set_query(const float* query) override {
Expand Down
1 change: 1 addition & 0 deletions faiss/IndexIVFSpectralHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ struct IVFScanner : InvertedListScanner {
hc(qcode.data(), index->code_size) {
this->store_pairs = store_pairs;
this->code_size = index->code_size;
this->keep_max = is_similarity_metric(index->metric_type);
}

void set_query(const float* query) override {
Expand Down
1 change: 1 addition & 0 deletions faiss/impl/ScalarQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ struct IVFSQScannerIP : InvertedListScanner {
this->store_pairs = store_pairs;
this->sel = sel;
this->code_size = code_size;
this->keep_max = true;
}

void set_query(const float* query) override {
Expand Down

0 comments on commit 79f558f

Please sign in to comment.