Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions faiss/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(FAISS_SRC
IndexIVFAdditiveQuantizerFastScan.cpp
IndexIVFPQFastScan.cpp
IndexIVFPQR.cpp
IndexIVFRaBitQ.cpp
IndexIVFSpectralHash.cpp
IndexLSH.cpp
IndexNNDescent.cpp
Expand All @@ -39,6 +40,7 @@ set(FAISS_SRC
IndexIVFIndependentQuantizer.cpp
IndexPQFastScan.cpp
IndexPreTransform.cpp
IndexRaBitQ.cpp
IndexRefine.cpp
IndexReplicas.cpp
IndexRowwiseMinMax.cpp
Expand All @@ -60,6 +62,7 @@ set(FAISS_SRC
impl/PolysemousTraining.cpp
impl/ProductQuantizer.cpp
impl/AdditiveQuantizer.cpp
impl/RaBitQuantizer.cpp
impl/ResidualQuantizer.cpp
impl/LocalSearchQuantizer.cpp
impl/ProductAdditiveQuantizer.cpp
Expand Down Expand Up @@ -123,6 +126,7 @@ set(FAISS_HEADERS
IndexIVFAdditiveQuantizerFastScan.h
IndexIVFPQFastScan.h
IndexIVFPQR.h
IndexIVFRaBitQ.h
IndexIVFSpectralHash.h
IndexLSH.h
IndexNeuralNetCodec.h
Expand All @@ -136,6 +140,7 @@ set(FAISS_HEADERS
IndexPreTransform.h
IndexRefine.h
IndexReplicas.h
IndexRaBitQ.h
IndexRowwiseMinMax.h
IndexScalarQuantizer.h
IndexShards.h
Expand Down Expand Up @@ -164,6 +169,7 @@ set(FAISS_HEADERS
impl/ProductQuantizer-inl.h
impl/ProductQuantizer.h
impl/Quantizer.h
impl/RaBitQuantizer.h
impl/ResidualQuantizer.h
impl/ResultHandler.h
impl/ScalarQuantizer.h
Expand Down
23 changes: 20 additions & 3 deletions faiss/IndexIVF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void IndexIVF::search_preassigned(
#pragma omp parallel if (do_parallel) reduction(+ : nlistv, ndis, nheap)
{
std::unique_ptr<InvertedListScanner> scanner(
get_InvertedListScanner(store_pairs, sel));
get_InvertedListScanner(store_pairs, sel, params));

/*****************************************************
* Depending on parallel_mode, there are two possible ways
Expand Down Expand Up @@ -796,7 +796,7 @@ void IndexIVF::range_search_preassigned(
{
RangeSearchPartialResult pres(result);
std::unique_ptr<InvertedListScanner> scanner(
get_InvertedListScanner(store_pairs, sel));
get_InvertedListScanner(store_pairs, sel, params));
FAISS_THROW_IF_NOT(scanner.get());
all_pres[omp_get_thread_num()] = &pres;

Expand Down Expand Up @@ -912,7 +912,8 @@ void IndexIVF::range_search_preassigned(

InvertedListScanner* IndexIVF::get_InvertedListScanner(
bool /*store_pairs*/,
const IDSelector* /* sel */) const {
const IDSelector* /* sel */,
const IVFSearchParameters* /* params */) const {
FAISS_THROW_MSG("get_InvertedListScanner not implemented");
}

Expand Down Expand Up @@ -1290,6 +1291,14 @@ size_t InvertedListScanner::scan_codes(

if (!keep_max) {
for (size_t j = 0; j < list_size; j++) {
if (sel != nullptr) {
int64_t id = store_pairs ? lo_build(list_no, j) : ids[j];
if (!sel->is_member(id)) {
codes += code_size;
continue;
}
}

float dis = distance_to_code(codes);
if (dis < simi[0]) {
int64_t id = store_pairs ? lo_build(list_no, j) : ids[j];
Expand All @@ -1300,6 +1309,14 @@ size_t InvertedListScanner::scan_codes(
}
} else {
for (size_t j = 0; j < list_size; j++) {
if (sel != nullptr) {
int64_t id = store_pairs ? lo_build(list_no, j) : ids[j];
if (!sel->is_member(id)) {
codes += code_size;
continue;
}
}

float dis = distance_to_code(codes);
if (dis > simi[0]) {
int64_t id = store_pairs ? lo_build(list_no, j) : ids[j];
Expand Down
7 changes: 5 additions & 2 deletions faiss/IndexIVF.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,14 @@ struct IndexIVF : Index, IndexIVFInterface {

/** Get a scanner for this index (store_pairs means ignore labels)
*
* The default search implementation uses this to compute the distances
* The default search implementation uses this to compute the distances.
* Use sel instead of params->sel, because sel is initialized with
* params->sel, but may get overriden by IndexIVF's internal logic.
*/
virtual InvertedListScanner* get_InvertedListScanner(
bool store_pairs = false,
const IDSelector* sel = nullptr) const;
const IDSelector* sel = nullptr,
const IVFSearchParameters* params = nullptr) const;

/** reconstruct a vector. Works only if maintain_direct_map is set to 1 or 2
*/
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ struct AQInvertedListScannerLUT : AQInvertedListScanner {

InvertedListScanner* IndexIVFAdditiveQuantizer::get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const {
const IDSelector* sel,
const IVFSearchParameters*) const {
FAISS_THROW_IF_NOT(!sel);
if (metric_type == METRIC_INNER_PRODUCT) {
if (aq->search_type == AdditiveQuantizer::ST_decompress) {
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFAdditiveQuantizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ struct IndexIVFAdditiveQuantizer : IndexIVF {

InvertedListScanner* get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const override;
const IDSelector* sel,
const IVFSearchParameters* params) const override;

void sa_decode(idx_t n, const uint8_t* codes, float* x) const override;

Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFFlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ InvertedListScanner* get_InvertedListScanner1(

InvertedListScanner* IndexIVFFlat::get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const {
const IDSelector* sel,
const IVFSearchParameters*) const {
if (sel) {
return get_InvertedListScanner1<true>(this, store_pairs, sel);
} else {
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFFlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct IndexIVFFlat : IndexIVF {

InvertedListScanner* get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const override;
const IDSelector* sel,
const IVFSearchParameters* params) const override;

void reconstruct_from_offset(int64_t list_no, int64_t offset, float* recons)
const override;
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFPQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,8 @@ InvertedListScanner* get_InvertedListScanner2(

InvertedListScanner* IndexIVFPQ::get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const {
const IDSelector* sel,
const IVFSearchParameters*) const {
if (sel) {
return get_InvertedListScanner2<true>(*this, store_pairs, sel);
} else {
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFPQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ struct IndexIVFPQ : IndexIVF {

InvertedListScanner* get_InvertedListScanner(
bool store_pairs,
const IDSelector* sel) const override;
const IDSelector* sel,
const IVFSearchParameters* params) const override;

/// build precomputed table
void precompute_table();
Expand Down
Loading
Loading