-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Python C code snippets
It is not always obvious how the C++ and Python layers interact. Therefore, we give some handy code in Python notebooks that can be copy/pasted to perform some useful operations.
They rely mostly on vector_to_array
and a few other Python/C++ tricks described here
The faiss.contrib.inspect_tools
module has a few useful functions to inspect the Faiss objects.
In particular inspect_tools.print_object_fields
lists all the fields of an object and their values.
Use the function faiss.contrib.inspect_tools. get_LinearTransform_matrix
, or see this code:
get_matrix_from_PCA.ipynb.
This applies to any LinearTransform
object.
See access_PQ_centroids.ipynb.
Use the function faiss.contrib.inspect_tools.get_invlist
, or see this code:
get_invlists.ipynb
See this code snippet: demo_hnsw_struct.ipynb
See demo_merge_array_invertedlists.ipynb
We have an index file but don't know what's in it.
When accessing the Index
fields of a wrapper index, they show up as a plain Index
object.
The downcast_index
converts this plain index to the "leaf" class the index belongs to.
This snippet is a demo on how to use downcast_index
to extract all info from it:
demo_explore_indedex.ipynb
IDMap2
inherits IDMap
, so this code works for both.
This code works for both directions: convert_idmap2_idmap.ipynb
See assign_on_gpu.ipynb.
plus: how to do this for IVF training
Faiss building blocks: clustering, PCA, quantization
Index IO, cloning and hyper parameter tuning
Threads and asynchronous calls
Inverted list objects and scanners
Indexes that do not fit in RAM
Brute force search without an index
Fast accumulation of PQ and AQ codes (FastScan)
Setting search parameters for one query
Binary hashing index benchmark