Skip to content

api: expose parameter validation helpers without constructing indexes #191

@Fieldnote-Echo

Description

Context

OrdinalDB validates dimensions, bit widths, finite inputs, mask lengths, and candidate IDs before calling ordvec. Today those invariants are embedded in constructors and methods as assert!/assert_eq!, so downstreams must duplicate the same rules to avoid panics.

#86 tracks broader Result-returning try_* APIs. This issue is narrower and complementary: expose validation helpers for static/index-shape invariants so DBs and bindings can preflight user input and produce their own error types without constructing temporary indexes or duplicating rules.

Evidence

  • RankQuant::new enforces bits {1,2,4}, dim >= 2, dim <= u16::MAX, dim % (8 / bits) == 0, and dim % (1 << bits) == 0: src/quant.rs:150-174.
  • Bitmap::new enforces dim % 64 == 0, dim <= MAX_DIM, and 0 < n_top < dim: src/bitmap.rs:50-65.
  • SignBitmap::new enforces nonzero dim, dim % 64 == 0, and dim <= MAX_SIGN_BITMAP_DIM: src/sign_bitmap.rs:60-67.
  • RankQuant::add validates row-major length and finite inputs: src/quant.rs:194-203.
  • RankQuant::search_asymmetric_subset validates query length, finite inputs, and candidate bounds with panics/asserts: src/quant.rs:547-564.

Proposed Shape

Sketch only:

pub fn validate_rankquant_params(dim: usize, bits: u8) -> Result<(), OrdvecError>;
pub fn validate_bitmap_params(dim: usize, n_top: usize) -> Result<(), OrdvecError>;
pub fn validate_signbitmap_dim(dim: usize) -> Result<(), OrdvecError>;
pub fn validate_flat_vectors_len(len: usize, dim: usize) -> Result<usize, OrdvecError>;
pub fn validate_candidate_ids(candidates: &[u32], n_vectors: usize) -> Result<(), OrdvecError>;

Equivalent method placement is fine, e.g. associated RankQuant::validate_params.

Acceptance Criteria

  • Public validation helpers return stable typed errors, not panics.
  • Helpers exactly match constructor/method invariants for RankQuant, Bitmap, and SignBitmap.
  • Tests assert each helper agrees with constructor acceptance/rejection across edge cases.
  • Helpers are usable without allocating an index.
  • Docs explain that panicking APIs remain available and try_* APIs from Result-returning try_add / try_search* (parallel to the panicking API) #86 can delegate to the same helpers.

Non-goals

  • Do not replace the current fail-loud API.
  • Do not add database-level validation for external IDs, masks, metadata predicates, or persistence bundles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-apiCore search/index public API surface (pre-1.0)enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions