Expand temporal context window for SMS retrieval from ±2 days to ±4 days
This commit is contained in:
@@ -737,14 +737,14 @@ impl InsightGenerator {
|
|||||||
let disable_rag_for_testing = false;
|
let disable_rag_for_testing = false;
|
||||||
|
|
||||||
if disable_rag_for_testing {
|
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
|
// Skip directly to fallback
|
||||||
} else {
|
} else {
|
||||||
// ALWAYS use Strategy B: Expanded immediate context + historical RAG
|
// ALWAYS use Strategy B: Expanded immediate context + historical RAG
|
||||||
// This is more reliable than pure semantic search which can match irrelevant messages
|
// This is more reliable than pure semantic search which can match irrelevant messages
|
||||||
log::info!("Using expanded immediate context + historical RAG approach");
|
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
|
let immediate_messages = self
|
||||||
.sms_client
|
.sms_client
|
||||||
.fetch_messages_for_contact(contact.as_deref(), timestamp)
|
.fetch_messages_for_contact(contact.as_deref(), timestamp)
|
||||||
@@ -755,7 +755,7 @@ impl InsightGenerator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
log::info!(
|
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()
|
immediate_messages.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -813,7 +813,7 @@ impl InsightGenerator {
|
|||||||
|
|
||||||
// Combine summaries
|
// Combine summaries
|
||||||
sms_summary = Some(format!(
|
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
|
immediate_summary, historical_summary
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -863,7 +863,7 @@ impl InsightGenerator {
|
|||||||
|
|
||||||
// 6. Fallback to traditional time-based message retrieval if RAG didn't work
|
// 6. Fallback to traditional time-based message retrieval if RAG didn't work
|
||||||
if !used_rag {
|
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
|
let sms_messages = self
|
||||||
.sms_client
|
.sms_client
|
||||||
.fetch_messages_for_contact(contact.as_deref(), timestamp)
|
.fetch_messages_for_contact(contact.as_deref(), timestamp)
|
||||||
|
|||||||
@@ -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
|
/// Falls back to all contacts if no messages found for the specific contact
|
||||||
/// Messages are sorted by proximity to the center timestamp
|
/// Messages are sorted by proximity to the center timestamp
|
||||||
pub async fn fetch_messages_for_contact(
|
pub async fn fetch_messages_for_contact(
|
||||||
@@ -30,12 +30,12 @@ impl SmsApiClient {
|
|||||||
) -> Result<Vec<SmsMessage>> {
|
) -> Result<Vec<SmsMessage>> {
|
||||||
use chrono::Duration;
|
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)
|
let center_dt = chrono::DateTime::from_timestamp(center_timestamp, 0)
|
||||||
.ok_or_else(|| anyhow::anyhow!("Invalid timestamp"))?;
|
.ok_or_else(|| anyhow::anyhow!("Invalid timestamp"))?;
|
||||||
|
|
||||||
let start_dt = center_dt - Duration::days(2);
|
let start_dt = center_dt - Duration::days(4);
|
||||||
let end_dt = center_dt + Duration::days(2);
|
let end_dt = center_dt + Duration::days(4);
|
||||||
|
|
||||||
let start_ts = start_dt.timestamp();
|
let start_ts = start_dt.timestamp();
|
||||||
let end_ts = end_dt.timestamp();
|
let end_ts = end_dt.timestamp();
|
||||||
@@ -43,7 +43,7 @@ impl SmsApiClient {
|
|||||||
// If contact specified, try fetching for that contact first
|
// If contact specified, try fetching for that contact first
|
||||||
if let Some(contact_name) = contact {
|
if let Some(contact_name) = contact {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Fetching SMS for contact: {} (±2 days from {})",
|
"Fetching SMS for contact: {} (±4 days from {})",
|
||||||
contact_name,
|
contact_name,
|
||||||
center_dt.format("%Y-%m-%d %H:%M:%S")
|
center_dt.format("%Y-%m-%d %H:%M:%S")
|
||||||
);
|
);
|
||||||
@@ -68,7 +68,7 @@ impl SmsApiClient {
|
|||||||
|
|
||||||
// Fallback to all contacts
|
// Fallback to all contacts
|
||||||
log::info!(
|
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")
|
center_dt.format("%Y-%m-%d %H:%M:%S")
|
||||||
);
|
);
|
||||||
self.fetch_messages(start_ts, end_ts, None, Some(center_timestamp))
|
self.fetch_messages(start_ts, end_ts, None, Some(center_timestamp))
|
||||||
|
|||||||
Reference in New Issue
Block a user