Expand temporal context window for SMS retrieval from ±2 days to ±4 days

This commit is contained in:
Cameron
2026-01-29 19:48:09 -05:00
parent 92a468233e
commit e92513fbe9
2 changed files with 11 additions and 11 deletions

View File

@@ -737,14 +737,14 @@ impl InsightGenerator {
let disable_rag_for_testing = false;
if disable_rag_for_testing {
log::warn!("RAG DISABLED FOR TESTING - Using only time-based retrieval (±2 days)");
log::warn!("RAG DISABLED FOR TESTING - Using only time-based retrieval (±4 days)");
// Skip directly to fallback
} else {
// ALWAYS use Strategy B: Expanded immediate context + historical RAG
// This is more reliable than pure semantic search which can match irrelevant messages
log::info!("Using expanded immediate context + historical RAG approach");
// Step 1: Get FULL immediate temporal context (±2 days, ALL messages)
// Step 1: Get FULL immediate temporal context (±4 days, ALL messages)
let immediate_messages = self
.sms_client
.fetch_messages_for_contact(contact.as_deref(), timestamp)
@@ -755,7 +755,7 @@ impl InsightGenerator {
});
log::info!(
"Fetched {} messages from ±2 days window (using ALL for immediate context)",
"Fetched {} messages from ±4 days window (using ALL for immediate context)",
immediate_messages.len()
);
@@ -813,7 +813,7 @@ impl InsightGenerator {
// Combine summaries
sms_summary = Some(format!(
"Immediate context (±2 days): {}\n\nSimilar moments from the past: {}",
"Immediate context (±4 days): {}\n\nSimilar moments from the past: {}",
immediate_summary, historical_summary
));
}
@@ -863,7 +863,7 @@ impl InsightGenerator {
// 6. Fallback to traditional time-based message retrieval if RAG didn't work
if !used_rag {
log::info!("Using traditional time-based message retrieval (±2 days)");
log::info!("Using traditional time-based message retrieval (±4 days)");
let sms_messages = self
.sms_client
.fetch_messages_for_contact(contact.as_deref(), timestamp)

View File

@@ -20,7 +20,7 @@ impl SmsApiClient {
}
}
/// Fetch messages for a specific contact within ±1 day of the given timestamp
/// Fetch messages for a specific contact within ±4 days of the given timestamp
/// Falls back to all contacts if no messages found for the specific contact
/// Messages are sorted by proximity to the center timestamp
pub async fn fetch_messages_for_contact(
@@ -30,12 +30,12 @@ impl SmsApiClient {
) -> Result<Vec<SmsMessage>> {
use chrono::Duration;
// Calculate ±2 days range around the center timestamp
// Calculate ±4 days range around the center timestamp
let center_dt = chrono::DateTime::from_timestamp(center_timestamp, 0)
.ok_or_else(|| anyhow::anyhow!("Invalid timestamp"))?;
let start_dt = center_dt - Duration::days(2);
let end_dt = center_dt + Duration::days(2);
let start_dt = center_dt - Duration::days(4);
let end_dt = center_dt + Duration::days(4);
let start_ts = start_dt.timestamp();
let end_ts = end_dt.timestamp();
@@ -43,7 +43,7 @@ impl SmsApiClient {
// If contact specified, try fetching for that contact first
if let Some(contact_name) = contact {
log::info!(
"Fetching SMS for contact: {} (±2 days from {})",
"Fetching SMS for contact: {} (±4 days from {})",
contact_name,
center_dt.format("%Y-%m-%d %H:%M:%S")
);
@@ -68,7 +68,7 @@ impl SmsApiClient {
// Fallback to all contacts
log::info!(
"Fetching all SMS messages (±1 day from {})",
"Fetching all SMS messages (±4 days from {})",
center_dt.format("%Y-%m-%d %H:%M:%S")
);
self.fetch_messages(start_ts, end_ts, None, Some(center_timestamp))