Faiss

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
faiss::ProductQuantizer Struct Reference

`#include <ProductQuantizer.h>`

## Classes
struct | PQDecoder16
struct | PQDecoder8
struct | PQDecoderGeneric
struct | PQEncoder16
struct | PQEncoder8
struct | PQEncoderGeneric

## Public Types
enum | train_type_t { Train_default, Train_hot_start, Train_shared, Train_hypercube, Train_hypercube_pca }
| initialization More...
using | idx_t = Index::idx_t

## Public Member Functions
float * | get_centroids (size_t m, size_t i)
| return the centroids associated with subvector m
const float * | get_centroids (size_t m, size_t i) const
void | train (int n, const float *x)
| ProductQuantizer (size_t d, size_t M, size_t nbits)
void | set_derived_values ()
| compute derived values when d, M and nbits have been set
void | set_params (const float *centroids, int m)
| Define the centroids for subquantizer m.
void | compute_code (const float *x, uint8_t *code) const
| Quantize one vector with the product quantizer.
void | compute_codes (const float *x, uint8_t *codes, size_t n) const
| same as compute_code for several vectors
void | compute_codes_with_assign_index (const float *x, uint8_t *codes, size_t n)
void | decode (const uint8_t *code, float *x) const
| decode a vector from a given code (or n vectors if third argument)
void | decode (const uint8_t *code, float *x, size_t n) const
void | compute_code_from_distance_table (const float *tab, uint8_t *code) const
void | compute_distance_table (const float *x, float *dis_table) const
void | compute_inner_prod_table (const float *x, float *dis_table) const
void | compute_distance_tables (size_t nx, const float *x, float *dis_tables) const
void | compute_inner_prod_tables (size_t nx, const float *x, float *dis_tables) const
void | search (const float *x, size_t nx, const uint8_t *codes, const size_t ncodes, float_maxheap_array_t *res, bool init_finalize_heap=true) const
void | search_ip (const float *x, size_t nx, const uint8_t *codes, const size_t ncodes, float_minheap_array_t *res, bool init_finalize_heap=true) const
void | compute_sdc_table ()
void | search_sdc (const uint8_t *qcodes, size_t nq, const uint8_t *bcodes, const size_t ncodes, float_maxheap_array_t *res, bool init_finalize_heap=true) const

## Public Attributes
size_t | d
| size of the input vectors
size_t | M
| number of subquantizers
size_t | nbits
| number of bits per quantization index
size_t | dsub
| dimensionality of each subvector
size_t | code_size
| byte per indexed vector
size_t | ksub
| number of centroids for each subquantizer
bool | verbose
| verbose during training?
train_type_t | train_type
ClusteringParameters | cp
| parameters used during clustering
Index * | assign_index
std::vector< float > | centroids
| Centroid table, size M * ksub * dsub.
std::vector< float > | sdc_table
| Symmetric Distance Table.

## Detailed Description

Product Quantizer. Implemented only for METRIC_L2

Definition at line 23 of file ProductQuantizer.h.

## Member Enumeration Documentation

enum faiss::ProductQuantizer::train_type_t

initialization

Enumerator
Train_hot_start | the centroids are already initialized
Train_shared | share dictionary accross PQ segments
Train_hypercube | intialize centroids with nbits-D hypercube
Train_hypercube_pca | intialize centroids with nbits-D hypercube

Definition at line 39 of file ProductQuantizer.h.

## Member Function Documentation

void faiss::ProductQuantizer::compute_code_from_distance_table | ( | const float * | tab,
|  | uint8_t * | code
| ) |  | const

If we happen to have the distance tables precomputed, this is more efficient to compute the codes.

Definition at line 406 of file ProductQuantizer.cpp.

void faiss::ProductQuantizer::compute_codes_with_assign_index | ( | const float * | x,
|  | uint8_t * | codes,
|  | size_t | n
| ) |  |

speed up code assignment using assign_index (non-const because the index is changed)

Definition at line 427 of file ProductQuantizer.cpp.

void faiss::ProductQuantizer::compute_distance_table | ( | const float * | x,
|  | float * | dis_table
| ) |  | const

Compute distance table for one vector.

The distance table for x = [x_0 x_1 .. x_(M-1)] is a M * ksub matrix that contains

dis_table (m, j) = || x_m - c_(m, j)||^2 for m = 0..M-1 and j = 0 .. ksub - 1

where c_(m, j) is the centroid no j of sub-quantizer m.

Parameters

  x | input vector size d
  dis_table | output table, size M * ksub

Definition at line 517 of file ProductQuantizer.cpp.

void faiss::ProductQuantizer::compute_distance_tables | ( | size_t | nx,
|  | const float * | x,
|  | float * | dis_tables
| ) |  | const

compute distance table for several vectors

Parameters

  nx | nb of input vectors
  x | input vector size nx * d
  dis_table | output table, size nx * M * ksub

Definition at line 546 of file ProductQuantizer.cpp.

void faiss::ProductQuantizer::search | ( | const float * | x,
|  | size_t | nx,
|  | const uint8_t * | codes,
|  | const size_t | ncodes,
|  | float_maxheap_array_t * | res,
|  | bool | init_finalize_heap = `true`
| ) |  | const

perform a search (L2 distance)

Parameters

  x | query vectors, size nx * d
  nx | nb of queries
  codes | database codes, size ncodes * code_size
  ncodes | nb of nb vectors
  res | heap array to store results (nh == nx)
  init_finalize_heap | initialize heap (input) and sort (output)?

Definition at line 659 of file ProductQuantizer.cpp.

void faiss::ProductQuantizer::search_ip | ( | const float * | x,
|  | size_t | nx,
|  | const uint8_t * | codes,
|  | const size_t | ncodes,
|  | float_minheap_array_t * | res,
|  | bool | init_finalize_heap = `true`
| ) |  | const

same as search, but with inner product similarity

Definition at line 674 of file ProductQuantizer.cpp.

## Member Data Documentation

Index* faiss::ProductQuantizer::assign_index

if non-NULL, use this index for assignment (should be of size d / M)

Definition at line 52 of file ProductQuantizer.h.

The documentation for this struct was generated from the following files:

- /data/users/hoss/faiss/ProductQuantizer.h
- /data/users/hoss/faiss/ProductQuantizer.cpp