Summary
The current contract panics on invalid input (wrong dimension, non-finite values, over-capacity). Fail-loud is correct default behaviour for a library and should stay. But callers feeding embeddings from an external model API can't practically catch panics.
Ask
Add a parallel, Result-returning API alongside (not replacing) the panicking one:
pub fn try_add(&mut self, vectors: &[f32]) -> Result<(), OrdvecError>;
pub fn try_search(&self, queries: &[f32], k: usize) -> Result<SearchResults, OrdvecError>;
pub fn try_search_asymmetric(&self, queries: &[f32], k: usize) -> Result<SearchResults, OrdvecError>;
Implement by hoisting the existing validation (assert_all_finite, dim checks, the util::checked_new_len capacity guard) into functions that return Err(OrdvecError::…) instead of panicking; the panicking methods delegate to the try_* form to avoid duplicated logic. Introduce a small OrdvecError enum (e.g. DimMismatch, NonFinite, CapacityExceeded).
Notes
- Towards 1.0.
- Mirrors the Python binding, which already turns these core panics into clean
ValueErrors — this would let the binding call the try_* path directly and would pair naturally with the C-ABI issue (error reporting across the boundary).
Filed from an external technical review (May 2026); verified against v0.2.0 (search methods currently return SearchResults, not Result).
Summary
The current contract panics on invalid input (wrong dimension, non-finite values, over-capacity). Fail-loud is correct default behaviour for a library and should stay. But callers feeding embeddings from an external model API can't practically catch panics.
Ask
Add a parallel,
Result-returning API alongside (not replacing) the panicking one:Implement by hoisting the existing validation (
assert_all_finite, dim checks, theutil::checked_new_lencapacity guard) into functions that returnErr(OrdvecError::…)instead of panicking; the panicking methods delegate to thetry_*form to avoid duplicated logic. Introduce a smallOrdvecErrorenum (e.g.DimMismatch,NonFinite,CapacityExceeded).Notes
ValueErrors — this would let the binding call thetry_*path directly and would pair naturally with the C-ABI issue (error reporting across the boundary).Filed from an external technical review (May 2026); verified against v0.2.0 (search methods currently return
SearchResults, notResult).