Skip to main content

load_from_file

Function load_from_file 

Source
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:

  1. File-size pre-check — the file is stat’d before any deserialization; if it exceeds [MAX_HNSW_BYTES] the call returns Err immediately.
  2. 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 Err rather than an allocator abort.

The magic / version header is validated before the unbounded body is touched, so corrupt non-HNSW files are rejected cheaply.