Commit 9579d8f
Add type stubs for SVS index classes + IndexIVFFlatPanorama.batch_size (#5489)
Summary:
Pull Request resolved: #5489
Fbcode/faiss/python/__init__.pyi is missing type stubs for 7 SWIG-exposed
SVS (Intel Scalable Vector Search) index classes and one field on
IndexIVFFlatPanorama, causing Pyre `[missing-attribute]` errors for any
Python caller that constructs or type-annotates these classes.
`swigfaiss.swig` `%include`s and `DOWNCAST`s `IndexSVSFlat`,
`IndexSVSVamana`, `IndexSVSVamanaLVQ`, `IndexSVSVamanaLeanVec`,
`IndexSVSIVF`, `IndexSVSIVFLVQ`, and `IndexSVSIVFLeanVec` (lines 763-769,
928-934) -- all 7 classes are live, constructible Python types today. None
of the 7 appear anywhere in `__init__.pyi`: 0 matches for each. Verified
against current trunk before implementing, not from a stale backlog
snapshot.
This diff adds:
- `SVSStorageKind = int` module-level type alias plus the 10 constant
values (`SVS_FP32`, `SVS_FP16`, `SVS_SQ8`, `SVS_LVQ4x0/4x4/4x8`,
`SVS_LVQ8x0`, `SVS_LeanVec4x4/4x8/8x8`, `SVS_count`), matching the
existing `MetricType = int` / `METRIC_L2: int` convention used for
every other plain (non-`enum class`) C++ enum in this file --
`SVSStorageKind` is declared as an unscoped `enum` in
`svs/IndexSVSVamana.h`, so SWIG exposes its values as bare top-level
names, not `SVSStorageKind_`-prefixed names (that prefix convention
only applies to C++11 `enum class` types, e.g. `ClusteringInitMethod`).
- `SearchParametersSVSVamana` and `SearchParametersSVSIVF` stubs
(`search_window_size`/`search_buffer_capacity`, `n_probes`/`k_reorder`
respectively), the two `SearchParameters` subclasses defined alongside
the SVS index headers that were equally unstubbed.
- `IndexSVSFlat`, `IndexSVSVamana` (+ `is_lvq_leanvec_enabled()` static
method), `IndexSVSVamanaLVQ`, `IndexSVSVamanaLeanVec` (+
`train_with_queries` support surfaced via the base `Index.train()`
Python wrapper, not a separate stub method -- see below),
`IndexSVSIVF` (+ `is_lvq_leanvec_enabled()`), `IndexSVSIVFLVQ`, and
`IndexSVSIVFLeanVec`, each with the constructor signature and public
config fields read directly from their C++ headers
(`svs/IndexSVS*.h`). Internal implementation-detail members
(`impl`, `mmap_owner`, `stored_vectors`, `stored_vectors_valid`,
`training_data` -- raw pointers into the unwrapped `svs_runtime::*`
library, or reconstruction-cache storage) are deliberately excluded,
matching this file's existing convention of omitting internal storage
fields even when technically public (e.g. `IndexIVFFlatPanorama.cum_sums`
is similarly excluded today).
- `IndexIVFFlatPanorama.batch_size: int` field and constructor parameter
(default `Panorama::kDefaultBatchSize` = 128, expressed as `= ...` per
this file's existing convention for non-literal defaults). The class
already had `n_levels` stubbed but was missing `batch_size`, added in
the same commit (D111132644-era) as the class itself.
Confirmed `train_with_queries` (a raw SWIG-exposed C++ method used
internally by `Index`'s Python `train()` wrapper for out-of-distribution
training data, per `class_wrappers.py`) does not need its own stub entry:
the same pattern already excludes `train_c`/`train_ex`, the other two raw
per-numeric-type dispatch targets of the same wrapper -- callers use
`index.train(x, xq_train=...)`, not the raw method name directly.
This is a stub-only change: `python/__init__.pyi` is consumed exclusively
by static type checkers (Pyre, mypy, pyright) and IDE autocompletion, not
by the Python runtime, so no behavior change is possible. Validated with
`python3 -c "import ast; ast.parse(open('python/__init__.pyi').read())"`
(0 syntax errors) and a full-file identifier-occurrence grep confirming
each new symbol appears exactly where intended with no accidental
duplicate class/constant definitions. `buck2 build fbcode//faiss:faiss`
and `fbcode//faiss/python:pyfaiss` both build clean (0 warnings, 0
errors); `buck2 test fbcode//faiss/tests:test_io` (Friday rotation
target) passes 30/30.
___
Differential Revision: D114349814
fbshipit-source-id: 4bfe5ad481438d1727247235240634a5a02a73b11 parent a3d59f0 commit 9579d8f
1 file changed
Lines changed: 126 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
| |||
277 | 291 | | |
278 | 292 | | |
279 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
280 | 304 | | |
281 | 305 | | |
282 | 306 | | |
| |||
1803 | 1827 | | |
1804 | 1828 | | |
1805 | 1829 | | |
| 1830 | + | |
1806 | 1831 | | |
1807 | 1832 | | |
1808 | 1833 | | |
| |||
1812 | 1837 | | |
1813 | 1838 | | |
1814 | 1839 | | |
| 1840 | + | |
1815 | 1841 | | |
1816 | 1842 | | |
1817 | 1843 | | |
| |||
3833 | 3859 | | |
3834 | 3860 | | |
3835 | 3861 | | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
| 3870 | + | |
| 3871 | + | |
| 3872 | + | |
| 3873 | + | |
| 3874 | + | |
| 3875 | + | |
| 3876 | + | |
| 3877 | + | |
| 3878 | + | |
| 3879 | + | |
| 3880 | + | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
| 3934 | + | |
| 3935 | + | |
| 3936 | + | |
| 3937 | + | |
| 3938 | + | |
| 3939 | + | |
| 3940 | + | |
| 3941 | + | |
| 3942 | + | |
| 3943 | + | |
| 3944 | + | |
| 3945 | + | |
| 3946 | + | |
| 3947 | + | |
| 3948 | + | |
| 3949 | + | |
| 3950 | + | |
| 3951 | + | |
| 3952 | + | |
| 3953 | + | |
| 3954 | + | |
| 3955 | + | |
| 3956 | + | |
| 3957 | + | |
| 3958 | + | |
| 3959 | + | |
| 3960 | + | |
| 3961 | + | |
3836 | 3962 | | |
3837 | 3963 | | |
3838 | 3964 | | |
| |||
0 commit comments