faiss 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/faiss/extconf.rb +1 -0
- data/ext/faiss/index.cpp +42 -0
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/IVFlib.cpp +48 -51
- data/vendor/faiss/faiss/IVFlib.h +6 -2
- data/vendor/faiss/faiss/Index.cpp +2 -2
- data/vendor/faiss/faiss/Index.h +3 -3
- data/vendor/faiss/faiss/IndexBinary.cpp +2 -2
- data/vendor/faiss/faiss/IndexBinary.h +2 -2
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +6 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +6 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexFlat.cpp +1 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +12 -10
- data/vendor/faiss/faiss/IndexHNSW.h +2 -5
- data/vendor/faiss/faiss/IndexIDMap.cpp +17 -4
- data/vendor/faiss/faiss/IndexIDMap.h +10 -5
- data/vendor/faiss/faiss/IndexIVF.cpp +68 -37
- data/vendor/faiss/faiss/IndexIVF.h +37 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +5 -15
- data/vendor/faiss/faiss/IndexIVFFlat.h +6 -6
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +28 -44
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +2 -11
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.cpp +1694 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQSSD.h +288 -0
- data/vendor/faiss/faiss/IndexIVFSQFastScan.cpp +7 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +21 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +189 -41
- data/vendor/faiss/faiss/IndexRaBitQ.h +5 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +1 -1
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +2 -2
- data/vendor/faiss/faiss/SuperKMeans.cpp +2 -2
- data/vendor/faiss/faiss/VectorTransform.cpp +156 -9
- data/vendor/faiss/faiss/VectorTransform.h +24 -1
- data/vendor/faiss/faiss/factory_tools.cpp +19 -1
- data/vendor/faiss/faiss/gpu/Dataset.h +66 -14
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +8 -2
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +8 -2
- data/vendor/faiss/faiss/gpu/impl/optimal_kmeans/GpuOptimalKMeans.h +184 -0
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +12 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +6 -5
- data/vendor/faiss/faiss/gpu_metal/GpuIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalCloner.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalDistance.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalFlatKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndex.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalIndexIVFPQ.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalKernels.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalPythonBridge.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/MetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/StandardMetalResources.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFFlat.h +1 -1
- data/vendor/faiss/faiss/gpu_metal/impl/MetalIVFPQ.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
- data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +31 -50
- data/vendor/faiss/faiss/impl/ClusteringInitialization.h +0 -15
- data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
- data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +2 -2
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.cpp +2167 -0
- data/vendor/faiss/faiss/impl/DeterministicNNDescent.h +301 -0
- data/vendor/faiss/faiss/impl/HNSW.cpp +2 -2
- data/vendor/faiss/faiss/impl/HNSW.h +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +5 -4
- data/vendor/faiss/faiss/impl/NNDescent.h +4 -0
- data/vendor/faiss/faiss/impl/PiPNN.cpp +4 -2
- data/vendor/faiss/faiss/impl/PiPNN.h +1 -1
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +0 -2
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +29 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +14 -13
- data/vendor/faiss/faiss/impl/ResultHandler.h +116 -0
- data/vendor/faiss/faiss/impl/binary_hamming/IndexBinaryIVF_impl.h +1 -3
- data/vendor/faiss/faiss/impl/expanded_scanners.h +29 -24
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.cpp +68 -6
- data/vendor/faiss/faiss/impl/fast_scan/fast_scan.h +43 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx2.cpp +15 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-avx512.cpp +115 -0
- data/vendor/faiss/faiss/impl/fast_scan/impl-neon.cpp +13 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd256.h +84 -0
- data/vendor/faiss/faiss/impl/fast_scan/kernels_simd512.h +0 -4
- data/vendor/faiss/faiss/impl/fast_scan/rabitq_result_handler.h +0 -1
- data/vendor/faiss/faiss/impl/fast_scan/simd_result_handlers.h +64 -55
- data/vendor/faiss/faiss/impl/hnsw/LockVector.h +1 -2
- data/vendor/faiss/faiss/impl/index_read.cpp +146 -9
- data/vendor/faiss/faiss/impl/index_write.cpp +29 -5
- data/vendor/faiss/faiss/impl/io.cpp +1 -0
- data/vendor/faiss/faiss/impl/io_macros.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +3 -1
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +78 -41
- data/vendor/faiss/faiss/impl/nndescent/gram-avx2.cpp +121 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-avx512.cpp +124 -0
- data/vendor/faiss/faiss/impl/nndescent/gram-neon.cpp +114 -0
- data/vendor/faiss/faiss/impl/nndescent/gram.h +66 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-avx512.cpp +431 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/BlockCombiner-inl.h +1157 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.cpp +282 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeans.h +226 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.cpp +1567 -0
- data/vendor/faiss/faiss/impl/optimal_kmeans/OptimalKMeansCompressed.h +281 -0
- data/vendor/faiss/faiss/impl/pipnn/HashPrune.cpp +1 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +47 -28
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQScanner_impl.h +6 -1
- data/vendor/faiss/faiss/impl/pq_code_distance/IVFPQ_QueryTables.cpp +17 -17
- data/vendor/faiss/faiss/impl/result_handler/ResultHandler.cpp +68 -1
- data/vendor/faiss/faiss/impl/result_handler/avx2.cpp +70 -2
- data/vendor/faiss/faiss/impl/result_handler/avx512.cpp +2 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/EDENQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +26 -26
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +48 -45
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-impl.h +34 -32
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512-spr.cpp +8 -6
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +4 -3
- data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +34 -33
- data/vendor/faiss/faiss/impl/simdlib/simdlib_avx512.h +20 -20
- data/vendor/faiss/faiss/impl/simdlib/simdlib_neon.h +4 -4
- data/vendor/faiss/faiss/impl/zerocopy_io.cpp +2 -1
- data/vendor/faiss/faiss/index_factory.cpp +30 -6
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DiskIOBackend.cpp +121 -0
- data/vendor/faiss/faiss/invlists/DiskIOBackend.h +71 -0
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +12 -9
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +26 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +5 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +9 -24
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.cpp +751 -0
- data/vendor/faiss/faiss/invlists/RaBitQSSDInvertedLists.h +224 -0
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +2 -7
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSIVF.cpp +2 -2
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +4 -4
- data/vendor/faiss/faiss/utils/WorkerThread.h +0 -1
- data/vendor/faiss/faiss/utils/distances.cpp +246 -34
- data/vendor/faiss/faiss/utils/distances.h +145 -2
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/hamming-inl.h +3 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
- data/vendor/faiss/faiss/utils/rabitq_simd.h +120 -6
- data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +47 -7
- data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +7 -3
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +47 -7
- data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +50 -10
- data/vendor/faiss/faiss/utils/simd_impl/distances_simdlib256.h +3 -3
- data/vendor/faiss/faiss/utils/simd_impl/exhaustive_L2sqr_blas_cmax.h +13 -0
- data/vendor/faiss/faiss/utils/simd_impl/partitioning_simdlib256.h +16 -15
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp +131 -36
- data/vendor/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp +156 -45
- data/vendor/faiss/faiss/utils/simd_levels.cpp +3 -3
- data/vendor/faiss/faiss/utils/sorting.cpp +6 -5
- data/vendor/faiss/faiss/utils/utils.cpp +4 -0
- metadata +20 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <cstddef>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
#include <faiss/invlists/InvertedLists.h>
|
|
17
|
+
#include <faiss/invlists/InvertedListsIOHook.h>
|
|
18
|
+
#include <faiss/utils/AlignedTable.h>
|
|
19
|
+
|
|
20
|
+
namespace faiss {
|
|
21
|
+
|
|
22
|
+
struct DiskIOBackend;
|
|
23
|
+
|
|
24
|
+
/** Inverted lists of IndexIVFRaBitQSSD: the RaBitQ code of each vector is
|
|
25
|
+
* split between memory and a file on an SSD.
|
|
26
|
+
*
|
|
27
|
+
* Memory holds each list as batches of 32 vectors. A batch is the sign bits
|
|
28
|
+
* of dimensions [0, mem_dim) of its vectors, packed in the FastScan block
|
|
29
|
+
* layout, followed by kMemFactors arrays of 32 floats (f_add, f_rescale,
|
|
30
|
+
* f_error).
|
|
31
|
+
*
|
|
32
|
+
* The file holds one fixed-size record per vector:
|
|
33
|
+
*
|
|
34
|
+
* sign bits of dimensions [mem_dim, d) ((d - mem_dim) / 8 bytes)
|
|
35
|
+
* extra-bit code (d * ex_bits / 8 bytes)
|
|
36
|
+
* f_add_ex, f_rescale_ex (2 floats)
|
|
37
|
+
* id (int64)
|
|
38
|
+
*
|
|
39
|
+
* The file starts with a kSectorSize-byte header. Records are packed into
|
|
40
|
+
* pages of page_size bytes, the smallest multiple of kSectorSize that holds
|
|
41
|
+
* one record, and never straddle two pages. The pages of a list are stored
|
|
42
|
+
* in a few extents, allocated as the list grows, so the records of a list
|
|
43
|
+
* are in add order and a page is one aligned read.
|
|
44
|
+
*
|
|
45
|
+
* The file is opened with O_DIRECT, so that searches read from the device
|
|
46
|
+
* and not from the page cache. Searches read it with libaio, one context per
|
|
47
|
+
* search thread. The contexts are kept between searches and destroyed with
|
|
48
|
+
* the inverted lists.
|
|
49
|
+
*
|
|
50
|
+
* The codes are written by IndexIVFRaBitQSSD::add, through append(); the
|
|
51
|
+
* generic add_entries / update_entries / get_codes calls are not supported.
|
|
52
|
+
*
|
|
53
|
+
* read_index supports IO_FLAG_READ_ONLY and IO_FLAG_ONDISK_SAME_DIR;
|
|
54
|
+
* IO_FLAG_SKIP_IVF_DATA and IO_FLAG_MMAP are not supported.
|
|
55
|
+
*/
|
|
56
|
+
struct RaBitQSSDInvertedLists : InvertedLists {
|
|
57
|
+
/// alignment and size unit of all file accesses
|
|
58
|
+
static constexpr size_t kSectorSize = 4096;
|
|
59
|
+
/// vectors per in-memory batch, the FastScan block size
|
|
60
|
+
static constexpr size_t kBatchSize = 32;
|
|
61
|
+
/// floats stored in memory per vector
|
|
62
|
+
static constexpr size_t kMemFactors = 3;
|
|
63
|
+
|
|
64
|
+
size_t d = 0; ///< dimensionality
|
|
65
|
+
size_t mem_dim = 0; ///< dimensions whose sign bits stay in memory
|
|
66
|
+
size_t ex_bits = 0; ///< extra bits per dimension, in the file
|
|
67
|
+
|
|
68
|
+
// derived from d, mem_dim and ex_bits by set_derived_values()
|
|
69
|
+
size_t batch_bytes = 0; ///< bytes per in-memory batch
|
|
70
|
+
size_t record_size = 0; ///< bytes per record in the file
|
|
71
|
+
size_t page_size = 0; ///< bytes per page in the file
|
|
72
|
+
size_t records_per_page = 0; ///< records per page
|
|
73
|
+
|
|
74
|
+
std::string filename; ///< path of the file
|
|
75
|
+
int fd = -1; ///< descriptor of filename, opened with O_DIRECT
|
|
76
|
+
bool read_only = false;
|
|
77
|
+
|
|
78
|
+
/// a run of pages of the file, owned by one list
|
|
79
|
+
struct Extent {
|
|
80
|
+
size_t first_page; ///< in the file
|
|
81
|
+
size_t n_pages;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
std::vector<size_t> sizes; ///< number of vectors in each list
|
|
85
|
+
|
|
86
|
+
/// in-memory batches of each list. The capacity of a table may exceed
|
|
87
|
+
/// the bytes in use, batch_bytes per started batch.
|
|
88
|
+
std::vector<AlignedTableTightAlloc<uint8_t>> mem_data;
|
|
89
|
+
|
|
90
|
+
/// pages of each list, in list order
|
|
91
|
+
std::vector<std::vector<Extent>> extents;
|
|
92
|
+
|
|
93
|
+
size_t total_pages = 0; ///< pages allocated in the file
|
|
94
|
+
uint64_t file_id = 0; ///< random tag, also written to the file header
|
|
95
|
+
|
|
96
|
+
/** Create the inverted lists and their file (truncating it).
|
|
97
|
+
*
|
|
98
|
+
* @param nlist number of lists
|
|
99
|
+
* @param d dimensionality, a multiple of 64
|
|
100
|
+
* @param mem_dim dimensions whose sign bits stay in memory, a
|
|
101
|
+
* multiple of 64 in [64, d]
|
|
102
|
+
* @param ex_bits extra bits per dimension, in [1, 8]
|
|
103
|
+
* @param filename path of the file
|
|
104
|
+
*/
|
|
105
|
+
RaBitQSSDInvertedLists(
|
|
106
|
+
size_t nlist,
|
|
107
|
+
size_t d,
|
|
108
|
+
size_t mem_dim,
|
|
109
|
+
size_t ex_bits,
|
|
110
|
+
const char* filename);
|
|
111
|
+
|
|
112
|
+
/// for the I/O functions
|
|
113
|
+
RaBitQSSDInvertedLists();
|
|
114
|
+
|
|
115
|
+
RaBitQSSDInvertedLists(const RaBitQSSDInvertedLists&) = delete;
|
|
116
|
+
RaBitQSSDInvertedLists& operator=(const RaBitQSSDInvertedLists&) = delete;
|
|
117
|
+
|
|
118
|
+
~RaBitQSSDInvertedLists() override;
|
|
119
|
+
|
|
120
|
+
/// check d, mem_dim and ex_bits, and compute the derived sizes
|
|
121
|
+
void set_derived_values();
|
|
122
|
+
|
|
123
|
+
/// number of in-memory batches of a list
|
|
124
|
+
size_t list_batches(size_t list_no) const;
|
|
125
|
+
|
|
126
|
+
/// pages of the file used by a list
|
|
127
|
+
size_t list_pages(size_t list_no) const;
|
|
128
|
+
|
|
129
|
+
/// byte offset in the file of page page_no of a list
|
|
130
|
+
size_t page_offset(size_t list_no, size_t page_no) const;
|
|
131
|
+
|
|
132
|
+
// hidden from SWIG, which does not handle std::unique_ptr well
|
|
133
|
+
#ifndef SWIG
|
|
134
|
+
/** A libaio context for one search thread, for up to max_events reads
|
|
135
|
+
* in flight. Creating and destroying a context takes tens of
|
|
136
|
+
* milliseconds, so the contexts are kept for the next searches.
|
|
137
|
+
* Thread-safe.
|
|
138
|
+
*/
|
|
139
|
+
std::unique_ptr<DiskIOBackend> acquire_io(int max_events) const;
|
|
140
|
+
|
|
141
|
+
/// give back a context of acquire_io(), with no read in flight
|
|
142
|
+
void release_io(std::unique_ptr<DiskIOBackend> io) const noexcept;
|
|
143
|
+
#endif
|
|
144
|
+
|
|
145
|
+
/*************************
|
|
146
|
+
* InvertedLists interface */
|
|
147
|
+
|
|
148
|
+
size_t list_size(size_t list_no) const override;
|
|
149
|
+
|
|
150
|
+
/// not supported: the codes are split between memory and the file
|
|
151
|
+
const uint8_t* get_codes(size_t list_no) const override;
|
|
152
|
+
|
|
153
|
+
/// read the ids of a list from the file. Release with release_ids.
|
|
154
|
+
const idx_t* get_ids(size_t list_no) const override;
|
|
155
|
+
|
|
156
|
+
void release_ids(size_t list_no, const idx_t* ids) const override;
|
|
157
|
+
|
|
158
|
+
/// read one id from the file
|
|
159
|
+
idx_t get_single_id(size_t list_no, size_t offset) const override;
|
|
160
|
+
|
|
161
|
+
/// not supported, use IndexIVFRaBitQSSD::add
|
|
162
|
+
size_t add_entries(
|
|
163
|
+
size_t list_no,
|
|
164
|
+
size_t n_entry,
|
|
165
|
+
const idx_t* ids,
|
|
166
|
+
const uint8_t* code) override;
|
|
167
|
+
|
|
168
|
+
/// not supported
|
|
169
|
+
void update_entries(
|
|
170
|
+
size_t list_no,
|
|
171
|
+
size_t offset,
|
|
172
|
+
size_t n_entry,
|
|
173
|
+
const idx_t* ids,
|
|
174
|
+
const uint8_t* code) override;
|
|
175
|
+
|
|
176
|
+
/// only new_size == list_size(list_no) is supported
|
|
177
|
+
void resize(size_t list_no, size_t new_size) override;
|
|
178
|
+
|
|
179
|
+
/// empty all lists, truncate the file to its header and invalidate
|
|
180
|
+
/// previously written index files by changing the file identifier
|
|
181
|
+
void reset() override;
|
|
182
|
+
|
|
183
|
+
/*************************
|
|
184
|
+
* split-code interface */
|
|
185
|
+
|
|
186
|
+
/// make room in the file for n_more vectors in a list. append() does it
|
|
187
|
+
/// as needed; calling it first with the total count of a batch of
|
|
188
|
+
/// appends gives the list a single extent.
|
|
189
|
+
void reserve(size_t list_no, size_t n_more);
|
|
190
|
+
|
|
191
|
+
/** Append vectors to a list. Not thread-safe for the same list.
|
|
192
|
+
*
|
|
193
|
+
* @param n number of vectors
|
|
194
|
+
* @param mem_codes sign bits of dimensions [0, mem_dim), mem_dim / 8
|
|
195
|
+
* bytes per vector
|
|
196
|
+
* @param factors kMemFactors floats per vector
|
|
197
|
+
* @param records record_size bytes per vector, in the file format
|
|
198
|
+
*/
|
|
199
|
+
void append(
|
|
200
|
+
size_t list_no,
|
|
201
|
+
size_t n,
|
|
202
|
+
const uint8_t* mem_codes,
|
|
203
|
+
const float* factors,
|
|
204
|
+
const uint8_t* records);
|
|
205
|
+
|
|
206
|
+
/// open the file of deserialized inverted lists and check its header
|
|
207
|
+
void open_file();
|
|
208
|
+
|
|
209
|
+
// opaque, so hidden from SWIG
|
|
210
|
+
#ifndef SWIG
|
|
211
|
+
/// pool of libaio contexts for the searches and its mutex, and the
|
|
212
|
+
/// mutex of total_pages
|
|
213
|
+
struct IOState;
|
|
214
|
+
IOState* io_state = nullptr;
|
|
215
|
+
#endif
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
struct RaBitQSSDInvertedListsIOHook : InvertedListsIOHook {
|
|
219
|
+
RaBitQSSDInvertedListsIOHook();
|
|
220
|
+
void write(const InvertedLists* ils, IOWriter* f) const override;
|
|
221
|
+
InvertedLists* read(IOReader* f, int io_flags) const override;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
} // namespace faiss
|
|
@@ -66,7 +66,6 @@ struct FaissIDFilter : public svs_runtime::IDFilter {
|
|
|
66
66
|
return selector.is_member(static_cast<faiss::idx_t>(id));
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
private:
|
|
70
69
|
const faiss::IDSelector& selector;
|
|
71
70
|
};
|
|
72
71
|
|
|
@@ -104,7 +103,6 @@ struct InputBufferConverter {
|
|
|
104
103
|
return buffer;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
private:
|
|
108
106
|
std::vector<T> buffer;
|
|
109
107
|
};
|
|
110
108
|
|
|
@@ -134,7 +132,6 @@ struct InputBufferConverter<
|
|
|
134
132
|
reinterpret_cast<const T*>(data_span.data()), data_span.size());
|
|
135
133
|
}
|
|
136
134
|
|
|
137
|
-
private:
|
|
138
135
|
std::span<const U> data_span;
|
|
139
136
|
};
|
|
140
137
|
|
|
@@ -162,7 +159,6 @@ struct OutputBufferConverter {
|
|
|
162
159
|
return buffer;
|
|
163
160
|
}
|
|
164
161
|
|
|
165
|
-
private:
|
|
166
162
|
std::span<U> data_span;
|
|
167
163
|
std::vector<T> buffer;
|
|
168
164
|
};
|
|
@@ -186,7 +182,6 @@ struct OutputBufferConverter<
|
|
|
186
182
|
reinterpret_cast<T*>(data_span.data()), data_span.size());
|
|
187
183
|
}
|
|
188
184
|
|
|
189
|
-
private:
|
|
190
185
|
std::span<U> data_span;
|
|
191
186
|
};
|
|
192
187
|
|
|
@@ -220,7 +215,8 @@ auto convert_output_buffer(U* data, size_t size) {
|
|
|
220
215
|
}
|
|
221
216
|
|
|
222
217
|
struct FaissResultsAllocator : public svs_runtime::ResultsAllocator {
|
|
223
|
-
FaissResultsAllocator(faiss::RangeSearchResult*
|
|
218
|
+
FaissResultsAllocator(faiss::RangeSearchResult* result_in)
|
|
219
|
+
: result(result_in) {
|
|
224
220
|
FAISS_ASSERT(result != nullptr);
|
|
225
221
|
}
|
|
226
222
|
|
|
@@ -244,7 +240,6 @@ struct FaissResultsAllocator : public svs_runtime::ResultsAllocator {
|
|
|
244
240
|
result->distances, result->lims[result_counts.size()])};
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
private:
|
|
248
243
|
faiss::RangeSearchResult* result;
|
|
249
244
|
using LabelsConverter = OutputBufferConverter<size_t, faiss::idx_t>;
|
|
250
245
|
mutable LabelsConverter labels_converter;
|
|
@@ -66,10 +66,10 @@ IndexSVSIVF::IndexSVSIVF(
|
|
|
66
66
|
size_t nlist,
|
|
67
67
|
MetricType metric,
|
|
68
68
|
SVSStorageKind storage,
|
|
69
|
-
bool
|
|
69
|
+
bool is_static_in)
|
|
70
70
|
: Index(d, metric),
|
|
71
71
|
num_centroids{nlist},
|
|
72
|
-
is_static{
|
|
72
|
+
is_static{is_static_in},
|
|
73
73
|
storage_kind{storage} {
|
|
74
74
|
is_trained = false;
|
|
75
75
|
|
|
@@ -67,13 +67,13 @@ IndexSVSVamana::IndexSVSVamana(
|
|
|
67
67
|
size_t degree,
|
|
68
68
|
MetricType metric,
|
|
69
69
|
SVSStorageKind storage,
|
|
70
|
-
bool
|
|
71
|
-
bool
|
|
70
|
+
bool is_static_in,
|
|
71
|
+
bool store_vectors_in)
|
|
72
72
|
: Index(d, metric),
|
|
73
73
|
graph_max_degree{degree},
|
|
74
|
-
is_static{
|
|
74
|
+
is_static{is_static_in},
|
|
75
75
|
storage_kind{storage},
|
|
76
|
-
store_vectors{
|
|
76
|
+
store_vectors{store_vectors_in} {
|
|
77
77
|
prune_to = graph_max_degree < 4 ? graph_max_degree : graph_max_degree - 4;
|
|
78
78
|
alpha = metric == METRIC_L2 ? 1.2f : 0.95f;
|
|
79
79
|
|