pub struct InMemoryMemoryService { /* private fields */ }Expand description
An in-memory implementation of MemoryService. Thread-safe.
Searches return at most ten entries, ranked by the number of distinct query words they match. Ties follow session insertion order, then event order.
It also implements EventAdder: EventAdder::add_events appends to the bucket of
req.session_id and keeps the first stored event of each non-empty event ID in that
bucket; MemoryService::add_session_to_memory replaces the bucket of the session.
Both add methods skip events whose content is None or holds no part; such an event does
not reserve its ID. Thought parts are left out of both matching and the returned content.
An event with parts but no searchable text, such as a blob-only or thought-only event, is
stored and reserves its ID, but no search returns it.
A query and the stored text are split into words: runs of letters, numbers and underscores, taken after Unicode NFC normalization and lowercased with full Unicode case mapping. An event matches a query word when it has that word. A query word with non-ASCII characters also matches anywhere inside the event’s text, and a stored word that mixes Latin and other scripts, such as the Python in 私はPythonを使う, also yields each single-script run as a word. A query with no words returns no entries.
Implementations§
Trait Implementations§
Source§impl Debug for InMemoryMemoryService
impl Debug for InMemoryMemoryService
Source§impl Default for InMemoryMemoryService
impl Default for InMemoryMemoryService
Source§impl EventAdder for InMemoryMemoryService
impl EventAdder for InMemoryMemoryService
Source§fn add_events<'life0, 'async_trait>(
&'life0 self,
req: AddEventsRequest,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add_events<'life0, 'async_trait>(
&'life0 self,
req: AddEventsRequest,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Appends to the bucket of req.session_id
(the default bucket when it is empty), skipping an event whose non-empty ID the bucket
already holds. req.custom_metadata is ignored.
Source§impl MemoryService for InMemoryMemoryService
impl MemoryService for InMemoryMemoryService
Source§fn add_session_to_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 dyn Session,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add_session_to_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 dyn Session,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Replaces the session’s bucket with the session’s events.
Source§fn search_memory<'life0, 'async_trait>(
&'life0 self,
req: SearchRequest,
) -> Pin<Box<dyn Future<Output = Result<SearchResponse, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn search_memory<'life0, 'async_trait>(
&'life0 self,
req: SearchRequest,
) -> Pin<Box<dyn Future<Output = Result<SearchResponse, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns up to ten entries, ranked by the number of distinct query words matched.
Source§fn as_event_adder(&self) -> Option<&dyn EventAdder>
fn as_event_adder(&self) -> Option<&dyn EventAdder>
EventAdder, when it can ingest an incremental delta of events;
None by default. Read more