memory: collapse the duplicated corpus char limit #114
No files matched your search
+1
-11
@@ -40,10 +40,6 @@ use crate::memory::track::Track;
|
||||
use crate::tools::ToolContext;
|
||||
use crate::tools::ToolRegistry;
|
||||
|
||||
/// Maximum rendered L4u prompt size in characters. Matches the L4u and
|
||||
/// L3u budgets. Exceeded → hard error.
|
||||
const CORPUS_CHAR_LIMIT: usize = 800_000;
|
||||
|
||||
/// The date range covered by the chosen L4u file.
|
||||
pub type PeriodSpan = Span;
|
||||
|
||||
@@ -202,13 +198,7 @@ pub(crate) async fn decide_and_render(
|
||||
backend: &dyn ChatBackend,
|
||||
) -> Result<RenderOutcome> {
|
||||
let l4u_prompt = render_l4u_for_prompt(claims);
|
||||
if l4u_prompt.len() > CORPUS_CHAR_LIMIT {
|
||||
bail!(
|
||||
"L4u corpus is {} chars, exceeds limit of {}; windowing not yet supported",
|
||||
l4u_prompt.len(),
|
||||
CORPUS_CHAR_LIMIT
|
||||
);
|
||||
}
|
||||
crate::memory::check_corpus_size(&l4u_prompt, "L4u")?;
|
||||
info!(
|
||||
chars = l4u_prompt.len(),
|
||||
claims = claims.len(),
|
||||
|
||||
+3
-14
@@ -30,11 +30,6 @@ use crate::memory::track::Track;
|
||||
use crate::tools::ToolContext;
|
||||
use crate::tools::ToolRegistry;
|
||||
|
||||
/// Maximum rendered prompt size in characters. ~200k tokens worth, well
|
||||
/// under Kimi K2.6's 256k window. Exceeded → hard error (not a warning):
|
||||
/// the windowing strategy isn't designed yet.
|
||||
const CORPUS_CHAR_LIMIT: usize = 800_000;
|
||||
|
||||
/// A loaded L2 claim with its assigned L3u-input id.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct L2Entry {
|
||||
@@ -124,20 +119,14 @@ pub fn render_corpus_for_prompt(by_day: &[(NaiveDate, Vec<L2Entry>)]) -> String
|
||||
}
|
||||
|
||||
/// Run the L2 → L3u extraction in a single LLM call. Errors if the
|
||||
/// rendered corpus exceeds [`CORPUS_CHAR_LIMIT`].
|
||||
/// rendered corpus exceeds [`crate::memory::CORPUS_CHAR_LIMIT`].
|
||||
pub async fn extract(
|
||||
by_day: &[(NaiveDate, Vec<L2Entry>)],
|
||||
track: &Track,
|
||||
backend: &dyn ChatBackend,
|
||||
) -> Result<Vec<L3uClaim>> {
|
||||
let prompt = render_corpus_for_prompt(by_day);
|
||||
if prompt.len() > CORPUS_CHAR_LIMIT {
|
||||
bail!(
|
||||
"L2 corpus is {} chars, exceeds limit of {}; windowing not yet supported",
|
||||
prompt.len(),
|
||||
CORPUS_CHAR_LIMIT
|
||||
);
|
||||
}
|
||||
crate::memory::check_corpus_size(&prompt, "L2")?;
|
||||
|
||||
info!(
|
||||
chars = prompt.len(),
|
||||
@@ -293,7 +282,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn extract_errors_on_oversized_corpus() {
|
||||
// Build a single huge claim to blow the budget.
|
||||
let big = "x".repeat(CORPUS_CHAR_LIMIT + 1);
|
||||
let big = "x".repeat(crate::memory::CORPUS_CHAR_LIMIT + 1);
|
||||
let entries = vec![(
|
||||
day(2026, 5, 9),
|
||||
vec![L2Entry {
|
||||
|
||||
+3
-14
@@ -34,11 +34,6 @@ use crate::memory::track::Track;
|
||||
use crate::tools::ToolContext;
|
||||
use crate::tools::ToolRegistry;
|
||||
|
||||
/// Maximum rendered prompt size in characters. Matches L3u's budget —
|
||||
/// well under Kimi K2.6's 256k token window. Exceeded → hard error
|
||||
/// (not a warning): windowing isn't designed yet.
|
||||
const CORPUS_CHAR_LIMIT: usize = 800_000;
|
||||
|
||||
/// The date range covered by a single L3u file, parsed from its filename.
|
||||
pub type PeriodTag = Span;
|
||||
|
||||
@@ -140,20 +135,14 @@ pub fn render_corpus_for_prompt(by_period: &[(PeriodTag, Vec<L3uEntry>)]) -> Str
|
||||
}
|
||||
|
||||
/// Run the L3u → L4u extraction in a single LLM call. Errors if the
|
||||
/// rendered corpus exceeds [`CORPUS_CHAR_LIMIT`].
|
||||
/// rendered corpus exceeds [`crate::memory::CORPUS_CHAR_LIMIT`].
|
||||
pub async fn extract(
|
||||
by_period: &[(PeriodTag, Vec<L3uEntry>)],
|
||||
track: &Track,
|
||||
backend: &dyn ChatBackend,
|
||||
) -> Result<Vec<L4uClaim>> {
|
||||
let prompt = render_corpus_for_prompt(by_period);
|
||||
if prompt.len() > CORPUS_CHAR_LIMIT {
|
||||
bail!(
|
||||
"L3u corpus is {} chars, exceeds limit of {}; windowing not yet supported",
|
||||
prompt.len(),
|
||||
CORPUS_CHAR_LIMIT
|
||||
);
|
||||
}
|
||||
crate::memory::check_corpus_size(&prompt, "L3u")?;
|
||||
|
||||
info!(
|
||||
chars = prompt.len(),
|
||||
@@ -325,7 +314,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn extract_errors_on_oversized_corpus() {
|
||||
let big = "x".repeat(CORPUS_CHAR_LIMIT + 1);
|
||||
let big = "x".repeat(crate::memory::CORPUS_CHAR_LIMIT + 1);
|
||||
let p = period(day(2026, 2, 24), day(2026, 5, 14));
|
||||
let entries = vec![(
|
||||
p,
|
||||
|
||||
@@ -40,6 +40,36 @@ pub mod nightly;
|
||||
pub mod store;
|
||||
pub mod track;
|
||||
|
||||
/// Maximum rendered prompt size in characters for the consolidating levels
|
||||
/// (L3, L4 and the document generator). ~200k tokens worth, well under Kimi
|
||||
/// K2.6's 256k window.
|
||||
///
|
||||
/// This is a character count standing in for a token count. Replacing it
|
||||
/// with a real tokenizer is what a future windowing strategy needs, and is
|
||||
/// deliberately not attempted here.
|
||||
pub const CORPUS_CHAR_LIMIT: usize = 800_000;
|
||||
|
||||
/// Reject a rendered corpus that exceeds [`CORPUS_CHAR_LIMIT`].
|
||||
///
|
||||
/// Exceeding the budget is a hard error rather than a warning: the levels
|
||||
/// above L2 have no windowing strategy, so a corpus that does not fit has
|
||||
/// no correct truncation and we would rather fail loudly than silently
|
||||
/// consolidate a prefix of the user's history.
|
||||
///
|
||||
/// `level` names the *input* corpus for the message, e.g. `"L2"` for the
|
||||
/// L2 → L3 stage.
|
||||
pub fn check_corpus_size(rendered: &str, level: &str) -> Result<()> {
|
||||
if rendered.len() > CORPUS_CHAR_LIMIT {
|
||||
bail!(
|
||||
"{} corpus is {} chars, exceeds limit of {}; windowing not yet supported",
|
||||
level,
|
||||
rendered.len(),
|
||||
CORPUS_CHAR_LIMIT
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run the L1 → L2 extraction pipeline.
|
||||
///
|
||||
/// Reads the primary room's JSONL from `input_dir`, groups its entries by
|
||||
|
||||
Reference in new issue
Block a user