Skip to main content

SemanticSummarizer

Struct SemanticSummarizer 

Source
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

Source

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();
Source

pub fn with_config(min_len: usize, max_len: usize, max_steps: usize) -> Self

Create a semantic summarizer with custom configuration.

§Arguments
  • min_len - Minimum words in summary
  • max_len - Maximum words in summary
  • max_steps - Maximum key steps to extract
§Examples
use do_memory_core::semantic::SemanticSummarizer;

let summarizer = SemanticSummarizer::with_config(50, 150, 3);
Source

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?;
Source

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 summarize
  • embedding_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());
Source

pub fn extract_key_concepts(&self, episode: &Episode) -> Vec<String>

Extract key concepts from an episode.

§Arguments
  • episode - The episode to extract concepts from
§Returns

Vector of key concept strings

Source

pub fn extract_key_steps(&self, episode: &Episode) -> Vec<String>

Extract key steps from an episode.

§Arguments
  • episode - The episode to extract steps from
§Returns

Vector of key step descriptions

Source

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

Source§

fn clone(&self) -> SemanticSummarizer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SemanticSummarizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SemanticSummarizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> SendAlias for T

Source§

impl<T> SendAlias for T

Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

Source§

impl<T> SyncAlias for T

Source§

impl<T> SyncAlias for T