faiss 0.4.3 → 0.5.1
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 +10 -0
- data/README.md +2 -0
- data/ext/faiss/index.cpp +33 -6
- data/ext/faiss/index_binary.cpp +17 -4
- data/ext/faiss/kmeans.cpp +6 -6
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -3
- data/vendor/faiss/faiss/AutoTune.h +1 -1
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +26 -51
- data/vendor/faiss/faiss/IVFlib.h +1 -1
- data/vendor/faiss/faiss/Index.cpp +11 -0
- data/vendor/faiss/faiss/Index.h +34 -11
- data/vendor/faiss/faiss/Index2Layer.cpp +1 -1
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +1 -0
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +9 -4
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexBinary.h +7 -7
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +8 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +5 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +7 -6
- data/vendor/faiss/faiss/IndexFastScan.cpp +125 -49
- data/vendor/faiss/faiss/IndexFastScan.h +102 -7
- data/vendor/faiss/faiss/IndexFlat.cpp +374 -4
- data/vendor/faiss/faiss/IndexFlat.h +81 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +93 -2
- data/vendor/faiss/faiss/IndexHNSW.h +58 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +14 -13
- data/vendor/faiss/faiss/IndexIDMap.h +6 -6
- data/vendor/faiss/faiss/IndexIVF.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVF.h +5 -5
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +9 -3
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +3 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +176 -90
- data/vendor/faiss/faiss/IndexIVFFastScan.h +173 -18
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +251 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +64 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +1 -1
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +134 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +7 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +99 -8
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +4 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +828 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +252 -0
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -1
- data/vendor/faiss/faiss/IndexNSG.cpp +1 -1
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +1 -1
- data/vendor/faiss/faiss/IndexPQ.cpp +4 -1
- data/vendor/faiss/faiss/IndexPQ.h +1 -1
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +6 -2
- data/vendor/faiss/faiss/IndexPQFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexPreTransform.cpp +14 -0
- data/vendor/faiss/faiss/IndexPreTransform.h +9 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +96 -13
- data/vendor/faiss/faiss/IndexRaBitQ.h +11 -2
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +731 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +175 -0
- data/vendor/faiss/faiss/IndexRefine.cpp +49 -0
- data/vendor/faiss/faiss/IndexRefine.h +17 -0
- data/vendor/faiss/faiss/IndexShards.cpp +1 -1
- data/vendor/faiss/faiss/MatrixStats.cpp +3 -3
- data/vendor/faiss/faiss/MetricType.h +1 -1
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +5 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +11 -7
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +1 -1
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIcmEncoder.cpp +7 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -1
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +77 -6
- data/vendor/faiss/faiss/impl/FastScanDistancePostProcessing.h +53 -0
- data/vendor/faiss/faiss/impl/HNSW.cpp +295 -16
- data/vendor/faiss/faiss/impl/HNSW.h +35 -6
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +1 -1
- data/vendor/faiss/faiss/impl/Panorama.cpp +193 -0
- data/vendor/faiss/faiss/impl/Panorama.h +204 -0
- data/vendor/faiss/faiss/impl/PanoramaStats.cpp +33 -0
- data/vendor/faiss/faiss/impl/PanoramaStats.h +38 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +5 -5
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +29 -0
- data/vendor/faiss/faiss/impl/RaBitQStats.h +56 -0
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +294 -0
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +330 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +304 -223
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +72 -4
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +362 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +112 -0
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +4 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +7 -10
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +2 -4
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +7 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +238 -10
- data/vendor/faiss/faiss/impl/index_write.cpp +212 -19
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +4 -4
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +1 -1
- data/vendor/faiss/faiss/impl/kmeans1d.h +1 -1
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.h +4 -3
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +8 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +12 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +30 -4
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +14 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +5 -6
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +55 -11
- data/vendor/faiss/faiss/impl/svs_io.cpp +86 -0
- data/vendor/faiss/faiss/impl/svs_io.h +67 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.h +1 -1
- data/vendor/faiss/faiss/index_factory.cpp +217 -8
- data/vendor/faiss/faiss/index_factory.h +1 -1
- data/vendor/faiss/faiss/index_io.h +1 -1
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +1 -1
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +115 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.h +46 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +1 -1
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +261 -0
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +117 -0
- data/vendor/faiss/faiss/svs/IndexSVSFlat.h +66 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +245 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +137 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.cpp +39 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +42 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +149 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +58 -0
- data/vendor/faiss/faiss/utils/AlignedTable.h +1 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +3 -3
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +1 -1
- data/vendor/faiss/faiss/utils/NeuralNet.h +3 -3
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +1 -1
- data/vendor/faiss/faiss/utils/distances.cpp +0 -3
- data/vendor/faiss/faiss/utils/distances.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +3 -1
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -0
- data/vendor/faiss/faiss/utils/hamming.cpp +7 -6
- data/vendor/faiss/faiss/utils/hamming.h +1 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +5 -5
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/rabitq_simd.h +222 -336
- data/vendor/faiss/faiss/utils/random.cpp +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +1 -1
- data/vendor/faiss/faiss/utils/utils.cpp +9 -2
- data/vendor/faiss/faiss/utils/utils.h +2 -2
- metadata +29 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
25
|
+
#include <faiss/svs/IndexSVSVamana.h>
|
|
26
|
+
|
|
27
|
+
#include <faiss/Index.h>
|
|
28
|
+
|
|
29
|
+
#include <svs/runtime/api_defs.h>
|
|
30
|
+
#include <svs/runtime/dynamic_vamana_index.h>
|
|
31
|
+
#include <svs/runtime/vamana_index.h>
|
|
32
|
+
|
|
33
|
+
#include <cstddef>
|
|
34
|
+
#include <numeric>
|
|
35
|
+
#include <span>
|
|
36
|
+
#include <type_traits>
|
|
37
|
+
#include <vector>
|
|
38
|
+
|
|
39
|
+
namespace faiss {
|
|
40
|
+
namespace {
|
|
41
|
+
svs_runtime::VamanaIndex::SearchParams make_search_parameters(
|
|
42
|
+
const IndexSVSVamana& index,
|
|
43
|
+
const SearchParameters* params) {
|
|
44
|
+
FAISS_THROW_IF_NOT(index.impl);
|
|
45
|
+
|
|
46
|
+
auto search_window_size = index.search_window_size;
|
|
47
|
+
auto search_buffer_capacity = index.search_buffer_capacity;
|
|
48
|
+
|
|
49
|
+
if (auto svs_params =
|
|
50
|
+
dynamic_cast<const SearchParametersSVSVamana*>(params)) {
|
|
51
|
+
if (svs_params->search_window_size > 0)
|
|
52
|
+
search_window_size = svs_params->search_window_size;
|
|
53
|
+
if (svs_params->search_buffer_capacity > 0)
|
|
54
|
+
search_buffer_capacity = svs_params->search_buffer_capacity;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {search_window_size, search_buffer_capacity};
|
|
58
|
+
}
|
|
59
|
+
} // namespace
|
|
60
|
+
|
|
61
|
+
IndexSVSVamana::IndexSVSVamana() = default;
|
|
62
|
+
|
|
63
|
+
IndexSVSVamana::IndexSVSVamana(
|
|
64
|
+
idx_t d,
|
|
65
|
+
size_t degree,
|
|
66
|
+
MetricType metric,
|
|
67
|
+
SVSStorageKind storage)
|
|
68
|
+
: Index(d, metric), graph_max_degree{degree}, storage_kind{storage} {
|
|
69
|
+
prune_to = graph_max_degree < 4 ? graph_max_degree : graph_max_degree - 4;
|
|
70
|
+
alpha = metric == METRIC_L2 ? 1.2f : 0.95f;
|
|
71
|
+
|
|
72
|
+
// Validate the requested storage kind is available in current runtime.
|
|
73
|
+
// NB: LVQ/LeanVec are only available on Intel(R) hardware AND when using
|
|
74
|
+
// a build based on LVQ/LeanVec-enabled SVS.
|
|
75
|
+
auto svs_storage = to_svs_storage_kind(storage_kind);
|
|
76
|
+
auto status =
|
|
77
|
+
svs_runtime::DynamicVamanaIndex::check_storage_kind(svs_storage);
|
|
78
|
+
if (!status.ok()) {
|
|
79
|
+
FAISS_THROW_MSG(status.message());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
bool IndexSVSVamana::is_lvq_leanvec_enabled() {
|
|
84
|
+
auto lvq = to_svs_storage_kind(SVS_LVQ4x0);
|
|
85
|
+
auto status = svs_runtime::DynamicVamanaIndex::check_storage_kind(lvq);
|
|
86
|
+
if (!status.ok()) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
auto leanvec = to_svs_storage_kind(SVS_LeanVec4x4);
|
|
90
|
+
status = svs_runtime::DynamicVamanaIndex::check_storage_kind(leanvec);
|
|
91
|
+
if (!status.ok()) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
IndexSVSVamana::~IndexSVSVamana() {
|
|
98
|
+
if (impl) {
|
|
99
|
+
auto status = svs_runtime::DynamicVamanaIndex::destroy(impl);
|
|
100
|
+
FAISS_ASSERT(status.ok());
|
|
101
|
+
impl = nullptr;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void IndexSVSVamana::add(idx_t n, const float* x) {
|
|
106
|
+
if (!impl) {
|
|
107
|
+
create_impl();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
std::vector<size_t> labels(n);
|
|
111
|
+
std::iota(labels.begin(), labels.end(), ntotal);
|
|
112
|
+
|
|
113
|
+
auto status = impl->add(n, labels.data(), x);
|
|
114
|
+
if (!status.ok()) {
|
|
115
|
+
FAISS_THROW_MSG(status.message());
|
|
116
|
+
}
|
|
117
|
+
ntotal += n;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void IndexSVSVamana::reset() {
|
|
121
|
+
if (impl) {
|
|
122
|
+
impl->reset();
|
|
123
|
+
}
|
|
124
|
+
is_trained = false;
|
|
125
|
+
ntotal = 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void IndexSVSVamana::search(
|
|
129
|
+
idx_t n,
|
|
130
|
+
const float* x,
|
|
131
|
+
idx_t k,
|
|
132
|
+
float* distances,
|
|
133
|
+
idx_t* labels,
|
|
134
|
+
const SearchParameters* params) const {
|
|
135
|
+
if (!impl) {
|
|
136
|
+
for (idx_t i = 0; i < n; ++i) {
|
|
137
|
+
distances[i] = std::numeric_limits<float>::infinity();
|
|
138
|
+
labels[i] = -1;
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
FAISS_THROW_IF_NOT(k > 0);
|
|
143
|
+
FAISS_THROW_IF_NOT(is_trained);
|
|
144
|
+
|
|
145
|
+
auto sp = make_search_parameters(*this, params);
|
|
146
|
+
auto id_filter = make_faiss_id_filter(params);
|
|
147
|
+
auto status = impl->search(
|
|
148
|
+
static_cast<size_t>(n),
|
|
149
|
+
x,
|
|
150
|
+
static_cast<size_t>(k),
|
|
151
|
+
distances,
|
|
152
|
+
convert_output_buffer<size_t>(labels, static_cast<size_t>(n * k)),
|
|
153
|
+
&sp,
|
|
154
|
+
id_filter.get());
|
|
155
|
+
|
|
156
|
+
if (!status.ok()) {
|
|
157
|
+
FAISS_THROW_MSG(status.message());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void IndexSVSVamana::range_search(
|
|
162
|
+
idx_t n,
|
|
163
|
+
const float* x,
|
|
164
|
+
float radius,
|
|
165
|
+
RangeSearchResult* result,
|
|
166
|
+
const SearchParameters* params) const {
|
|
167
|
+
FAISS_THROW_IF_NOT(impl);
|
|
168
|
+
FAISS_THROW_IF_NOT(radius > 0);
|
|
169
|
+
FAISS_THROW_IF_NOT(is_trained);
|
|
170
|
+
FAISS_THROW_IF_NOT(result->nq == static_cast<size_t>(n));
|
|
171
|
+
|
|
172
|
+
auto sp = make_search_parameters(*this, params);
|
|
173
|
+
auto id_filter = make_faiss_id_filter(params);
|
|
174
|
+
auto status = impl->range_search(
|
|
175
|
+
static_cast<size_t>(n),
|
|
176
|
+
x,
|
|
177
|
+
radius,
|
|
178
|
+
FaissResultsAllocator{result},
|
|
179
|
+
&sp,
|
|
180
|
+
id_filter.get());
|
|
181
|
+
if (!status.ok()) {
|
|
182
|
+
FAISS_THROW_MSG(status.message());
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
size_t IndexSVSVamana::remove_ids(const IDSelector& sel) {
|
|
187
|
+
FAISS_THROW_IF_NOT(impl);
|
|
188
|
+
auto id_filter = FaissIDFilter{sel};
|
|
189
|
+
size_t removed = 0;
|
|
190
|
+
auto Status = impl->remove_selected(&removed, id_filter);
|
|
191
|
+
ntotal -= removed;
|
|
192
|
+
return removed;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
void IndexSVSVamana::create_impl() {
|
|
196
|
+
FAISS_THROW_IF_NOT(!impl);
|
|
197
|
+
ntotal = 0;
|
|
198
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
199
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
200
|
+
auto build_params = svs_runtime::VamanaIndex::BuildParams{
|
|
201
|
+
.graph_max_degree = graph_max_degree,
|
|
202
|
+
.prune_to = prune_to,
|
|
203
|
+
.alpha = alpha,
|
|
204
|
+
.construction_window_size = construction_window_size,
|
|
205
|
+
.max_candidate_pool_size = max_candidate_pool_size,
|
|
206
|
+
.use_full_search_history = use_full_search_history,
|
|
207
|
+
};
|
|
208
|
+
auto search_params = svs_runtime::VamanaIndex::SearchParams{
|
|
209
|
+
.search_window_size = search_window_size,
|
|
210
|
+
.search_buffer_capacity = search_buffer_capacity,
|
|
211
|
+
};
|
|
212
|
+
auto Status = svs_runtime::DynamicVamanaIndex::build(
|
|
213
|
+
&impl,
|
|
214
|
+
d,
|
|
215
|
+
svs_metric,
|
|
216
|
+
svs_storage_kind,
|
|
217
|
+
build_params,
|
|
218
|
+
search_params);
|
|
219
|
+
if (!Status.ok()) {
|
|
220
|
+
FAISS_THROW_MSG(Status.message());
|
|
221
|
+
}
|
|
222
|
+
FAISS_THROW_IF_NOT(impl);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void IndexSVSVamana::serialize_impl(std::ostream& out) const {
|
|
226
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
227
|
+
impl, "Cannot serialize: SVS index not initialized.");
|
|
228
|
+
|
|
229
|
+
auto status = impl->save(out);
|
|
230
|
+
if (!status.ok()) {
|
|
231
|
+
FAISS_THROW_MSG(status.message());
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
void IndexSVSVamana::deserialize_impl(std::istream& in) {
|
|
236
|
+
FAISS_THROW_IF_MSG(impl, "Cannot deserialize: SVS index already loaded.");
|
|
237
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
238
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
239
|
+
auto status = impl->load(&impl, in, svs_metric, svs_storage_kind);
|
|
240
|
+
if (!status.ok()) {
|
|
241
|
+
FAISS_THROW_MSG(status.message());
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
} // namespace faiss
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <faiss/Index.h>
|
|
27
|
+
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
28
|
+
|
|
29
|
+
#include <svs/runtime/api_defs.h>
|
|
30
|
+
|
|
31
|
+
#include <iostream>
|
|
32
|
+
|
|
33
|
+
namespace faiss {
|
|
34
|
+
|
|
35
|
+
struct SearchParametersSVSVamana : public SearchParameters {
|
|
36
|
+
size_t search_window_size = 0;
|
|
37
|
+
size_t search_buffer_capacity = 0;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// redefinition for swig export
|
|
41
|
+
enum SVSStorageKind {
|
|
42
|
+
SVS_FP32,
|
|
43
|
+
SVS_FP16,
|
|
44
|
+
SVS_SQI8,
|
|
45
|
+
SVS_LVQ4x0,
|
|
46
|
+
SVS_LVQ4x4,
|
|
47
|
+
SVS_LVQ4x8,
|
|
48
|
+
SVS_LeanVec4x4,
|
|
49
|
+
SVS_LeanVec4x8,
|
|
50
|
+
SVS_LeanVec8x8,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) {
|
|
54
|
+
switch (kind) {
|
|
55
|
+
case SVS_FP32:
|
|
56
|
+
return svs_runtime::StorageKind::FP32;
|
|
57
|
+
case SVS_FP16:
|
|
58
|
+
return svs_runtime::StorageKind::FP16;
|
|
59
|
+
case SVS_SQI8:
|
|
60
|
+
return svs_runtime::StorageKind::SQI8;
|
|
61
|
+
case SVS_LVQ4x0:
|
|
62
|
+
return svs_runtime::StorageKind::LVQ4x0;
|
|
63
|
+
case SVS_LVQ4x4:
|
|
64
|
+
return svs_runtime::StorageKind::LVQ4x4;
|
|
65
|
+
case SVS_LVQ4x8:
|
|
66
|
+
return svs_runtime::StorageKind::LVQ4x8;
|
|
67
|
+
case SVS_LeanVec4x4:
|
|
68
|
+
return svs_runtime::StorageKind::LeanVec4x4;
|
|
69
|
+
case SVS_LeanVec4x8:
|
|
70
|
+
return svs_runtime::StorageKind::LeanVec4x8;
|
|
71
|
+
case SVS_LeanVec8x8:
|
|
72
|
+
return svs_runtime::StorageKind::LeanVec8x8;
|
|
73
|
+
default:
|
|
74
|
+
FAISS_ASSERT(!"not supported SVS storage kind");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
struct IndexSVSVamana : Index {
|
|
79
|
+
size_t graph_max_degree;
|
|
80
|
+
size_t prune_to;
|
|
81
|
+
float alpha = 1.2;
|
|
82
|
+
size_t search_window_size = 10;
|
|
83
|
+
size_t search_buffer_capacity = 10;
|
|
84
|
+
size_t construction_window_size = 40;
|
|
85
|
+
size_t max_candidate_pool_size = 200;
|
|
86
|
+
bool use_full_search_history = true;
|
|
87
|
+
|
|
88
|
+
SVSStorageKind storage_kind;
|
|
89
|
+
|
|
90
|
+
IndexSVSVamana();
|
|
91
|
+
|
|
92
|
+
IndexSVSVamana(
|
|
93
|
+
idx_t d,
|
|
94
|
+
size_t degree,
|
|
95
|
+
MetricType metric = METRIC_L2,
|
|
96
|
+
SVSStorageKind storage = SVSStorageKind::SVS_FP32);
|
|
97
|
+
|
|
98
|
+
~IndexSVSVamana() override;
|
|
99
|
+
|
|
100
|
+
// static member that exposes whether or not LVQ/LeanVec are enabled for
|
|
101
|
+
// this build and runtime.
|
|
102
|
+
static bool is_lvq_leanvec_enabled();
|
|
103
|
+
|
|
104
|
+
void add(idx_t n, const float* x) override;
|
|
105
|
+
|
|
106
|
+
void search(
|
|
107
|
+
idx_t n,
|
|
108
|
+
const float* x,
|
|
109
|
+
idx_t k,
|
|
110
|
+
float* distances,
|
|
111
|
+
idx_t* labels,
|
|
112
|
+
const SearchParameters* params = nullptr) const override;
|
|
113
|
+
|
|
114
|
+
void range_search(
|
|
115
|
+
idx_t n,
|
|
116
|
+
const float* x,
|
|
117
|
+
float radius,
|
|
118
|
+
RangeSearchResult* result,
|
|
119
|
+
const SearchParameters* params = nullptr) const override;
|
|
120
|
+
|
|
121
|
+
size_t remove_ids(const IDSelector& sel) override;
|
|
122
|
+
|
|
123
|
+
void reset() override;
|
|
124
|
+
|
|
125
|
+
/* Serialization and deserialization helpers */
|
|
126
|
+
void serialize_impl(std::ostream& out) const;
|
|
127
|
+
virtual void deserialize_impl(std::istream& in);
|
|
128
|
+
|
|
129
|
+
/* The actual SVS implementation */
|
|
130
|
+
svs_runtime::DynamicVamanaIndex* impl{nullptr};
|
|
131
|
+
|
|
132
|
+
protected:
|
|
133
|
+
/* Initializes the implementation*/
|
|
134
|
+
virtual void create_impl();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
} // namespace faiss
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <faiss/svs/IndexSVSVamanaLVQ.h>
|
|
25
|
+
|
|
26
|
+
namespace faiss {
|
|
27
|
+
|
|
28
|
+
IndexSVSVamanaLVQ::IndexSVSVamanaLVQ() : IndexSVSVamana() {
|
|
29
|
+
storage_kind = SVSStorageKind::SVS_LVQ4x0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
IndexSVSVamanaLVQ::IndexSVSVamanaLVQ(
|
|
33
|
+
idx_t d,
|
|
34
|
+
size_t degree,
|
|
35
|
+
MetricType metric,
|
|
36
|
+
SVSStorageKind storage)
|
|
37
|
+
: IndexSVSVamana(d, degree, metric, storage) {}
|
|
38
|
+
|
|
39
|
+
} // namespace faiss
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <faiss/svs/IndexSVSVamana.h>
|
|
27
|
+
|
|
28
|
+
namespace faiss {
|
|
29
|
+
|
|
30
|
+
struct IndexSVSVamanaLVQ : IndexSVSVamana {
|
|
31
|
+
IndexSVSVamanaLVQ();
|
|
32
|
+
|
|
33
|
+
IndexSVSVamanaLVQ(
|
|
34
|
+
idx_t d,
|
|
35
|
+
size_t degree,
|
|
36
|
+
MetricType metric = METRIC_L2,
|
|
37
|
+
SVSStorageKind storage = SVSStorageKind::SVS_LVQ4x4);
|
|
38
|
+
|
|
39
|
+
~IndexSVSVamanaLVQ() override = default;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} // namespace faiss
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <faiss/svs/IndexSVSFaissUtils.h>
|
|
25
|
+
#include <faiss/svs/IndexSVSVamanaLeanVec.h>
|
|
26
|
+
|
|
27
|
+
#include <svs/runtime/dynamic_vamana_index.h>
|
|
28
|
+
#include <svs/runtime/training.h>
|
|
29
|
+
#include <svs/runtime/vamana_index.h>
|
|
30
|
+
|
|
31
|
+
#include <memory>
|
|
32
|
+
#include <span>
|
|
33
|
+
#include "faiss/svs/IndexSVSVamana.h"
|
|
34
|
+
|
|
35
|
+
namespace faiss {
|
|
36
|
+
|
|
37
|
+
IndexSVSVamanaLeanVec::IndexSVSVamanaLeanVec() : IndexSVSVamana() {
|
|
38
|
+
is_trained = false;
|
|
39
|
+
storage_kind = SVSStorageKind::SVS_LeanVec4x4;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
IndexSVSVamanaLeanVec::IndexSVSVamanaLeanVec(
|
|
43
|
+
idx_t d,
|
|
44
|
+
size_t degree,
|
|
45
|
+
MetricType metric,
|
|
46
|
+
size_t leanvec_dims,
|
|
47
|
+
SVSStorageKind storage_kind)
|
|
48
|
+
: IndexSVSVamana(d, degree, metric, storage_kind) {
|
|
49
|
+
is_trained = false;
|
|
50
|
+
leanvec_d = leanvec_dims == 0 ? d / 2 : leanvec_dims;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
IndexSVSVamanaLeanVec::~IndexSVSVamanaLeanVec() {
|
|
54
|
+
if (training_data) {
|
|
55
|
+
auto status = svs_runtime::LeanVecTrainingData::destroy(training_data);
|
|
56
|
+
FAISS_ASSERT(status.ok());
|
|
57
|
+
training_data = nullptr;
|
|
58
|
+
}
|
|
59
|
+
IndexSVSVamana::~IndexSVSVamana();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void IndexSVSVamanaLeanVec::add(idx_t n, const float* x) {
|
|
63
|
+
FAISS_THROW_IF_MSG(
|
|
64
|
+
!is_trained, "Index not trained: call train() before add().");
|
|
65
|
+
IndexSVSVamana::add(n, x);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void IndexSVSVamanaLeanVec::train(idx_t n, const float* x) {
|
|
69
|
+
FAISS_THROW_IF_MSG(
|
|
70
|
+
training_data || impl, "Index already trained or contains data.");
|
|
71
|
+
|
|
72
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
73
|
+
IndexSVSVamana::is_lvq_leanvec_enabled(),
|
|
74
|
+
"LVQ/LeanVec support not available on this platform or build");
|
|
75
|
+
|
|
76
|
+
auto status = svs_runtime::LeanVecTrainingData::build(
|
|
77
|
+
&training_data, d, n, x, leanvec_d);
|
|
78
|
+
if (!status.ok()) {
|
|
79
|
+
FAISS_THROW_MSG(status.message());
|
|
80
|
+
}
|
|
81
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
82
|
+
training_data, "Failed to build leanvec training info.");
|
|
83
|
+
is_trained = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void IndexSVSVamanaLeanVec::serialize_training_data(std::ostream& out) const {
|
|
87
|
+
FAISS_THROW_IF_NOT_MSG(
|
|
88
|
+
training_data, "Cannot serialize: Training data not initialized.");
|
|
89
|
+
|
|
90
|
+
auto status = training_data->save(out);
|
|
91
|
+
if (!status.ok()) {
|
|
92
|
+
FAISS_THROW_MSG(status.message());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void IndexSVSVamanaLeanVec::deserialize_training_data(std::istream& in) {
|
|
97
|
+
svs_runtime::LeanVecTrainingData* tdata = nullptr;
|
|
98
|
+
auto status = svs_runtime::LeanVecTrainingData::load(&tdata, in);
|
|
99
|
+
if (!status.ok()) {
|
|
100
|
+
FAISS_THROW_MSG(status.message());
|
|
101
|
+
}
|
|
102
|
+
FAISS_THROW_IF_NOT_MSG(tdata, "Failed to load leanvec training data.");
|
|
103
|
+
training_data = tdata;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void IndexSVSVamanaLeanVec::create_impl() {
|
|
107
|
+
ntotal = 0;
|
|
108
|
+
auto svs_metric = to_svs_metric(metric_type);
|
|
109
|
+
auto svs_storage_kind = to_svs_storage_kind(storage_kind);
|
|
110
|
+
auto build_params = svs_runtime::VamanaIndex::BuildParams{
|
|
111
|
+
.graph_max_degree = graph_max_degree,
|
|
112
|
+
.prune_to = prune_to,
|
|
113
|
+
.alpha = alpha,
|
|
114
|
+
.construction_window_size = construction_window_size,
|
|
115
|
+
.max_candidate_pool_size = max_candidate_pool_size,
|
|
116
|
+
.use_full_search_history = use_full_search_history,
|
|
117
|
+
};
|
|
118
|
+
auto search_params = svs_runtime::VamanaIndex::SearchParams{
|
|
119
|
+
.search_window_size = search_window_size,
|
|
120
|
+
.search_buffer_capacity = search_buffer_capacity,
|
|
121
|
+
};
|
|
122
|
+
auto status = svs_runtime::Status_Ok;
|
|
123
|
+
if (training_data) {
|
|
124
|
+
status = svs_runtime::DynamicVamanaIndexLeanVec::build(
|
|
125
|
+
&impl,
|
|
126
|
+
d,
|
|
127
|
+
svs_metric,
|
|
128
|
+
svs_storage_kind,
|
|
129
|
+
training_data,
|
|
130
|
+
build_params,
|
|
131
|
+
search_params);
|
|
132
|
+
} else {
|
|
133
|
+
status = svs_runtime::DynamicVamanaIndexLeanVec::build(
|
|
134
|
+
&impl,
|
|
135
|
+
d,
|
|
136
|
+
svs_metric,
|
|
137
|
+
svs_storage_kind,
|
|
138
|
+
leanvec_d,
|
|
139
|
+
build_params,
|
|
140
|
+
search_params);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!status.ok()) {
|
|
144
|
+
FAISS_THROW_MSG(status.message());
|
|
145
|
+
}
|
|
146
|
+
FAISS_THROW_IF_NOT(impl);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
} // namespace faiss
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Portions 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
|
+
/*
|
|
9
|
+
* Portions Copyright 2025 Intel Corporation
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#pragma once
|
|
25
|
+
|
|
26
|
+
#include <faiss/svs/IndexSVSVamana.h>
|
|
27
|
+
|
|
28
|
+
namespace faiss {
|
|
29
|
+
|
|
30
|
+
struct IndexSVSVamanaLeanVec : IndexSVSVamana {
|
|
31
|
+
IndexSVSVamanaLeanVec();
|
|
32
|
+
|
|
33
|
+
IndexSVSVamanaLeanVec(
|
|
34
|
+
idx_t d,
|
|
35
|
+
size_t degree,
|
|
36
|
+
MetricType metric = METRIC_L2,
|
|
37
|
+
size_t leanvec_dims = 0,
|
|
38
|
+
SVSStorageKind storage = SVSStorageKind::SVS_LeanVec4x4);
|
|
39
|
+
|
|
40
|
+
~IndexSVSVamanaLeanVec() override;
|
|
41
|
+
|
|
42
|
+
void add(idx_t n, const float* x) override;
|
|
43
|
+
|
|
44
|
+
void train(idx_t n, const float* x) override;
|
|
45
|
+
|
|
46
|
+
void serialize_training_data(std::ostream& out) const;
|
|
47
|
+
void deserialize_training_data(std::istream& in);
|
|
48
|
+
|
|
49
|
+
size_t leanvec_d;
|
|
50
|
+
|
|
51
|
+
/* Training information */
|
|
52
|
+
svs_runtime::LeanVecTrainingData* training_data{nullptr};
|
|
53
|
+
|
|
54
|
+
protected:
|
|
55
|
+
void create_impl() override;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace faiss
|
|
@@ -25,7 +25,7 @@ inline bool is_aligned_pointer(const void* x) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// class that manages suitably aligned arrays for SIMD
|
|
28
|
-
// T should be a
|
|
28
|
+
// T should be a POD type. The default alignment is 32 for AVX
|
|
29
29
|
template <class T, int A = 32>
|
|
30
30
|
struct AlignedTableTightAlloc {
|
|
31
31
|
T* ptr;
|
|
@@ -139,7 +139,7 @@ void HeapArray<C>::per_line_extrema(T* out_val, TI* out_ids) const {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
// explicit
|
|
142
|
+
// explicit instantiations
|
|
143
143
|
|
|
144
144
|
template struct HeapArray<CMin<float, int64_t>>;
|
|
145
145
|
template struct HeapArray<CMax<float, int64_t>>;
|
|
@@ -238,7 +238,7 @@ void merge_knn_results(
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
// explicit
|
|
241
|
+
// explicit instantiations
|
|
242
242
|
#define INSTANTIATE(C, distance_t) \
|
|
243
243
|
template void merge_knn_results<int64_t, C<distance_t, int>>( \
|
|
244
244
|
size_t, \
|