1 Commits
Author SHA1 Message Date
Justin Gibbs 8008ca2a70 Fix deadly signal in to_svs_metric() for unsupported metrics (#5032)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5032

Convert supported metric type assert to throw in `to_svs_metric()` to
better support tests that expect exceptions when processing invalid input.

There are two vectors that reach `to_svs_metric()` with an unsupported
metric:

1. **Deserialization** (`deserialize_impl()`):
   A invalid binary index with fourcc `"IBFf"`
   (IndexBinaryFromFloat) wrapping an SVS float index (`"ISVF"`,
   `"ILVQ"`, etc.) can carry any valid `MetricType` in the
   serialized stream. When the metric is not L2 or INNER_PRODUCT,
   `to_svs_metric()` is called with the unsupported value during
   `deserialize_impl()`.

2. **Programmatic construction** (`create_impl()`):
   Creating an SVS index (e.g., `IndexSVSFlat`) with an unsupported
   metric and calling `add()` triggers `create_impl()` which calls
   `to_svs_metric()`. This is a user-error path.

Reviewed By: mnorris11

Differential Revision: D99336458

fbshipit-source-id: ee5449b72e957a5e7eb77f651471f84c34e5c122
2026-04-03 15:08:59 -07:00