pub struct RecallQueryShape {
pub original_tokens: usize,
pub sent_tokens: usize,
pub sent_tokens_max: usize,
pub budget_tokens: usize,
pub envelope_stripped: bool,
pub units_dropped: usize,
}Expand description
What shaping did to the recall query before it was embedded (#4972).
Why: the query used to go to the embedder whole and come back cut at the
512-token window with “no warning, no metric, and no signal to the caller”
— the defect as filed. This struct is the metric. It rides the enriched-
prompt log line, which is the same corpus the 52%-over-window rate was
measured from, so the rate after the fix is two jq filters away:
select(.recall_query.units_dropped > 0) for queries this module reduced,
and select(.recall_query.sent_tokens_max > .recall_query.budget_tokens) for
sends whose fit inside the window could not be proven.
What: token estimates before and after shaping, the ceiling on what was
sent, the budget in force, and what was removed. Absent from the JSON when
no palace was resolved and no recall was attempted.
Test: single_event_roundtrip covers serialisation;
prompt_context::tests::over_window_query_is_reduced_to_whole_units covers
the values.
Fields§
§original_tokens: usizeEstimated tokens in the raw prompt, before any shaping.
sent_tokens: usizeEstimated tokens actually sent to /recall.
sent_tokens_max: usizeUpper bound on the true tokens sent (#4972).
Why: sent_tokens charges ASCII-letter runs by a calibrated divisor,
which no divisor above 1 token per character can make a bound. Without
this field a shape reporting sent_tokens: 490, units_dropped: 0 asserts
a clean pass on a query the embedder may have cut — the metric reading
healthy while the loss happens.
What: prompt_context::query::max_tokens of the sent text.
#[serde(default)] so log lines written before this field parse back.
budget_tokens: usizeToken budget in force for this firing.
envelope_stripped: boolWhether a task-notification envelope was reduced to its payload.
units_dropped: usizeWhole units (lines, or words) dropped to fit the budget. On the last-resort character path the unit is the character.
Implementations§
Source§impl RecallQueryShape
impl RecallQueryShape
Sourcepub fn reshaped(&self) -> bool
pub fn reshaped(&self) -> bool
True when shaping changed the query the embedder saw.
Why: the pass-through case is the common one and must stay quiet — a
warn on every firing is a warn nobody reads.
What: envelope_stripped || units_dropped > 0.
Test: prompt_context::tests::short_query_passes_through_untouched.
Sourcepub fn may_exceed_window(&self) -> bool
pub fn may_exceed_window(&self) -> bool
True when the sent query is not provably inside the embedder window.
Why (#4972, round-3 review): sent_tokens <= budget_tokens is an
estimate clearing a budget, not a proof, and treating it as one is what
let a reshaped query still overrun the window while the log reported the
reduction as a success. This is the honest complement — false means the
send fits, full stop; true means it may have been cut and the shape
declines to claim otherwise.
What: sent_tokens_max > budget_tokens.
Test: prompt_context::tests::shape_flags_a_send_it_cannot_prove_fits.
Trait Implementations§
Source§impl Clone for RecallQueryShape
impl Clone for RecallQueryShape
Source§impl Debug for RecallQueryShape
impl Debug for RecallQueryShape
Source§impl Default for RecallQueryShape
impl Default for RecallQueryShape
Source§impl<'de> Deserialize<'de> for RecallQueryShape
impl<'de> Deserialize<'de> for RecallQueryShape
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RecallQueryShape
Source§impl PartialEq for RecallQueryShape
impl PartialEq for RecallQueryShape
Source§impl Serialize for RecallQueryShape
impl Serialize for RecallQueryShape
impl StructuralPartialEq for RecallQueryShape
Auto Trait Implementations§
impl Freeze for RecallQueryShape
impl RefUnwindSafe for RecallQueryShape
impl Send for RecallQueryShape
impl Sync for RecallQueryShape
impl Unpin for RecallQueryShape
impl UnsafeUnpin for RecallQueryShape
impl UnwindSafe for RecallQueryShape
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more