feat(index): add IVF+PQ compression flag for the FAISS build - #155
Open
dex0shubham wants to merge 1 commit into
Open
feat(index): add IVF+PQ compression flag for the FAISS build#155dex0shubham wants to merge 1 commit into
dex0shubham wants to merge 1 commit into
Conversation
|
@dex0shubham is attempting to deploy a commit to the andylizf's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #153.
Motivation
The FAISS backend uses
IndexIVFFlat, storing every vector at full float32precision — ~245 GB of RAM for a 30 M-vector corpus at dim 2048. That's out of
reach for air-gapped or Docker-free deployments that can't run a Qdrant sidecar,
even though Qdrant users can already compress via
--qdrant-quantization-config.This adds the equivalent knob on the FAISS side.
Change
Opt-in
--pq-m/--pq-nbitsflags selectIndexIVFPQ(Product Quantization)instead of
IndexIVFFlat. Atpq_m=64, nbits=8each vector shrinks from 8192to 64 bytes (~128x, ~1.9 GB for 30 M vectors) for a typical small recall cost.
embed/src/pixelrag_embed/index.py—build_ivftakespq_m(default 0 =unchanged IVFFlat) and
pq_nbits(4 or 8). Whenpq_m > 0it buildsIndexIVFPQ; the existing.train()call trains the PQ codebooks too, so nonew training path.
summary.jsonrecordsindex_type/pq_m/pq_nbitsso the served index is self-describing.
index/src/pixelrag_index/pipelines.py— forwardsindex.pq_m/index.pq_nbitsfrompixelrag.yamlto the build command.One fix vs. the proposal
The issue's sketch was
faiss.IndexIVFPQ(quantizer, dim, nlist, pq_m, pq_nbits),which defaults to
METRIC_L2— wrong for the IP-normalized embeddings thisindex uses, and a silent ranking regression. This PR passes
metric_typeexplicitly and a test locks it in.
Validation:
pq_mmust divide the embedding dim evenly, else a clearValueError(FAISS would otherwise assert deep in C++).Tests
tests/test_ivfpq_index.py(plainpytest,faissviaimportorskip, no model— builds a real index from a synthetic shard):
ntotal == n, is searchable, and itsmetric_typeis inner product (guards the L2-default bug).summary.jsonrecordsindex_type="ivfpq"and the PQ params.pq_mnot dividing the dim raisesValueError.pq_m=0(default) still produces anIndexIVFFlat— no behavior change.All pass;
ruff check/ruff format --checkclean.