|
31 | 31 | #include <svs/runtime/vamana_index.h> |
32 | 32 |
|
33 | 33 | #include <cstddef> |
| 34 | +#include <cstring> |
34 | 35 | #include <numeric> |
35 | 36 | #include <span> |
36 | 37 | #include <type_traits> |
@@ -114,13 +115,32 @@ void IndexSVSVamana::add(idx_t n, const float* x) { |
114 | 115 | if (!status.ok()) { |
115 | 116 | FAISS_THROW_MSG(status.message()); |
116 | 117 | } |
| 118 | + |
| 119 | + if (stored_vectors_valid) { |
| 120 | + size_t prev = static_cast<size_t>(ntotal) * d; |
| 121 | + stored_vectors.resize(prev + static_cast<size_t>(n) * d); |
| 122 | + std::memcpy(stored_vectors.data() + prev, x, sizeof(float) * n * d); |
| 123 | + } |
117 | 124 | ntotal += n; |
118 | 125 | } |
119 | 126 |
|
| 127 | +void IndexSVSVamana::reconstruct(idx_t key, float* recons) const { |
| 128 | + FAISS_THROW_IF_NOT_MSG( |
| 129 | + key >= 0 && key < ntotal, |
| 130 | + "IndexSVSVamana::reconstruct: key out of range"); |
| 131 | + FAISS_THROW_IF_NOT_MSG( |
| 132 | + stored_vectors_valid && !stored_vectors.empty(), |
| 133 | + "IndexSVSVamana::reconstruct: stored_vectors unavailable " |
| 134 | + "(invalidated by remove_ids or not restored after deserialization)"); |
| 135 | + std::memcpy(recons, stored_vectors.data() + key * d, sizeof(float) * d); |
| 136 | +} |
| 137 | + |
120 | 138 | void IndexSVSVamana::reset() { |
121 | 139 | if (impl) { |
122 | 140 | impl->reset(); |
123 | 141 | } |
| 142 | + stored_vectors.clear(); |
| 143 | + stored_vectors_valid = true; |
124 | 144 | is_trained = false; |
125 | 145 | ntotal = 0; |
126 | 146 | } |
@@ -189,6 +209,8 @@ size_t IndexSVSVamana::remove_ids(const IDSelector& sel) { |
189 | 209 | size_t removed = 0; |
190 | 210 | auto Status = impl->remove_selected(&removed, id_filter); |
191 | 211 | ntotal -= removed; |
| 212 | + stored_vectors.clear(); |
| 213 | + stored_vectors_valid = false; |
192 | 214 | return removed; |
193 | 215 | } |
194 | 216 |
|
|
0 commit comments