This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use BF for HNSW and PQ+Refine for DiskANN when Filter Ratio is High (#…
…861) Signed-off-by: Patrick Weizhi Xu <[email protected]>
- Loading branch information
Showing
15 changed files
with
673 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (C) 2019-2023 Zilliz. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <optional> | ||
#include <queue> | ||
#include <utility> | ||
|
||
namespace knowhere { | ||
|
||
// Maintain intermediate top-k results via maxheap | ||
// TODO: this naive implementation might be optimzed later | ||
// 1. Based on top-k and pushed element count to swtich strategy | ||
// 2. Combine `pop` and `push` operation to `replace` | ||
template <typename DisT, typename IdT> | ||
class ResultMaxHeap { | ||
public: | ||
explicit ResultMaxHeap(size_t k) : k_(k) {} | ||
|
||
inline std::optional<std::pair<DisT, IdT>> | ||
Pop() { | ||
if (pq.empty()) { | ||
return std::nullopt; | ||
} | ||
std::optional<std::pair<DisT, IdT>> res = pq.top(); | ||
pq.pop(); | ||
return res; | ||
} | ||
|
||
inline void | ||
Push(DisT dis, IdT id) { | ||
if (pq.size() < k_) { | ||
pq.emplace(dis, id); | ||
return; | ||
} | ||
|
||
if (dis < pq.top().first) { | ||
pq.pop(); | ||
pq.emplace(dis, id); | ||
} | ||
} | ||
|
||
inline size_t | ||
Size() { | ||
return pq.size(); | ||
} | ||
|
||
private: | ||
size_t k_; | ||
std::priority_queue<std::pair<DisT, IdT>> pq; | ||
}; | ||
|
||
} // namespace knowhere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.