Skip to content

Commit 7e04fa2

Browse files
mdouzemeta-codesync[bot]
authored andcommitted
Update Python type stubs (__init__.pyi) to match current API (facebookresearch#4998)
Summary: Pull Request resolved: facebookresearch#4998 🤖 This diff was automatically generated by myclaw_faiss_monitor Updates the PEP 561 type stubs for the faiss Python package to reflect API changes since the initial stubs were added in D94139717. Changes: - Fix wrong RaBitQ constructor signatures (IndexRaBitQ, IndexIVFRaBitQ) to match actual C++ constructors (removed nonexistent M, nbit, trained params, renamed attribute from rq to rabitq) - Add missing Panorama index classes: IndexFlatPanorama, IndexFlatL2Panorama, IndexFlatIPPanorama, IndexHNSWFlatPanorama, IndexIVFFlatPanorama, IndexRefinePanorama - Add RaBitQ FastScan classes: IndexRaBitQFastScan, IndexIVFRaBitQFastScan - Add RaBitQ search parameter classes: RaBitQSearchParameters, IVFRaBitQSearchParameters - Add HadamardRotation VectorTransform - Add IndexQINCo class, fix IndexNeuralNetCodec constructor signature - Fix IndexRandom constructor (add missing ntotal, metric params) - Add new ClusteringParameters fields (init_method, afkmc2_chain_length, early_stop_threshold) - Add deserialization safety functions (get/set_deserialization_loop_limit, get/set_deserialization_vector_byte_limit) Reviewed By: mnorris11 Differential Revision: D98439353 fbshipit-source-id: c6b8908d85bb3edaae30613e7e89074034678a7b
1 parent 18c85e1 commit 7e04fa2

File tree

1 file changed

+173
-15
lines changed

1 file changed

+173
-15
lines changed

faiss/python/__init__.pyi

Lines changed: 173 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ class RandomRotationMatrix(LinearTransform):
492492
def __init__(self, d_in: int, d_out: int) -> None: ...
493493
def init(self, seed: int) -> None: ...
494494

495+
class HadamardRotation(VectorTransform):
496+
"""Three rounds of random sign-flip + Fast Walsh-Hadamard Transform.
497+
Produces a pseudo-random rotation in O(d log d) time.
498+
d_out is the smallest power of 2 >= d_in (zero-padded as needed).
499+
"""
500+
501+
seed: int
502+
503+
def __init__(self, d: int, seed: int = 12345) -> None: ...
504+
def init(self, seed: int) -> None: ...
505+
495506
class PCAMatrix(LinearTransform):
496507
eigen_power: float
497508
epsilon: float
@@ -638,6 +649,31 @@ class IndexFlat1D(IndexFlatL2):
638649
def update_permutation(self) -> None: ...
639650
def reset(self) -> None: ...
640651

652+
class IndexFlatPanorama(IndexFlat):
653+
"""Panorama implementation of IndexFlat following https://arxiv.org/abs/2510.00566"""
654+
655+
batch_size: int
656+
n_levels: int
657+
658+
def __init__(
659+
self,
660+
d: int,
661+
metric: MetricType,
662+
n_levels: int,
663+
batch_size: int,
664+
) -> None: ...
665+
def permute_entries(self, perm: npt.NDArray[np.int64]) -> None: ...
666+
667+
class IndexFlatL2Panorama(IndexFlatPanorama):
668+
def __init__(
669+
self, d: int, n_levels: int, batch_size: int = 512
670+
) -> None: ...
671+
672+
class IndexFlatIPPanorama(IndexFlatPanorama):
673+
def __init__(
674+
self, d: int, n_levels: int, batch_size: int = 512
675+
) -> None: ...
676+
641677
class IndexPreTransform(Index):
642678
chain: list[VectorTransform] # std::vector<VectorTransform*> chain
643679
index: Index
@@ -1617,6 +1653,21 @@ class IndexIVFFlat(IndexIVF):
16171653
self, quantizer: Index, d: int, nlist: int, metric: MetricType = METRIC_L2
16181654
) -> None: ...
16191655

1656+
class IndexIVFFlatPanorama(IndexIVFFlat):
1657+
"""Panorama adaptation of IndexIVFFlat following https://arxiv.org/abs/2510.00566"""
1658+
1659+
n_levels: int
1660+
1661+
def __init__(
1662+
self,
1663+
quantizer: Index,
1664+
d: int,
1665+
nlist: int,
1666+
n_levels: int,
1667+
metric: MetricType = METRIC_L2,
1668+
own_invlists: bool = True,
1669+
) -> None: ...
1670+
16201671
class IndexIVFPQ(IndexIVF):
16211672
pq: ProductQuantizer
16221673
code_size: int
@@ -1744,6 +1795,21 @@ class IndexHNSW(Index):
17441795
class IndexHNSWFlat(IndexHNSW):
17451796
def __init__(self, d: int, M: int, metric: MetricType = METRIC_L2) -> None: ...
17461797

1798+
class IndexHNSWFlatPanorama(IndexHNSWFlat):
1799+
"""Panorama implementation of IndexHNSWFlat.
1800+
Uses progressive distance refinement to prune candidates early.
1801+
"""
1802+
1803+
num_panorama_levels: int
1804+
1805+
def __init__(
1806+
self,
1807+
d: int,
1808+
M: int,
1809+
num_panorama_levels: int,
1810+
metric: MetricType = METRIC_L2,
1811+
) -> None: ...
1812+
17471813
class IndexHNSWPQ(IndexHNSW):
17481814
pq: ProductQuantizer
17491815

@@ -1997,6 +2063,15 @@ class IndexRefineFlat(IndexRefine):
19972063
self, base_index: Index | None = None, xb: npt.NDArray[np.float32] | None = None
19982064
) -> None: ...
19992065

2066+
class IndexRefinePanorama(IndexRefine):
2067+
"""Version where the search calls search_subset, allowing for Panorama refinement."""
2068+
2069+
def __init__(
2070+
self,
2071+
base_index: Index | None = None,
2072+
refine_index: Index | None = None,
2073+
) -> None: ...
2074+
20002075
# FastScan base class
20012076
class IndexFastScan(Index):
20022077
M: int
@@ -2088,6 +2163,12 @@ def read_VectorTransform(fname: str) -> VectorTransform: ...
20882163
def write_InvertedLists(invlists: InvertedLists, writer: IOWriter) -> None: ...
20892164
def read_InvertedLists(reader: IOReader, io_flags: int = 0) -> InvertedLists: ...
20902165

2166+
# Deserialization safety limits
2167+
def get_deserialization_loop_limit() -> int: ...
2168+
def set_deserialization_loop_limit(value: int) -> None: ...
2169+
def get_deserialization_vector_byte_limit() -> int: ...
2170+
def set_deserialization_vector_byte_limit(value: int) -> None: ...
2171+
20912172
# Search with parameters functions
20922173
@overload
20932174
def search_with_parameters(
@@ -2278,6 +2359,9 @@ class ClusteringParameters:
22782359
decode_block_size: int
22792360
check_input_data_for_NaNs: bool
22802361
use_faster_subsampling: bool
2362+
init_method: int # ClusteringInitMethod enum (RANDOM=0, KMEANS_PLUS_PLUS=1, AFK_MC2=2)
2363+
afkmc2_chain_length: int # chain length for AFK-MC² initialization
2364+
early_stop_threshold: float # early stop threshold [0, 1]
22812365

22822366
def __init__(self) -> None: ...
22832367

@@ -3063,9 +3147,15 @@ class IndexRowwiseMinMaxFP16(Index):
30633147

30643148
# IndexRandom for testing
30653149
class IndexRandom(Index):
3066-
d: int
3150+
seed: int
30673151

3068-
def __init__(self, d: int, seed: int = 1234) -> None: ...
3152+
def __init__(
3153+
self,
3154+
d: int,
3155+
ntotal: int = 0,
3156+
seed: int = 1234,
3157+
metric: MetricType = METRIC_L2,
3158+
) -> None: ...
30693159

30703160
# IndexShards and IndexReplicas (already templated in SWIG)
30713161
class IndexShardsIVF(Index):
@@ -3269,39 +3359,107 @@ class LocalSearchCoarseQuantizer(Index):
32693359

32703360
# NeuralNet index
32713361
class IndexNeuralNetCodec(Index):
3272-
d: int
3362+
M: int
3363+
nbits: int
3364+
3365+
def __init__(
3366+
self,
3367+
d: int = 0,
3368+
M: int = 0,
3369+
nbits: int = 0,
3370+
metric: MetricType = METRIC_L2,
3371+
) -> None: ...
32733372

3274-
def __init__(self, d: int, filename: str) -> None: ...
3373+
class IndexQINCo(IndexNeuralNetCodec):
3374+
def __init__(
3375+
self,
3376+
d: int,
3377+
M: int,
3378+
nbits: int,
3379+
L: int,
3380+
h: int,
3381+
metric: MetricType = METRIC_L2,
3382+
) -> None: ...
32753383

32763384
# RaBitQ indices
3385+
class RaBitQSearchParameters(SearchParameters):
3386+
qb: int # number of bits to quantize a query with (0 = raw fp32)
3387+
centered: bool # quantize with zero-centered scalar quantizer
3388+
3389+
def __init__(self) -> None: ...
3390+
32773391
class IndexRaBitQ(Index):
3278-
rq: RaBitQuantizer
3279-
codes: UInt8Vector
3392+
rabitq: RaBitQuantizer
3393+
center: Float32Vector
3394+
qb: int # default number of bits to quantize a query with
3395+
centered: bool
32803396

32813397
def __init__(
32823398
self,
32833399
d: int,
3284-
M: int,
3285-
nbit: int = 1,
32863400
metric: MetricType = METRIC_L2,
3287-
trained: bool = True,
3401+
nb_bits: int = 1,
32883402
) -> None: ...
32893403

3404+
class IVFRaBitQSearchParameters(IVFSearchParameters):
3405+
qb: int
3406+
centered: bool
3407+
3408+
def __init__(self) -> None: ...
3409+
32903410
class IndexIVFRaBitQ(IndexIVF):
3291-
rq: RaBitQuantizer
3292-
code_size: int
3293-
by_residual: bool
3411+
rabitq: RaBitQuantizer
3412+
qb: int
32943413

32953414
def __init__(
32963415
self,
32973416
quantizer: Index,
32983417
d: int,
32993418
nlist: int,
3300-
M: int,
3301-
nbit: int = 1,
33023419
metric: MetricType = METRIC_L2,
3303-
encode_residual: bool = True,
3420+
own_invlists: bool = True,
3421+
nb_bits: int = 1,
3422+
) -> None: ...
3423+
3424+
class IndexRaBitQFastScan(IndexFastScan):
3425+
"""Fast-scan version of RaBitQ that processes 32 database vectors at a time using SIMD."""
3426+
3427+
rabitq: RaBitQuantizer
3428+
center: Float32Vector
3429+
qb: int
3430+
centered: bool
3431+
3432+
@overload
3433+
def __init__(
3434+
self,
3435+
d: int,
3436+
metric: MetricType = METRIC_L2,
3437+
bbs: int = 32,
3438+
nb_bits: int = 1,
33043439
) -> None: ...
3440+
@overload
3441+
def __init__(self, orig: IndexRaBitQ, bbs: int = 32) -> None: ...
3442+
3443+
class IndexIVFRaBitQFastScan(IndexIVFFastScan):
3444+
"""Fast-scan version of IndexIVFRaBitQ that processes vectors in batches using SIMD."""
3445+
3446+
rabitq: RaBitQuantizer
3447+
qb: int
3448+
centered: bool
3449+
3450+
@overload
3451+
def __init__(
3452+
self,
3453+
quantizer: Index,
3454+
d: int,
3455+
nlist: int,
3456+
metric: MetricType = METRIC_L2,
3457+
bbs: int = 32,
3458+
own_invlists: bool = True,
3459+
nb_bits: int = 1,
3460+
) -> None: ...
3461+
@overload
3462+
def __init__(self, orig: IndexIVFRaBitQ, bbs: int = 32) -> None: ...
33053463

33063464
# Independent quantizer
33073465
class IndexIVFIndependentQuantizer(Index):

0 commit comments

Comments
 (0)