pub struct ContextWindowStrategy { /* private fields */ }Expand description
Grounding strategy that limits injected context to a token budget.
Uses a simple 4-chars-per-token heuristic. Documents are added in order until the budget would be exceeded.
§Example
use traitclaw_rag::{Document, GroundingStrategy};
use traitclaw_rag::hybrid::ContextWindowStrategy;
let large_doc = Document::new("d1", &"word ".repeat(1000));
let strategy = ContextWindowStrategy::new(50); // very small budget
let ctx = strategy.ground(&[large_doc]);
// Context is truncated to fit budget
assert!(ctx.chars().count() < 400); // 50 tokens * 4 chars eachImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContextWindowStrategy
impl RefUnwindSafe for ContextWindowStrategy
impl Send for ContextWindowStrategy
impl Sync for ContextWindowStrategy
impl Unpin for ContextWindowStrategy
impl UnsafeUnpin for ContextWindowStrategy
impl UnwindSafe for ContextWindowStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more