| 302 | } |
| 303 | |
| 304 | pub(crate) fn memory_items_to_context_result( |
| 305 | provider: impl Into<String>, |
| 306 | items: Vec<MemoryItem>, |
| 307 | ) -> crate::context::ContextResult { |
| 308 | let mut result = crate::context::ContextResult::new(provider); |
| 309 | for item in items { |
| 310 | let token_count = (item.content.len() / 4).max(1); |
| 311 | let context_item = crate::context::ContextItem::new( |
| 312 | &item.id, |
| 313 | crate::context::ContextType::Memory, |
| 314 | &item.content, |
| 315 | ) |
| 316 | .with_relevance(item.relevance_score()) |
| 317 | .with_token_count(token_count) |
| 318 | .with_source(format!("memory://{}", item.id)) |
| 319 | .with_provenance("long_term_memory") |
| 320 | .with_priority(0.35) |
| 321 | .with_trust(0.7) |
| 322 | .with_freshness(0.5); |
| 323 | result.add_item(context_item); |
| 324 | } |
| 325 | result |
| 326 | } |
| 327 | |
| 328 | #[async_trait::async_trait] |
| 329 | impl crate::context::ContextProvider for MemoryContextProvider { |