Skip to main content

probe_vector_size

Function probe_vector_size 

Source
pub async fn probe_vector_size<Fut, E>(
    embed_fut: Fut,
    timeout: Option<Duration>,
) -> Result<u64, ProbeError<E>>
where Fut: Future<Output = Result<Vec<f32>, E>>, E: Display,
Expand description

Learn an embedding provider’s output dimension.

Awaits embed_fut — the caller’s already-invoked embed call for a throwaway probe string — and returns the length of the resulting vector. When timeout is Some, the await is bounded by it; pass None to await unconditionally.

Taking the future itself (rather than a Fn(&str) -> Fut closure) sidesteps the higher-rank lifetime that a borrowing embed(&self, text: &str) call would otherwise require, and lets each caller keep its own probe string literal.

This function only performs the probe — pair the returned size with the caller’s own ensure_collection (or ensure_collection_with_quantization) call, since collection setup differs across call sites (plain vs. quantized, fixed vs. caller-supplied collection name).

§Errors

Returns ProbeError::Timeout if timeout elapses, or ProbeError::Embed if the probe call fails.

§Examples

use std::time::Duration;
use zeph_memory::embed_probe::probe_vector_size;

let embed_fut = async { Ok::<_, std::convert::Infallible>(vec![0.0_f32; 384]) };
let size = probe_vector_size(embed_fut, Some(Duration::from_secs(15))).await?;
assert_eq!(size, 384);