aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval/src/vespa/eval/eval/typed_cells.h1
-rw-r--r--searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp21
2 files changed, 20 insertions, 2 deletions
diff --git a/eval/src/vespa/eval/eval/typed_cells.h b/eval/src/vespa/eval/eval/typed_cells.h
index 6cb8675cd5f..3dd8c30a3a9 100644
--- a/eval/src/vespa/eval/eval/typed_cells.h
+++ b/eval/src/vespa/eval/eval/typed_cells.h
@@ -36,6 +36,7 @@ struct TypedCells {
TypedCells(const TypedCells &other) noexcept = default;
TypedCells & operator= (TypedCells &&other) noexcept = default;
TypedCells & operator= (const TypedCells &other) noexcept = default;
+ bool valid() const noexcept { return size != 0; }
};
} // namespace
diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp
index bf62fcdaa23..7b42fd9a0e1 100644
--- a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp
@@ -303,12 +303,29 @@ HnswIndex<type>::remove_link_to(uint32_t remove_from, uint32_t remove_id, uint32
_graph.set_link_array(remove_from, level, new_links);
}
+namespace {
+
+double
+calc_distance_helper(const BoundDistanceFunction &df, vespalib::eval::TypedCells rhs)
+{
+ if (!rhs.valid()) [[unlikely]] {
+ /*
+ * We are in a read thread and the write thread has removed the
+ * tensor.
+ */
+ return std::numeric_limits<double>::max();
+ }
+ return df.calc(rhs);
+}
+
+}
+
template <HnswIndexType type>
double
HnswIndex<type>::calc_distance(const BoundDistanceFunction &df, uint32_t rhs_nodeid) const
{
auto rhs = get_vector(rhs_nodeid);
- return df.calc(rhs);
+ return calc_distance_helper(df, rhs);
}
template <HnswIndexType type>
@@ -316,7 +333,7 @@ double
HnswIndex<type>::calc_distance(const BoundDistanceFunction &df, uint32_t rhs_docid, uint32_t rhs_subspace) const
{
auto rhs = get_vector(rhs_docid, rhs_subspace);
- return df.calc(rhs);
+ return calc_distance_helper(df, rhs);
}
template <HnswIndexType type>