diff --git a/faiss/impl/ResultHandler.h b/faiss/impl/ResultHandler.h index 270de8dcd6..713fe8e49f 100644 --- a/faiss/impl/ResultHandler.h +++ b/faiss/impl/ResultHandler.h @@ -12,8 +12,10 @@ #pragma once #include +#include #include #include +#include namespace faiss { @@ -504,7 +506,15 @@ struct RangeSearchBlockResultHandler : BlockResultHandler { void end() {} ~SingleResultHandler() { - pres.finalize(); + try { + // finalize the partial result + pres.finalize(); + } catch (const faiss::FaissException& e) { + // Do nothing if allocation fails in finalizing partial results. +#ifndef NDEBUG + std::cerr << e.what() << std::endl; +#endif + } } }; @@ -559,8 +569,15 @@ struct RangeSearchBlockResultHandler : BlockResultHandler { } ~RangeSearchBlockResultHandler() { - if (partial_results.size() > 0) { - RangeSearchPartialResult::merge(partial_results); + try { + if (partial_results.size() > 0) { + RangeSearchPartialResult::merge(partial_results); + } + } catch (const faiss::FaissException& e) { + // Do nothing if allocation fails in merge. +#ifndef NDEBUG + std::cerr << e.what() << std::endl; +#endif } } };