File io.h

namespace faiss

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. Implementation of k-means clustering with many variants.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. IDSelector is intended to define a subset of vectors to handle (for removal or as subset to search)

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. PQ4 SIMD packing and accumulation functions

The basic kernel accumulates nq query vectors with bbs = nb * 2 * 16 vectors and produces an output matrix for that. It is interesting for nq * nb <= 4, otherwise register spilling becomes too large.

The implementation of these functions is spread over 3 cpp files to reduce parallel compile times. Templates are instantiated explicitly.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. This file contains callbacks for kernels that compute distances.

Throughout the library, vectors are provided as float * pointers. Most algorithms can be optimized when several vectors are processed (added/searched) together in a batch. In this case, they are passed in as a matrix. When n vectors of size d are provided as float * x, component j of vector i is

x[ i * d + j ]

where 0 <= i < n and 0 <= j < d. In other words, matrices are always compact. When specifying the size of the matrix, we call it an n*d matrix, which implies a row-major storage.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. I/O functions can read/write to a filename, a file handle or to an object that abstracts the medium.

The read functions return objects that should be deallocated with delete. All references within these objectes are owned by the object.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. Definition of inverted lists + a few common classes that implement the interface.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. Since IVF (inverted file) indexes are of so much use for large-scale use cases, we group a few functions related to them in this small library. Most functions work both on IndexIVFs and IndexIVFs embedded within an IndexPreTransform.

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. In this file are the implementations of extra metrics beyond L2 and inner product

Copyright (c) Facebook, Inc. and its affiliates.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. Defines a few objects that apply transformations to a set of vectors Often these are pre-processing steps.

Functions

uint32_t fourcc(const char sx[4])

cast a 4-character string to a uint32_t that can be written and read easily

uint32_t fourcc(const std::string &sx)
void fourcc_inv(uint32_t x, char str[5])
std::string fourcc_inv(uint32_t x)
std::string fourcc_inv_printable(uint32_t x)
struct IOReader

Subclassed by PyCallbackIOReader, faiss::BufferedIOReader, faiss::FileIOReader, faiss::VectorIOReader

Public Functions

virtual size_t operator()(void *ptr, size_t size, size_t nitems) = 0
virtual int fileno()
inline virtual ~IOReader()

Public Members

std::string name
struct IOWriter

Subclassed by PyCallbackIOWriter, faiss::BufferedIOWriter, faiss::FileIOWriter, faiss::VectorIOWriter

Public Functions

virtual size_t operator()(const void *ptr, size_t size, size_t nitems) = 0
virtual int fileno()
inline virtual ~IOWriter() noexcept(false)

Public Members

std::string name
struct VectorIOReader : public faiss::IOReader

Public Functions

virtual size_t operator()(void *ptr, size_t size, size_t nitems) override
virtual int fileno()

Public Members

std::vector<uint8_t> data
size_t rp = 0
std::string name
struct VectorIOWriter : public faiss::IOWriter

Public Functions

virtual size_t operator()(const void *ptr, size_t size, size_t nitems) override
virtual int fileno()

Public Members

std::vector<uint8_t> data
std::string name
struct FileIOReader : public faiss::IOReader

Public Functions

FileIOReader(FILE *rf)
FileIOReader(const char *fname)
~FileIOReader() override
virtual size_t operator()(void *ptr, size_t size, size_t nitems) override
virtual int fileno() override

Public Members

FILE *f = nullptr
bool need_close = false
std::string name
struct FileIOWriter : public faiss::IOWriter

Public Functions

FileIOWriter(FILE *wf)
FileIOWriter(const char *fname)
~FileIOWriter() override
virtual size_t operator()(const void *ptr, size_t size, size_t nitems) override
virtual int fileno() override

Public Members

FILE *f = nullptr
bool need_close = false
std::string name
struct BufferedIOReader : public faiss::IOReader
#include <io.h>

wraps an ioreader to make buffered reads to avoid too small reads

Public Functions

explicit BufferedIOReader(IOReader *reader, size_t bsz = 1024 * 1024)
Parameters:

bsz – buffer size (bytes). Reads will be done by batched of this size

virtual size_t operator()(void *ptr, size_t size, size_t nitems) override
virtual int fileno()

Public Members

IOReader *reader
size_t bsz
size_t ofs

offset in input stream

size_t ofs2

number of bytes returned to caller

size_t b0
size_t b1

range of available bytes in the buffer

std::vector<char> buffer
std::string name
struct BufferedIOWriter : public faiss::IOWriter

Public Functions

explicit BufferedIOWriter(IOWriter *writer, size_t bsz = 1024 * 1024)
virtual size_t operator()(const void *ptr, size_t size, size_t nitems) override
~BufferedIOWriter() override
virtual int fileno()

Public Members

IOWriter *writer
size_t bsz
size_t ofs
size_t ofs2

number of bytes received from caller

size_t b0

amount of data in buffer

std::vector<char> buffer
std::string name