Reranking
Reranking is a technique widely adopted for improving recall of vector search. During searching, ANN algorithms usually
- shortlist a set of candidates based on an index and their quantization codes (e.g., in memory);
- retrieve the raw vectors (e.g., from disks) for those candidates which have the smallest estimated distances;
- computes the exact distances for the candidates to find the nearest neighbors.
RaBitQ has a unique advantage in reranking due to its theoretical error bound. It can skip reranking a candidate if the lower bound of its estimated distance is larger than the upper bound of the distance of the nearest neighbors.
Based on error bounds, it is possible to rerank fewer than K vectors to achieve nearly perfect recall - it only reranks the vectors on the boundaries of KNNs.
Algorithm Description
Let K be the number of nearest neighbors we target. After receiving the candidates and their estimated distances from an index, e.g., HNSW + RaBitQ, we perform the following strategy of reranking to minimize the number of retrieved raw vectors from disks.
- Sort the candidates with respect to their estimated distances.
- Initialize a max-heap (sorted by upper bounds of distances)
KNNs
with the top-K candidates which have the smallest estimated distances. - Enumerate the remaining candidates. For a new candidate A,
- [Condition 1 - A's lower bound > the maximum upper bound in
KNNs
.]- Drop the new candidate and move on.
- [Condition 2 - A's lower bound \le the maximum upper bound in
KNNs
, and the top candidate inKNNs
has been reranked.]- Rerank the new candidate, update
KNNs
and move on.
- Rerank the new candidate, update
- [Condition 3 - A's lower bound \le the maximum upper bound in
KNNs
, and the top candidate inKNNs
has NOT been reranked.]- Rerank the top candidate in
KNNs
, updateKNNs
and repeat the procedure for candidate A.
- Rerank the top candidate in
- [Condition 1 - A's lower bound > the maximum upper bound in