All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
faiss::IndexPQ Struct Reference

`#include <IndexPQ.h>`

Inheritance diagram for faiss::IndexPQ:

## Public Types

enum | Search_type_t { ST_PQ, ST_HE, ST_generalized_HE, ST_SDC, ST_polysemous, ST_polysemous_generalize }
| how to perform the search in search_core More...
Public Types inherited from faiss::Index
typedef long | idx_t
| all indices are this type

## Public Member Functions

| IndexPQ (int d, size_t M, size_t nbits, MetricType metric=METRIC_L2)
virtual void | set_typename () override
virtual void | train (idx_t n, const float *x) override
virtual void | add (idx_t n, const float *x) override
virtual void | search (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
virtual void | reset () override
| removes all elements from the database.
virtual void | reconstruct_n (idx_t i0, idx_t ni, float *recons) const override
virtual void | reconstruct (idx_t key, float *recons) const override
void | search_core_polysemous (idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const
void | hamming_distance_histogram (idx_t n, const float *x, idx_t nb, const float *xb, long *dist_histogram)
void | hamming_distance_table (idx_t n, const float *x, int32_t *dis) const
Public Member Functions inherited from faiss::Index
| Index (idx_t d=0, MetricType metric=METRIC_INNER_PRODUCT)
virtual void | add_with_ids (idx_t n, const float *x, const long *xids)
virtual void | range_search (idx_t n, const float *x, float radius, RangeSearchResult *result) const
void | assign (idx_t n, const float *x, idx_t *labels, idx_t k=1)
virtual long | remove_ids (const IDSelector &sel)
void | compute_residual (const float *x, float *residual, idx_t key) const
void | display () const
virtual std::string | get_typename () const

## Public Attributes

ProductQuantizer | pq
| The product quantizer used to encode the vectors.
std::vector< uint8_t > | codes
| Codes. Size ntotal * pq.code_size.
bool | do_polysemous_training
| false = standard PQ
PolysemousTraining | polysemous_training
| parameters used for the polysemous training
Search_type_t | search_type
bool | encode_signs
int | polysemous_ht
| Hamming threshold used for polysemy.
Public Attributes inherited from faiss::Index
std::string | index_typename
int | d
| vector dimension
idx_t | ntotal
| total nb of indexed vectors
bool | verbose
| verbosity level
bool | is_trained
| set if the Index does not require training, or if training is done already
MetricType | metric_type
| type of metric this index uses for search

## Detailed Description

Index based on a product quantizer. Stored vectors are approximated by PQ codes.

Definition at line 29 of file IndexPQ.h.

## Member Enumeration Documentation

enum faiss::IndexPQ::Search_type_t

how to perform the search in search_core

Enumerator
ST_PQ | asymmetric product quantizer (default)
ST_HE | Hamming distance on codes.
ST_generalized_HE | nb of same codes
ST_SDC | symmetric product quantizer (SDC)
ST_polysemous | HE filter (using ht) + PQ combination.
ST_polysemous_generalize | Filter on generalized Hamming.

Definition at line 77 of file IndexPQ.h.

## Constructor & Destructor Documentation

faiss::IndexPQ::IndexPQ | ( | int | d,
|  | size_t | M,
|  | size_t | nbits,
|  | MetricType | metric = `METRIC_L2`
| ) |  |

Constructor.

Parameters

  d | dimensionality of the input vectors
  M | number of subquantizers
  nbits | number of bit per subvector index

Parameters

  d | dimensionality of the input vectors
  M | number of subquantizers
  nbits | number of bit per subvector index

Definition at line 33 of file IndexPQ.cpp.

## Member Function Documentation

void faiss::IndexPQ::add | ( | idx_t | n,
|  | const float * | x
| ) |  |

overridevirtual

Add n vectors of dimension d to the index.

Vectors are implicitly assigned labels ntotal .. ntotal + n - 1 This function slices the input vectors in chuncks smaller than blocksize_add and calls add_core.

Parameters

  x | input matrix, size n * d

Implements faiss::Index.

Definition at line 88 of file IndexPQ.cpp.

void faiss::IndexPQ::hamming_distance_histogram | ( | idx_t | n,
|  | const float * | x,
|  | idx_t | nb,
|  | const float * | xb,
|  | long * | dist_histogram
| ) |  |

prepare query for a polysemous search, but instead of computing the result, just get the histogram of Hamming distances. May be computed on a provided dataset if xb != NULL

Parameters

  dist_histogram | (M * nbits + 1)

Definition at line 394 of file IndexPQ.cpp.

void faiss::IndexPQ::hamming_distance_table | ( | idx_t | n,
|  | const float * | x,
|  | int32_t * | dis
| ) |  | const

compute pairwise distances between queries and database

Parameters

  n | nb of query vectors
  x | query vector, size n * d
  dis | output distances, size n * ntotal

Definition at line 381 of file IndexPQ.cpp.

void faiss::IndexPQ::reconstruct | ( | idx_t | key,
|  | float * | recons
| ) |  | const

overridevirtual

Reconstruct a stored vector (or an approximation if lossy coding)

this function may not be defined for some indexes

Parameters

  key | id of the vector to reconstruct
  recons | reconstucted vector (size d)

Reimplemented from faiss::Index.

Definition at line 114 of file IndexPQ.cpp.

void faiss::IndexPQ::reconstruct_n | ( | idx_t | i0,
|  | idx_t | ni,
|  | float * | recons
| ) |  | const

overridevirtual

Reconstruct vectors i0 to i0 + ni - 1

this function may not be defined for some indexes

Parameters

  recons | reconstucted vector (size ni * d)

Reimplemented from faiss::Index.

Definition at line 104 of file IndexPQ.cpp.

void faiss::IndexPQ::search | ( | idx_t | n,
|  | const float * | x,
|  | idx_t | k,
|  | float * | distances,
|  | idx_t * | labels
| ) |  | const

overridevirtual

query n vectors of dimension d to the index.

return at most k vectors. If there are not enough results for a query, the result array is padded with -1s.

Parameters

  x | input vectors to search, size n * d
  labels | output labels of the NNs, size n*k
  distances | output pairwise distances, size n*k

Implements faiss::Index.

Definition at line 134 of file IndexPQ.cpp.

void faiss::IndexPQ::train | ( | idx_t | n,
|  | const float * | x
| ) |  |

overridevirtual

Perform training on a representative set of vectors

Parameters

  n | nb of training vectors
  x | training vecors, size n * d

Reimplemented from faiss::Index.

Definition at line 64 of file IndexPQ.cpp.

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

- IndexPQ.h
- IndexPQ.cpp