Skip to main content

EntityResolver

Struct EntityResolver 

Source
pub struct EntityResolver<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> EntityResolver<'a>

Source

pub fn new(store: &'a GraphStore) -> Self

Source

pub fn with_embedding_store(self, store: &'a Arc<EmbeddingStore>) -> Self

Source

pub fn with_provider(self, provider: &'a AnyProvider) -> Self

Source

pub fn with_thresholds(self, similarity: f32, ambiguous: f32) -> Self

Source

pub fn fallback_count(&self) -> Arc<AtomicU64>

Shared fallback counter — tests can clone this Arc to inspect the value.

Source

pub async fn resolve( &self, name: &str, entity_type: &str, summary: Option<&str>, ) -> Result<(i64, ResolutionOutcome), MemoryError>

Resolve an extracted entity using the alias-first canonicalization pipeline.

Pipeline:

  1. Normalize: trim, lowercase, strip control chars, truncate to 512 bytes.
  2. Parse entity type (fallback to Concept on unknown).
  3. Alias lookup: search graph_entity_aliases by normalized name + entity_type. If found, touch last_seen_at and return the existing entity id.
  4. Canonical name lookup: search graph_entities by canonical_name + entity_type. If found, touch last_seen_at and return the existing entity id.
  5. When embedding_store and provider are configured, performs embedding-based fuzzy matching: cosine similarity search (Qdrant), LLM disambiguation for ambiguous range, merge or create based on result. Failures degrade gracefully to step 6.
  6. Create: upsert new entity with canonical_name = normalized name.
  7. Register the normalized form (and original trimmed form if different) as aliases.
§Errors

Returns an error if the entity name is empty after normalization, or if a DB operation fails.

Source

pub async fn resolve_batch( &self, entities: &[ExtractedEntity], ) -> Result<Vec<(i64, ResolutionOutcome)>, MemoryError>

Resolve a batch of extracted entities concurrently.

Returns a Vec of (entity_id, ResolutionOutcome) in the same order as input.

§Errors

Returns an error if any DB operation fails.

§Panics

Panics if an internal stream collection bug causes a result index to be missing. This indicates a programming error and should never occur in correct usage.

Source

pub async fn resolve_edge( &self, source_id: i64, target_id: i64, relation: &str, fact: &str, confidence: f32, episode_id: Option<MessageId>, ) -> Result<Option<i64>, MemoryError>

Resolve an extracted edge: deduplicate or supersede existing edges.

  • If an active edge with the same direction and relation exists with an identical fact, returns None (deduplicated).
  • If an active edge with the same direction and relation exists with a different fact, invalidates the old edge and inserts the new one, returning Some(new_id).
  • If no matching edge exists, inserts a new edge and returns Some(new_id).

Relation and fact strings are sanitized (control chars stripped, length-capped).

§Errors

Returns an error if any database operation fails.

Source

pub async fn resolve_edge_typed( &self, source_id: i64, target_id: i64, relation: &str, fact: &str, confidence: f32, episode_id: Option<MessageId>, edge_type: EdgeType, ) -> Result<Option<i64>, MemoryError>

Resolve a typed edge: deduplicate or supersede existing edges of the same type.

Identical to [resolve_edge] but includes edge_type in the matching key. An active edge with the same (source, target, relation, edge_type) and identical fact returns None; same relation+type with different fact is superseded.

This ensures that different MAGMA edge types for the same entity pair are stored independently (critic mitigation: dedup key includes edge_type).

§Errors

Returns an error if any database operation fails.

Auto Trait Implementations§

§

impl<'a> Freeze for EntityResolver<'a>

§

impl<'a> !RefUnwindSafe for EntityResolver<'a>

§

impl<'a> Send for EntityResolver<'a>

§

impl<'a> Sync for EntityResolver<'a>

§

impl<'a> Unpin for EntityResolver<'a>

§

impl<'a> UnsafeUnpin for EntityResolver<'a>

§

impl<'a> !UnwindSafe for EntityResolver<'a>

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> 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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