pub struct SemanticSummarizer { /* private fields */ }Expand description
Semantic summarizer for episodes.
Compresses episodes into concise, searchable summaries suitable for efficient storage and retrieval. Extracts key concepts, critical steps, and generates coherent summary text.
§Configuration
min_summary_length- Minimum words in summary (default: 100)max_summary_length- Maximum words in summary (default: 200)max_key_steps- Maximum key steps to extract (default: 5)
§Examples
use do_memory_core::semantic::SemanticSummarizer;
use do_memory_core::{Episode, TaskContext, TaskType, ExecutionStep, ExecutionResult, TaskOutcome};
let summarizer = SemanticSummarizer::new();
let mut episode = Episode::new(
"Implement user authentication".to_string(),
TaskContext::default(),
TaskType::CodeGeneration,
);
// Add steps
let mut step = ExecutionStep::new(1, "planner".to_string(), "Analyze requirements".to_string());
step.result = Some(ExecutionResult::Success { output: "Requirements clear".to_string() });
episode.add_step(step);
episode.complete(TaskOutcome::Success {
verdict: "Authentication implemented successfully".to_string(),
artifacts: vec!["auth.rs".to_string()],
});
let summary = summarizer.summarize_episode(&episode).await?;
assert!(summary.summary_text.split_whitespace().count() >= 50);
assert!(!summary.key_concepts.is_empty());Implementations§
Source§impl SemanticSummarizer
impl SemanticSummarizer
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new semantic summarizer with default settings.
Default configuration:
- Min summary length: 100 words
- Max summary length: 200 words
- Max key steps: 5
§Examples
use do_memory_core::semantic::SemanticSummarizer;
let summarizer = SemanticSummarizer::new();Sourcepub fn with_config(min_len: usize, max_len: usize, max_steps: usize) -> Self
pub fn with_config(min_len: usize, max_len: usize, max_steps: usize) -> Self
Sourcepub async fn summarize_episode(
&self,
episode: &Episode,
) -> Result<EpisodeSummary>
pub async fn summarize_episode( &self, episode: &Episode, ) -> Result<EpisodeSummary>
Summarize an episode into a semantic summary.
Extracts key information and compresses the episode into a concise, searchable summary with key concepts, critical steps, and summary text. Optionally generates embedding if provider is available.
§Arguments
episode- The episode to summarize
§Returns
Semantic summary of the episode
§Examples
use do_memory_core::semantic::SemanticSummarizer;
use do_memory_core::{Episode, TaskContext, TaskType};
let summarizer = SemanticSummarizer::new();
let episode = Episode::new(
"Test task".to_string(),
TaskContext::default(),
TaskType::Testing,
);
let summary = summarizer.summarize_episode(&episode).await?;Sourcepub async fn summarize_with_embedding(
&self,
episode: &Episode,
embedding_provider: &impl EmbeddingProvider,
) -> Result<EpisodeSummary>
pub async fn summarize_with_embedding( &self, episode: &Episode, embedding_provider: &impl EmbeddingProvider, ) -> Result<EpisodeSummary>
Summarize an episode with embedding generation.
Like summarize_episode but also generates an embedding vector for
the summary text using the provided embedding provider.
§Arguments
episode- The episode to summarizeembedding_provider- Provider to generate embeddings
§Returns
Semantic summary with embedding vector
§Examples
use do_memory_core::semantic::SemanticSummarizer;
use do_memory_core::{Episode, TaskContext, TaskType};
use do_memory_core::embeddings::EmbeddingProvider;
let summarizer = SemanticSummarizer::new();
let summary = summarizer.summarize_with_embedding(&episode, &provider).await.unwrap();
assert!(summary.summary_embedding.is_some());Sourcepub fn extract_key_concepts(&self, episode: &Episode) -> Vec<String>
pub fn extract_key_concepts(&self, episode: &Episode) -> Vec<String>
Sourcepub fn extract_key_steps(&self, episode: &Episode) -> Vec<String>
pub fn extract_key_steps(&self, episode: &Episode) -> Vec<String>
Sourcepub fn generate_summary_text(&self, episode: &Episode) -> String
pub fn generate_summary_text(&self, episode: &Episode) -> String
Generate summary text from an episode.
Creates a coherent 100-200 word summary with:
- Task description
- Key execution steps
- Salient features (if available)
- Outcome and artifacts
§Arguments
episode- The episode to summarize
§Returns
Formatted summary text
§Examples
use do_memory_core::semantic::SemanticSummarizer;
use do_memory_core::{Episode, TaskContext, TaskType, TaskOutcome};
let summarizer = SemanticSummarizer::new();
let mut episode = Episode::new(
"Implement authentication".to_string(),
TaskContext::default(),
TaskType::CodeGeneration,
);
episode.complete(TaskOutcome::Success {
verdict: "Successfully implemented".to_string(),
artifacts: vec!["auth.rs".to_string()],
});
let summary = summarizer.generate_summary_text(&episode);
assert!(summary.contains("Task:"));
assert!(summary.contains("Outcome:"));Trait Implementations§
Source§impl Clone for SemanticSummarizer
impl Clone for SemanticSummarizer
Source§fn clone(&self) -> SemanticSummarizer
fn clone(&self) -> SemanticSummarizer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SemanticSummarizer
impl Debug for SemanticSummarizer
Auto Trait Implementations§
impl Freeze for SemanticSummarizer
impl RefUnwindSafe for SemanticSummarizer
impl Send for SemanticSummarizer
impl Sync for SemanticSummarizer
impl Unpin for SemanticSummarizer
impl UnsafeUnpin for SemanticSummarizer
impl UnwindSafe for SemanticSummarizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.