Skip to content

Commit

Permalink
more telemetry classes (#3854)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #3854

Laser can also write IndexIVFPQ and IndexIVFScalarQuantizer: https://www.internalfb.com/code/fbsource/[c3b602c11caed6275079645c45d1e9e89cc10690]/fbcode/fblearner/flow/projects/laser/laser_sim_search/knn_trainer.py?lines=407-422

Differential Revision: D62623242
  • Loading branch information
Michael Norris authored and facebook-github-bot committed Sep 13, 2024
1 parent 52ce3f5 commit 9c7e501
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 12 additions & 8 deletions faiss/impl/index_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ static void read_ProductLocalSearchQuantizer(
}
}

static void read_ScalarQuantizer(ScalarQuantizer* ivsc, IOReader* f) {
void read_ScalarQuantizer(ScalarQuantizer* ivsc, IOReader* f) {
READ1(ivsc->qtype);
READ1(ivsc->rangestat);
READ1(ivsc->rangestat_arg);
Expand Down Expand Up @@ -487,14 +487,14 @@ static ArrayInvertedLists* set_array_invlist(
return ail;
}

static IndexIVFPQ* read_ivfpq(IOReader* f, uint32_t h, int io_flags) {
IndexIVFPQ* read_ivfpq(
IOReader* f,
uint32_t h,
int io_flags,
IndexIVFPQR* ivfpqr,
IndexIVFPQ* ivpq) {
bool legacy = h == fourcc("IvQR") || h == fourcc("IvPQ");

IndexIVFPQR* ivfpqr = h == fourcc("IvQR") || h == fourcc("IwQR")
? new IndexIVFPQR()
: nullptr;
IndexIVFPQ* ivpq = ivfpqr ? ivfpqr : new IndexIVFPQ();

std::vector<std::vector<idx_t>> ids;
read_ivf_header(ivpq, f, legacy ? &ids : nullptr);
READ1(ivpq->by_residual);
Expand Down Expand Up @@ -876,7 +876,11 @@ Index* read_index(IOReader* f, int io_flags) {
} else if (
h == fourcc("IvPQ") || h == fourcc("IvQR") || h == fourcc("IwPQ") ||
h == fourcc("IwQR")) {
idx = read_ivfpq(f, h, io_flags);
IndexIVFPQR* ivfpqr = h == fourcc("IvQR") || h == fourcc("IwQR")
? new IndexIVFPQR()
: nullptr;
IndexIVFPQ* ivpq = ivfpqr ? ivfpqr : new IndexIVFPQ();
idx = read_ivfpq(f, h, io_flags, ivfpqr, ivpq);
} else if (h == fourcc("IwIQ")) {
auto* indep = new IndexIVFIndependentQuantizer();
indep->own_fields = true;
Expand Down
12 changes: 12 additions & 0 deletions faiss/index_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef FAISS_INDEX_IO_H
#define FAISS_INDEX_IO_H

#include <cstdint>
#include <cstdio>
#include <string>
#include <typeinfo>
Expand All @@ -32,6 +33,9 @@ struct ProductQuantizer;
struct IOReader;
struct IOWriter;
struct InvertedLists;
struct IndexIVFPQR;
struct IndexIVFPQ;
struct ScalarQuantizer;

/// skip the storage for graph-based indexes
const int IO_FLAG_SKIP_STORAGE = 1;
Expand Down Expand Up @@ -86,6 +90,14 @@ void write_ProductQuantizer(const ProductQuantizer* pq, IOWriter* f);
void write_InvertedLists(const InvertedLists* ils, IOWriter* f);
InvertedLists* read_InvertedLists(IOReader* reader, int io_flags = 0);

IndexIVFPQ* read_ivfpq(
IOReader* f,
uint32_t h,
int io_flags,
IndexIVFPQR* ivfpqr,
IndexIVFPQ* ivpq);
void read_ScalarQuantizer(ScalarQuantizer* ivsc, IOReader* f);

} // namespace faiss

#endif

0 comments on commit 9c7e501

Please sign in to comment.