Better handling of errors during add, search, and save

This commit is contained in:
Robert Schulze 2024-08-09 10:48:00 +00:00
parent e7c2bf49c3
commit f944ef25bb
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A

View File

@ -64,7 +64,9 @@ void USearchIndexWithSerialization<Metric>::serialize(WriteBuffer & ostr) const
return true; return true;
}; };
Base::save_to_stream(callback); auto result = Base::save_to_stream(callback);
if (result.error)
throw Exception::createRuntime(ErrorCodes::INCORRECT_DATA, "Could not save USearch index, error: " + String(result.error.release()));
} }
template <unum::usearch::metric_kind_t Metric> template <unum::usearch::metric_kind_t Metric>
@ -212,7 +214,7 @@ void MergeTreeIndexAggregatorUSearch<Metric>::update(const Block & block, size_t
{ {
auto rc = index->add(static_cast<uint32_t>(index->size()), &column_array_data_float_data[column_array_offsets[current_row - 1]]); auto rc = index->add(static_cast<uint32_t>(index->size()), &column_array_data_float_data[column_array_offsets[current_row - 1]]);
if (!rc) if (!rc)
throw Exception::createRuntime(ErrorCodes::INCORRECT_DATA, rc.error.release()); throw Exception::createRuntime(ErrorCodes::INCORRECT_DATA, "Could not add data to USearch index, error: " + String(rc.error.release()));
ProfileEvents::increment(ProfileEvents::USearchAddCount); ProfileEvents::increment(ProfileEvents::USearchAddCount);
ProfileEvents::increment(ProfileEvents::USearchAddVisitedMembers, rc.visited_members); ProfileEvents::increment(ProfileEvents::USearchAddVisitedMembers, rc.visited_members);
@ -274,6 +276,8 @@ std::vector<size_t> MergeTreeIndexConditionUSearch::getUsefulRangesImpl(MergeTre
ann_condition.getDimensions(), index->dimensions()); ann_condition.getDimensions(), index->dimensions());
auto result = index->search(reference_vector.data(), limit); auto result = index->search(reference_vector.data(), limit);
if (result.error)
throw Exception::createRuntime(ErrorCodes::INCORRECT_DATA, "Could not search in USearch index, error: " + String(result.error.release()));
ProfileEvents::increment(ProfileEvents::USearchSearchCount); ProfileEvents::increment(ProfileEvents::USearchSearchCount);
ProfileEvents::increment(ProfileEvents::USearchSearchVisitedMembers, result.visited_members); ProfileEvents::increment(ProfileEvents::USearchSearchVisitedMembers, result.visited_members);