Skip to main content

get_or_compute

Function get_or_compute 

Source
pub async fn get_or_compute<F, Fut>(
    db: &MemoryDatabase,
    text: &str,
    compute_fn: F,
) -> Result<Vec<f32>, Error>
where F: FnOnce(&str) -> Fut, Fut: Future<Output = Result<Vec<f32>, Error>>,
Expand description

Get or compute an embedding, using the cache.

If the embedding is cached, returns it directly. Otherwise, calls compute_fn, caches the result, and returns it.