18 Commits
Author SHA1 Message Date
Max BuckleyandClaude Opus 4.6 b3a2914982 fix: resolve compiler warnings in test files (#4944)
Summary:
- Fix compiler warnings in all 20 FAISS C++ test files
- Fixes include `-Wshadow`, `-Wunused-parameter`, and signed/unsigned comparisons

All changes are mechanical. No functional changes.

Part 13/13 of the compiler warnings cleanup (split from https://github.com/facebookresearch/faiss/issues/4810 per maintainer request).

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4944

Test Plan:
- [x] No functional changes — all fixes are mechanical renames and annotations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

Reviewed By: mnorris11

Differential Revision: D96996609

Pulled By: alibeklfc

fbshipit-source-id: 72555246a4ccf540eb5422e64018c8d5e2660dce
2026-03-20 10:21:55 -07:00
Alibek Zhakubayev 933ebb7781 Add InvertedListScanner support for IndexIVFRaBitQFastScan (#4760)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4760

This enables IndexIVFRaBitQFastScan to work with the standard IVF search interface by implementing the InvertedListScanner pattern. The scanner follows the same design as IVFPQFastScanScanner - processing one query at a time with SIMD-optimized distance computation via pq4_accumulate_loop, while applying RaBitQ-specific distance corrections through the IVFRaBitQHeapHandler.

This is needed for compatibility with low-level IVF APIs that use scanners directly, and for use cases requiring fine-grained control over inverted list scanning.

Reviewed By: junjieqi, mdouze

Differential Revision: D90634862

fbshipit-source-id: 88f0fae73f03663eaca821734d9aea317e8ee49b
2026-01-22 17:47:45 -08:00
Michael Norris f58fd4c8ca Add InvertedListScanner for IVFPQFastScan (#4537)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4537

Description
-
Adds InvertedListScanner for IVFPQFastScan. Right now IVFPQFastScan does not support a Scanner because the codes are PQFS packed. This is required from Unicorn to simplify the integration layer.

We can implement a scanner based on the search_implem_10. We can't do distance_to_code but we can do the whole scan. (that is what is done in this diff in the new `IVFPQFastScanScanner.scan_codes`).

Summary of changes (v10)
-
- High level: there's 2 heaps at play during a `scan_codes` call. One is the uint16_t heap inside the HeapHandler, which tracks the best results for a given iteration of nprobe. The other tracks the results across iterations and is in float: heap_distances. At the end of each call, we find the best results from the current iteration (`curr_dists`) then `heap_addn` those to the output distances `distances`).
- Moved `make_knn_handler` to the IndexIVFFastScan.h declaration so it can be used outside just IndexIVFFastScan.cpp. It is moved out of the anonymous namespace in the .cpp file too.
- Add the IVFPQFastScanScanner to IndexIVFPQFastScan. This impl for scan_codes is directly translated from search_implem_10 in in IndexIVFPQFastScan, because both search_implem_10 and scan_codes process 1 query and 1 invlist at a time (technically, search_implem_10 processes `n` queries at a time, just not batched. search_implem_10 has a simple loop over `n`, so search_implem_10 can be factored out to 1 query for this Scanner easily.). The only changes are removal of extraneous stuff from search_implem_10.
- Changes to test_lowlevel_ivf.cpp to test this. Refactored the test because IVFPQFastScanScanner does not behave like other scanners.

v15 vs v16
-
v15 matches search_implem_10 exactly. The unit tests pass with bit-exact match. They were not passing before due to the biases and LUT not matching exactly to search_implem_10.

Problems:
1. It requires quantizer search. Otherwise the biases and LUT will not match search_implem_10. The LUT is built from several inverted lists.
2. It requires mutable state across scan_codes calls. I called them lut_counter and bias_counter.
(I think even though this matches results, these problems make this option a no-go. It is mostly here to show the investigation.)

v16 does not use quantizer search and has no mutable state.
- cq.dis == distance from query (xi) to centroid represented by list_no.
- cq.ids == list_no

Both are of length 1 since we just have 1 list which is set explicitly.
Then we can call compute_LUT as normal.

The LUTs and biases are completely different from an existing approach, so results will not match an existing approach.

Match percentage between search_implem_10 and various by_residual approaches (I called it `recall` in the test):
by_residual_IP: 0.9745
by_residual_L2: 0.936
Thus I set a baseline of 0.9 in the test.

Reference impl:
https://github.com/facebookresearch/faiss/blob/514b44fca8542bafe8640adcbf1cccce1900f74c/faiss/IndexIVFFastScan.cpp#L918-L992

ntotal vs number of blocks?
-
- index.bbs is often 32 https://github.com/facebookresearch/faiss/wiki/Fast-accumulation-of-PQ-and-AQ-codes-(FastScan)#implementation. This is the number of codes per block.

~~Why do we need this io_simd_dis and io_simd_ids?~~
-
Old, but keeping it struck out. This describes the uint16_t heap kept over multiple scans.

~~Other scanners can scan over multiple lists with `set_query` then `set_list`, then calling `scan_codes`. Why? Because they take the `float* distances`. The heap can operate on these floats to re-use values from last iteration.~~

~~IVFPQFastScan is different. Codes are pq4 packed. The HeapHandler has to get initialized with values from scanning the prior list.~~

~~If the user is only setting 1 list and 1 query for the lifetime of this scanner (which I believe is Unicorn's use case), it does not matter because there's no need to use prior results and the user can follow the test named IVFPQFS_null_params. But if the user wants to use like the other Scanners, they can follow the other 2 tests in test_lowlevel_ivf.cpp that pass the heap size.~~

Reviewed By: ddrcoder, mdouze

Differential Revision: D80114737

fbshipit-source-id: a28392d444bc4dbe5d12e0fd84884e691cf00cf0
2025-10-15 20:39:45 -07:00
generatedunixname89002005287564 d7b000b89d Fix CQS signal readability-braces-around-statements in fbcode/faiss/tests (#4457)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4457

Reviewed By: dtolnay

Differential Revision: D78958889

fbshipit-source-id: 328145208517bbafd733adc4d6bd5e7a302cb99a
2025-07-25 02:37:10 -07:00
Michelle Ma 11904f6981 Support decode_vectors (sa_decode but no decode_listnos) in multiple IVF index (#4400)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4400

Unicorn now uses faiss opaquely, and we need support for decode vectors without decoding listnos, since we used encode_vectors without encoding listno in the codes.

Add decode_vectors, the inverse of encode_vectors, that for now doesn't decode listnos at all (can be changed)

Reviewed By: luciang, mnorris11

Differential Revision: D76870386

fbshipit-source-id: 5a4315b104253b10871e9d7095bb2fbcfa5ca453
2025-07-08 11:44:28 -07:00
Nicholas Ormrod eb5e7341a6 facebook-unused-include-check in fbcode/faiss (#4029)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4029

Remove headers flagged by facebook-unused-include-check over fbcode.faiss.

+ format and autodeps

This is a codemod. It was automatically generated and will be landed once it is approved and tests are passing in sandcastle.
You have been added as a reviewer by Sentinel or Butterfly.

Autodiff project: uif
Autodiff partition: fbcode.faiss
Autodiff bookmark: ad.uif.fbcode.faiss

Reviewed By: dtolnay

Differential Revision: D65957849

fbshipit-source-id: f6199250db595defd56f5e7b2828f838702e9a16
2024-11-15 13:53:46 -08:00
Michael Norris eff0898a13 Enable linting: lint config changes plus arc lint command (#3966)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3966

This actually enables the linting.

Manual changes:
- tools/arcanist/lint/fbsource-licenselint-config.toml
- tools/arcanist/lint/fbsource-lint-engine.toml

Automated changes:
`arc lint --apply-patches --take LICENSELINT --paths-cmd 'hg files faiss'`

Reviewed By: asadoughi

Differential Revision: D64484165

fbshipit-source-id: 4f2f6e953c94ef6ebfea8a5ae035ccfbea65ed04
2024-10-22 09:46:48 -07:00
Xiao Fu 5e452ed52a Cleaning up more unnecessary print (#3455)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3455

Code quality control by reducing the number of prints

Reviewed By: junjieqi

Differential Revision: D57502194

fbshipit-source-id: a6cd65ed4cc49590ce73d2978d41b640b5259c17
2024-05-17 16:59:36 -07:00
Matthijs Douze a996a4a052 Put idx_t in the faiss namespace (#2582)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2582

A few more or less cosmetic improvements
* Index::idx_t was in the Index object, which does not make much sense, this diff moves it to faiss::idx_t
* replace multiprocessing.dummy with multiprocessing.pool
* add Alexandr as a core contributor of Faiss in the README ;-)

```
for i in $( find . -name \*.cu -o -name \*.cuh -o -name \*.h -o -name \*.cpp ) ; do
  sed -i s/Index::idx_t/idx_t/ $i
done
```

For the fbcode deps:
```
for i in $( fbgs Index::idx_t --exclude fbcode/faiss -l ) ; do
   sed -i s/Index::idx_t/idx_t/ $i
done
```

Reviewed By: algoriddle

Differential Revision: D41437507

fbshipit-source-id: 8300f2a3ae97cace6172f3f14a9be3a83999fb89
2022-11-30 08:25:30 -08:00
Alexandr Guzhva 438b64cd8b IVFPQ AVX2 optimization for PQ, including polysemous filtering (#2277)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2277

* extend a specialized AVX2 version for IVFPQScannerT::scan_list_with_table to cover  IVFPQScannerT::scan_list_polysemous_hc as well
* lower the comparison precision in test_lowlevel_ivf tests from EXPECT_EQ to EXPECT-FLOAT_EQ because of the AVX2 change in IVFPQScannerT::scan_list_polysemous_hc, otherwise tests fail

Reviewed By: mdouze

Differential Revision: D34964138

fbshipit-source-id: 1d304a8f6eda040fa4c626676b4d492f2c12f04f
2022-03-24 06:35:38 -07:00
Lucas Hosseini e86bf8cae1 Enable clang-format + autofix.
Summary: Format whole codebase with clang-format.

Reviewed By: mdouze

Differential Revision: D22891341

fbshipit-source-id: 673032b2444d61026d1e2c3fa2c5659f178cf58b
2021-02-25 04:46:10 -08:00
Lucas Hosseini c37e71456b Get rid of non-portable drand48. (#1349)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1349

Reviewed By: mdouze

Differential Revision: D23289393

Pulled By: beauby

fbshipit-source-id: a626bbf252ced4ae01abbc3dce4be50d9e628728
2020-08-24 00:42:21 -07:00
Lucas Hosseini a97ebeeabd Fix format specifiers for size_t/idx_t. (#1338)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1338

Test Plan: Imported from OSS

Reviewed By: mdouze

Differential Revision: D23234964

Pulled By: beauby

fbshipit-source-id: 2222d90d8ca3f9a6ac3a9e624e7ec87072da3a25
2020-08-20 10:45:27 -07:00
Lucas Hosseini 36ddba9196 Facebook sync (2019-09-10) (#943)
* Facebook sync (2019-09-10)

* Fix depends Makefile target.

* Add faiss symlink for new include directives.

* Fix missing header.

* Fix tests.

* Fix Makefile.

* Update depend.

* Fix include directives spacing.
2019-09-20 18:59:10 +02:00
Lucas Hosseini a8118acbc5 Facebook sync (May 2019) + relicense (#838)
Changelog:

- changed license: BSD+Patents -> MIT
- propagates exceptions raised in sub-indexes of IndexShards and IndexReplicas
- support for searching several inverted lists in parallel (parallel_mode != 0)
- better support for PQ codes where nbit != 8 or 16
- IVFSpectralHash implementation: spectral hash codes inside an IVF
- 6-bit per component scalar quantizer (4 and 8 bit were already supported)
- combinations of inverted lists: HStackInvertedLists and VStackInvertedLists
- configurable number of threads for OnDiskInvertedLists prefetching (including 0=no prefetch)
- more test and demo code compatible with Python 3 (print with parentheses)
- refactored benchmark code: data loading is now in a single file
2019-05-28 16:17:22 +02:00
Lucas Hosseini f417a53628 Fix CI tests (#687)
* Fix test_transfer_invlists.cpp

* Fix relative imports.

* Fix test_index_accuracy.py.

* Use default OSX version.

* Allow osx gcc6 build to fail.
2019-01-08 17:52:36 +01:00
matthijs daf589d9d2 add bench_all_ivf 2018-12-20 05:43:36 -08:00
Lucas Hosseini 323dbf3be3 Facebook sync (Dec 2018). (#660)
* Add GpuIndexBinaryFlat
* Add IndexBinaryHNSW
2018-12-19 17:48:35 +01:00