RyanCodrai/turbovec · error

{e}

Error message

{e}

What it means

search_with_mask is the panicking form of the masked search: it calls try_search_with_mask and panics with the error's Display on failure. Errors include QueryBufferNotMultipleOfDim (query buffer length not a multiple of dim) and InvalidQueryValue (NaN/inf/huge coordinates).

Source

Thrown at turbovec/src/lib.rs:1302

    /// As with [`Self::search`], none of the three can fire on an index
    /// with no committed `dim` — that case returns the empty result
    /// before any validation. Use [`Self::try_search_with_mask`] for the
    /// non-panicking form.
    pub fn search_with_mask(
        &self,
        queries: &[f32],
        k: usize,
        mask: Option<&[bool]>,
    ) -> SearchResults {
        // Single source of validation: the checked form below owns all
        // three conditions, and this one turns them back into panics.
        // Re-validating here instead would run `first_invalid_coord`'s
        // O(nq·dim) scan twice per query batch. The payload is now the
        // error's `Display` rather than an `assert_eq!` rendering, so
        // three of the four sites report differently than they did —
        // see `try_search_with_mask` for the before/after.
        self.try_search_with_mask(queries, k, mask)
            .unwrap_or_else(|e| panic!("{e}"))
    }

    /// [`Self::search_with_mask`] as a `Result`: the non-panicking form.
    ///
    /// Returns [`SearchError::QueryBufferNotMultipleOfDim`],
    /// [`SearchError::InvalidQueryValue`], or
    /// [`SearchError::MaskLengthMismatch`]. On success the result is
    /// exactly what `search_with_mask` would have returned.
    ///
    /// `search_with_mask` now calls this function and panics with the
    /// error's `Display` text, so the two forms cannot diverge in what
    /// they detect: the conditions, the order they are checked in and
    /// the results returned are all exactly as before.
    ///
    /// The panic *text* did change at three of the four sites, which
    /// were previously raised by `assert_eq!` and now carry the error's
    /// `Display` alone. (Four sites, three conditions: the mask-length
    /// check has one site for an empty index and one for a populated

View on GitHub (pinned to ccab9f325e)

Solutions

  1. Switch to try_search_with_mask, the Result-returning non-panicking form, and match on SearchError.
  2. Assert queries.len() % dim == 0 before the call and trim partial vectors.
  3. Validate query coordinates are finite and |v| < 1e16 before searching.

Example fix

// before
let hits = index.search_with_mask(&queries, 10, Some(&mask)); // panics
// after
assert_eq!(queries.len() % dim, 0, "query buffer not multiple of dim");
let hits = index.try_search_with_mask(&queries, 10, Some(&mask)).unwrap_or_default();
Defensive patterns

Strategy: validation

Validate before calling

debug_assert_eq!(queries.len() % dim, 0, "query buffer not multiple of dim");
debug_assert!(queries.iter().all(|v| v.is_finite() && v.abs() < 1e16));

Type guard

fn queries_ok(q: &[f32], dim: usize) -> bool {
    q.len() % dim == 0 && q.iter().all(|v| v.is_finite() && v.abs() < 1e16)
}

Try / catch

// use the non-panicking form
let hits = index.try_search_with_mask(&queries, k, mask)
    .unwrap_or_else(|e| { warn("{e}"); Vec::new() });

Prevention

When it happens

Trigger: Calling search_with_mask(queries, k, mask) with queries.len() % dim != 0, or with a NaN/inf/|v|>=1e16 coordinate in the query buffer; also reached via search().

Common situations: Concatenated query batches with a trailing partial vector; queries built from a different-dimension embedding model than the index; corrupted or unnormalized query embeddings.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of RyanCodrai/turbovec@ccab9f325e (2026-09-06). Data as JSON: /api/errors/394ea5dfbc568ccf. Report an issue: GitHub.