Skip to main content

Module dedup

Module dedup 

Source
Expand description

Request Deduplication

Prevents duplicate requests from being processed multiple times. Useful for cost savings when users accidentally submit the same request.

§Usage

use std::time::Duration;
use tokio_prompt_orchestrator::enhanced::{Deduplicator, DeduplicationResult};
let dedup = Deduplicator::new(Duration::from_secs(300)); // 5 minute window

// Check if request is duplicate
match dedup.check_and_register("prompt_hash").await {
    DeduplicationResult::New(token) => {
        // Process new request
        let result = process_request().await;
        dedup.complete(token, result).await;
    }
    DeduplicationResult::InProgress => {
        // Wait for in-progress request
        let _result = dedup.wait_for_result("prompt_hash").await;
    }
    DeduplicationResult::Cached(result) => {
        // Use cached result
        println!("{result}");
    }
}

Structs§

DeduplicationStats
A point-in-time snapshot of Deduplicator state.
DeduplicationToken
Ownership token issued when a new request is registered with the Deduplicator.
Deduplicator
In-process request deduplicator that coalesces identical concurrent requests and caches recently completed results.

Enums§

DeduplicationResult
Outcome of a Deduplicator::check_and_register call.

Constants§

DEDUP_CANCELLED_SENTINEL
Behavior on Drop

Functions§

cosine_similarity
Compute the cosine similarity between two dense vectors.
dedup_key
is_cancelled_result
Returns true if the dedup result string represents a cancellation signal.