15 Commits
Author SHA1 Message Date
Tia Lim 0f0f728166 Format faiss Python files with black (line length 80) (#5349)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5349

# this is a no-op change

Ran `black -l 80` over all tracked Python files under `fbcode/faiss/`, using line length 80 to match faiss's documented coding style (`CONTRIBUTING.md`: "80 character line length (both for C++ and Python)"). 172 files were reformatted; 28 were already compliant.

This is a pure-formatting change. `black` runs its AST-equivalence safety check on every file, so no identifiers, string/numeric values, operators, or control flow were altered — only whitespace, indentation, line wrapping, blank lines, trailing commas, and string-quote normalization (single to double quotes).

`fbcode/faiss/` is intentionally excluded from Meta's standard Python autoformatter (`arc f` / `arc lint -a` report no formatter for these paths) because it mirrors to public GitHub, so the Python had drifted out of any consistent style. The C++ is already clang-format-clean (0 of 807 files change), so this effort is Python-only. This diff brings the Python to canonical `black` formatting.

Excluded `demos/index_pq_flat_separate_codes_from_codebook.py`: it contains a Jupyter `!rm` shell-magic line and is not valid Python, so `black` cannot parse it.

This is the base of a 3-diff stack: (1) this black reformat; (2) `.flake8` alignment (max-line-length 80 + black-compatible ignores E203/W503); (3) genuine lint fixes (F401/F403/F841/B011).

Reviewed By: mnorris11

Differential Revision: D109736099

fbshipit-source-id: 9a054635766ed11aa3760a788395babd3d198abf
2026-06-29 17:29:05 -07:00
Gergely Szilvasy f4338ade1b Parameterize existing tests with @for_all_simd_levels (#5134)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5134

Expand DD test coverage by applying for_all_simd_levels to existing test
classes that exercise DD-dispatched code paths but were previously pinned
to a single SIMD level.

This is the "mega decorator" diff from the DD test coverage gaps plan --
pure decorator additions, no new test logic. Follow-up diffs add new
test files and numerical cross-level assertions for gaps the decorator
alone cannot close.

Classes decorated (grouped by area):

* Binary Hamming non-IVF: TestRange and TestKnn in
  test_binary_hashindex.py; TestBinarySearchParams in
  test_binary_search_params.py; TestIndexBinaryFromFloat in
  test_index_binary_from_float.py; TestSpectralHash in
  test_index_accuracy.py.

* IVFPQ / search: EvalIVFPQAccuracy in test_index.py;
  TestSelector and TestSearchParams in test_search_params.py.

* Flat / refine / Panorama: TestIndexFlat, TestIndexFlatL2,
  TestIndexFlatL2Panorama, TestScalarQuantizer in test_index.py;
  TestDistanceComputer, TestIndexRefineSearchParams,
  TestIndexRefineRangeSearch in test_refine.py;
  TestIndexRefinePanorama, TestIndexFlatPanorama,
  TestIndexHNSWFlatPanorama, TestIndexIVFFlatPanorama in their
  respective files.

* Quantizer encode: TestResidualQuantizer,
  TestIndexResidualQuantizerSearch in test_residual_quantizer.py;
  TestComponents, TestLocalSearchQuantizer in
  test_local_search_quantizer.py.

* Fast scan: TestFastScanFiltering, TestBlockSkipConsistency,
  TestFastScanRangeSearchFilter in test_fastscan_filter.py.

* Broader index tests (search-exercising classes only):
  TestParameterSpace in test_autotune.py; TestSpectralHash in
  test_factory.py; TestMerge1, TestMerge2, TestRemoveFastScan in
  test_merge_index.py.

BUCK changes move decorated tests from the legacy-listing lists to the
simd_levels lists (which use supports_static_listing = False, required
for dynamic class name generation), and add the new entries
test_binary_search_params, test_fastscan_filter, test_refine_panorama,
test_hnsw_panorama.

___

overriding_review_checks_triggers_an_audit_and_retroactive_review
Oncall Short Name: fair_umami_cluster

Differential Revision: D101822335

fbshipit-source-id: 9a432c6d6bee201c3731713226405a8c8ecebbe6
2026-04-22 02:28:03 -07:00
Andrejs Krasilnikovs db5aef2253 Strengthen roundtrip tests by doing serialization after deserialization (#4851)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4851

Roundtrip tests only test serialize -> deserialize. They should also test the deserialize -> serialize sequence.

Reviewed By: mdouze

Differential Revision: D93678044

fbshipit-source-id: 1503b5b954d49df509d9f785d35911ade989290e
2026-03-02 16:30:12 -08:00
Subhadeep Karan 3a43e35292 Fix typos in tests and contrib directories (#4672)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4672

Fixed typos in test files and contrib utilities:

tests/:
- Fixed 20 typos across test files (C++ and Python)
- Fixed function/class name typos in Python tests:
  * test_result_order_miltihash → test_result_order_multihash
  * TestOrthognalReconstruct → TestOrthogonalReconstruct
  * test_recons_orthogona_impossible → test_recons_orthogonal_impossible
- Fixed comment typos and error messages in C++ tests

contrib/:
- Fixed 9 typos in Python contrib utilities
- Fixed string literal typos in client_server.py and rpc.py
- Fixed documentation typos in evaluation.py and big_batch_search.py

All changes maintain backward compatibility - no API changes.

Reviewed By: mnorris11

Differential Revision: D86571375

fbshipit-source-id: bd0edf7ca2e004f78e0ccba7f4aac7db6621781a
2025-11-12 11:39:51 -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 2d380e992b Add manifold check for size 0 (#1867)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1867

Merging code for the 1T photodna index seems to fail at

https://www.internalfb.com/phabricator/paste/view/P412975011?lines=174

with
```
terminate called after throwing an instance of 'facebook::manifold::blobstore::StorageException'
  what():  [400] Begin offset and/or length were invalid -- Begin offset must be positive and length must be non-negative. Received: offset = 2642410612, length = 0
Aborted (core dumped)
```
traces back to

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/fbcode/manifold/blobstore/BlobstoreThriftHandler.cpp?lines=671%2C700%2C732

There is a single case where we don't check if the read or write size is 0. So let's try this fix.

In the process I realized that the Manifold tests were non functional due to a name collision on common.py. Also fix this in all dependent files.

Differential Revision: D28231710

fbshipit-source-id: 700ffa6ca0c82c49e7d1eae9e76549ec5ff16332
2021-05-09 22:30:31 -07:00
Matthijs Douze 10c8583b2d Fix order of results for IndexBinaryHash and IndexBinaryMultiHash
Summary: The IndexBinaryHash and IndexBinaryMultiHash knn search functions returned results in a random order. This diff fixes that to the standard decreasing Hamming distance order + adds a test for that. I noticed on a notebook from sc268.

Reviewed By: sc268

Differential Revision: D26324795

fbshipit-source-id: 1444e26950e24bfac297f34f3d481d902d8ee769
2021-02-08 18:22:55 -08:00
Matthijs Douze a2791322d9 Update ProductQuantizer.cpp (#1634)
Summary:
Make error message more clear.
See https://github.com/facebookresearch/faiss/issues/1632

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

Reviewed By: beauby

Differential Revision: D25942961

Pulled By: mdouze

fbshipit-source-id: e96ca808a9a0dcd1de5417a5e048d39431b30a5e
2021-01-20 00:12:54 -08:00
Matthijs Douze 9b2384f305 Fix serialization of large hash indexes
Summary:
64-bit cleanness issue for BitstringWriter.
Shows in HashIndex I/O, see https://github.com/facebookresearch/faiss/issues/1532

Reviewed By: beauby

Differential Revision: D25804891

fbshipit-source-id: d4cd3714d116a1b2fe1c9446eb1e9d3a8acf854e
2021-01-11 05:48:12 -08:00
Matthijs Douze 3dd7ba8ff9 Add range search accuracy evaluation
Summary:
Added a few functions in contrib to:
- run range searches by batches on the query or the database side
- emulate range search on GPU: search on GPU with k=1024, if the farthest neighbor is still within range, re-perform search on CPU
- as reference implementations for precision-recall on range search datasets
- optimized code to plot precision-recall plots (ie. sweep over thresholds)

The new functions are mainly in a new `evaluation.py`

Reviewed By: wickedfoo

Differential Revision: D25627619

fbshipit-source-id: 58f90654c32c925557d7bbf8083efbb710712e03
2020-12-17 17:17:09 -08:00
Lucas Hosseini f3727a62f5 Remove python shebangs in tests.
Reviewed By: mdouze

Differential Revision: D23167048

fbshipit-source-id: 98196f489461bc922e6124e88e0bfb32dfe507ca
2020-08-17 11:46:26 -07:00
Lucas Hosseini ac74f576f7 fbshipit-source-id: 4f3cfa59471d548af93fe118d1b73d45bc648edf 2020-08-04 12:00:38 -07:00
Lucas Hosseini cd38e82f0c Facebook sync 2020-07-31 (#1308) 2020-08-03 22:15:02 +02:00
Lucas Hosseini a17a631dc3 Sync 20200323. (#1157)
* Sync 20200323.

* Bump version.

* Remove warning filter.
2020-03-24 14:06:48 +01:00