@@ -35,9 +35,7 @@ struct NumericIndex : public BaseIndex {
35
35
36
36
std::vector<DocId> Range (double l, double r) const ;
37
37
38
- std::optional<std::vector<DocId>> GetAllResults () const override {
39
- return Range (-std::numeric_limits<double >::infinity (), std::numeric_limits<double >::infinity ());
40
- }
38
+ std::vector<DocId> GetAllDocsWithNonNullValues () const override ;
41
39
42
40
private:
43
41
using Entry = std::pair<double , DocId>;
@@ -62,19 +60,7 @@ template <typename C> struct BaseStringIndex : public BaseIndex {
62
60
// Returns all the terms that appear as keys in the reverse index.
63
61
std::vector<std::string> GetTerms () const ;
64
62
65
- std::optional<std::vector<DocId>> GetAllResults () const override {
66
- absl::flat_hash_set<DocId> unique_docs;
67
-
68
- for (const auto & [term, container] : entries_) {
69
- for (const DocId& id : container) {
70
- unique_docs.insert (id);
71
- }
72
- }
73
-
74
- auto result = std::vector<DocId>(unique_docs.begin (), unique_docs.end ());
75
- std::sort (result.begin (), result.end ());
76
- return result;
77
- }
63
+ std::vector<DocId> GetAllDocsWithNonNullValues () const override ;
78
64
79
65
protected:
80
66
using StringList = DocumentAccessor::StringList;
@@ -152,31 +138,7 @@ struct FlatVectorIndex : public BaseVectorIndex {
152
138
const float * Get (DocId doc) const ;
153
139
154
140
// Return all documents that have vectors in this index
155
- std::optional<std::vector<DocId>> GetAllResults () const override {
156
- std::vector<DocId> result;
157
- size_t num_vectors = entries_.size () / dim_;
158
- result.reserve (num_vectors);
159
-
160
- for (DocId id = 0 ; id < num_vectors; ++id) {
161
- // Check if the vector is not zero (all elements are 0)
162
- // TODO: Valid vector can contain 0s, we should use a better approach
163
- const float * vec = Get (id);
164
- bool is_zero_vector = true ;
165
-
166
- for (size_t i = 0 ; i < dim_; ++i) {
167
- if (vec[i] != 0 .0f ) {
168
- is_zero_vector = false ;
169
- break ;
170
- }
171
- }
172
-
173
- if (!is_zero_vector) {
174
- result.push_back (id);
175
- }
176
- }
177
-
178
- return result;
179
- }
141
+ std::vector<DocId> GetAllDocsWithNonNullValues () const override ;
180
142
181
143
protected:
182
144
void AddVector (DocId id, const VectorPtr& vector) override ;
@@ -187,10 +149,6 @@ struct FlatVectorIndex : public BaseVectorIndex {
187
149
188
150
struct HnswlibAdapter ;
189
151
190
- // This index does't have GetAllResults method
191
- // because it's not possible to get all vectors from the index
192
- // It depends on the Hnswlib implementation
193
- // TODO: Consider adding GetAllResults method in the future
194
152
struct HnswVectorIndex : public BaseVectorIndex {
195
153
HnswVectorIndex (const SchemaField::VectorParams& params, PMR_NS::memory_resource* mr);
196
154
~HnswVectorIndex ();
@@ -201,6 +159,11 @@ struct HnswVectorIndex : public BaseVectorIndex {
201
159
std::vector<std::pair<float , DocId>> Knn (float * target, size_t k, std::optional<size_t > ef,
202
160
const std::vector<DocId>& allowed) const ;
203
161
162
+ // TODO: Implement if needed
163
+ std::vector<DocId> GetAllDocsWithNonNullValues () const override {
164
+ return std::vector<DocId>{};
165
+ }
166
+
204
167
protected:
205
168
void AddVector (DocId id, const VectorPtr& vector) override ;
206
169
0 commit comments