pub fn load_from_file(path: &Path) -> Result<HnswIndex>Expand description
Load an HnswIndex from the file at path.
Validates the file header (magic bytes and format version) before deserializing the index body.
§Security
Two guards prevent a corrupt or adversarial file from causing an OOM abort at startup:
- File-size pre-check — the file is stat’d before any deserialization;
if it exceeds [
MAX_HNSW_BYTES] the call returnsErrimmediately. - Bounded deserialization — bincode is configured with a byte limit
equal to the remaining file size after the header. This converts any
attempt to read more bytes than the file contains into a recoverable
Errrather than an allocator abort.
The magic / version header is validated before the unbounded body is touched, so corrupt non-HNSW files are rejected cheaply.