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§
- Deduplication
Stats - A point-in-time snapshot of
Deduplicatorstate. - Deduplication
Token - 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§
- Deduplication
Result - Outcome of a
Deduplicator::check_and_registercall.
Constants§
- DEDUP_
CANCELLED_ SENTINEL - Behavior on Drop
Functions§
- cosine_
similarity - Compute the cosine similarity between two dense vectors.
- dedup_
key - is_
cancelled_ result - Returns
trueif the dedup result string represents a cancellation signal.