pub struct TopicIndexService {
topics: Arc<RwLock<HashMap<String, Vec<MemoryId>>>>,
topic_namespaces: Arc<RwLock<HashMap<String, Vec<Namespace>>>>,
last_refresh: Arc<RwLock<Option<Instant>>>,
refresh_interval: Duration,
}Expand description
Service for maintaining topic → memory mappings.
Fields§
§topics: Arc<RwLock<HashMap<String, Vec<MemoryId>>>>Topic to memory ID mappings.
topic_namespaces: Arc<RwLock<HashMap<String, Vec<Namespace>>>>Topic to namespace mappings.
last_refresh: Arc<RwLock<Option<Instant>>>Last refresh timestamp.
refresh_interval: DurationRefresh interval.
Implementations§
Source§impl TopicIndexService
impl TopicIndexService
Sourcepub const fn with_refresh_interval(self, interval: Duration) -> Self
pub const fn with_refresh_interval(self, interval: Duration) -> Self
Sets the refresh interval.
Sourcepub fn needs_refresh(&self) -> bool
pub fn needs_refresh(&self) -> bool
Checks if the index needs refreshing.
Sourcepub fn build_index(&self, recall: &RecallService) -> Result<()>
pub fn build_index(&self, recall: &RecallService) -> Result<()>
Builds the topic index from a recall service.
Extracts topics from:
- Memory tags
- Memory namespace names
- Keywords in memory content
§Errors
Returns an error if memory retrieval fails.
Sourcepub fn list_topics(&self) -> Result<Vec<TopicInfo>>
pub fn list_topics(&self) -> Result<Vec<TopicInfo>>
Sourcepub fn add_memory(
&self,
memory_id: &MemoryId,
tags: &[String],
namespace: Namespace,
) -> Result<()>
pub fn add_memory( &self, memory_id: &MemoryId, tags: &[String], namespace: Namespace, ) -> Result<()>
Adds a memory to the topic index.
Call this when a new memory is captured to keep the index up to date.
§Errors
Returns an error if the lock is poisoned.
Sourcepub fn topic_count(&self) -> usize
pub fn topic_count(&self) -> usize
Returns the number of topics in the index.
Sourcepub fn association_count(&self) -> usize
pub fn association_count(&self) -> usize
Returns the total number of topic-memory associations.
Sourcepub fn remove_memory(&self, memory_id: &MemoryId) -> Result<()>
pub fn remove_memory(&self, memory_id: &MemoryId) -> Result<()>
Removes a memory from the topic index (PERF-M1: incremental updates).
Call this when a memory is deleted to keep the index up to date without requiring a full rebuild.
§Errors
Returns an error if the lock is poisoned.
Sourcepub fn update_memory(
&self,
memory_id: &MemoryId,
new_tags: &[String],
new_namespace: Namespace,
) -> Result<()>
pub fn update_memory( &self, memory_id: &MemoryId, new_tags: &[String], new_namespace: Namespace, ) -> Result<()>
Updates a memory in the topic index (PERF-M1: incremental updates).
This is a convenience method that removes the old entry and adds the new one. Use this when tags or namespace change.
§Errors
Returns an error if the lock is poisoned.
Sourcepub fn add_content_keywords(
&self,
memory_id: &MemoryId,
content: &str,
namespace: Namespace,
) -> Result<()>
pub fn add_content_keywords( &self, memory_id: &MemoryId, content: &str, namespace: Namespace, ) -> Result<()>
Adds content-based keywords to the topic index (PERF-M1: incremental updates).
Call this after add_memory() to also index keywords from the memory content.
This is separated to allow callers to control whether content keywords are indexed.
§Errors
Returns an error if the lock is poisoned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TopicIndexService
impl RefUnwindSafe for TopicIndexService
impl Send for TopicIndexService
impl Sync for TopicIndexService
impl Unpin for TopicIndexService
impl UnwindSafe for TopicIndexService
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].