Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test(retrieval): cover noisy session candidate windows

AkitaOnRails5a6886cb9e14
diff --git a/crates/ai-memory-store/src/lib.rs b/crates/ai-memory-store/src/lib.rs
index ae40d9ee..30a8cff9 100644
--- a/crates/ai-memory-store/src/lib.rs
+++ b/crates/ai-memory-store/src/lib.rs
@@ -2149,6 +2149,18 @@ mod tests {
session.tier = Tier::Episodic;
store.writer.upsert_page(session).await.unwrap();
+ for idx in 0..5 {
+ let mut noisy_session = sample_page(
+ ws,
+ proj,
+ &format!("sessions/noisy-{idx}.md"),
+ "What is the current decision about LLM embeddings? This session repeats the question as historical evidence.",
+ );
+ noisy_session.title = "What is the current decision about LLM embeddings?".into();
+ noisy_session.tier = Tier::Episodic;
+ store.writer.upsert_page(noisy_session).await.unwrap();
+ }
+
let mut rejected = sample_page(
ws,
proj,
@@ -2178,6 +2190,13 @@ mod tests {
);
assert!(scoped.windows(2).all(|pair| pair[0].rank <= pair[1].rank));
+ let top_one = store
+ .reader
+ .search_pages_for_project(ws, proj, query.into(), 1)
+ .await
+ .unwrap();
+ assert_eq!(top_one[0].path.as_str(), "decisions/embedding-policy.md");
+
let global = store
.reader
.search_pages_with_meta(query.into(), 10)
diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rs
index 4ea72969..74457923 100644
--- a/crates/ai-memory-store/src/reader.rs
+++ b/crates/ai-memory-store/src/reader.rs
@@ -56,6 +56,7 @@ fn page_kind_expr(path_column: &str, frontmatter_column: &str) -> String {
}
const AUTHORITY_CANDIDATE_MULTIPLIER: usize = 4;
+const AUTHORITY_MIN_CANDIDATES: usize = 20;
const AUTHORITY_MAX_EXTRA_CANDIDATES: usize = 300;
#[derive(Debug, Clone, Copy)]
@@ -80,7 +81,7 @@ impl PageAuthority {
"rule" | "decision" => 0.15,
"procedure" | "gotcha" => 0.12,
"concept" | "slot" => 0.07,
- "session" => -0.12,
+ "session" => -0.15,
_ => 0.0,
};
factor += match tier {
@@ -154,8 +155,12 @@ fn normalize_authority_tag(tag: &str) -> String {
}
fn authority_candidate_limit(limit: usize) -> usize {
+ if limit == 0 {
+ return 0;
+ }
limit
.saturating_mul(AUTHORITY_CANDIDATE_MULTIPLIER)
+ .max(AUTHORITY_MIN_CANDIDATES)
.min(limit.saturating_add(AUTHORITY_MAX_EXTRA_CANDIDATES))
}