pub struct ImplicitConflictDetector { /* private fields */ }Expand description
Write-time implicit conflict detector.
Compares a new edge’s predicate against existing active edges on the same source entity using the configured similarity method and threshold.
§Examples
use zeph_config::ImplicitConflictConfig;
use zeph_memory::graph::implicit_conflict::ImplicitConflictDetector;
let config = ImplicitConflictConfig { enabled: true, ..Default::default() };
let detector = ImplicitConflictDetector::new(config);
let candidates = detector.detect_candidates(42, "employ", &[(1, "employs")], false);
assert!(!candidates.is_empty());Implementations§
Source§impl ImplicitConflictDetector
impl ImplicitConflictDetector
Sourcepub fn new(config: ImplicitConflictConfig) -> Self
pub fn new(config: ImplicitConflictConfig) -> Self
Create a new detector with the given configuration.
Sourcepub fn detect_candidates(
&self,
new_edge_id: i64,
new_predicate: &str,
existing: &[(i64, &str)],
is_cardinality_n: bool,
) -> Vec<ConflictCandidate>
pub fn detect_candidates( &self, new_edge_id: i64, new_predicate: &str, existing: &[(i64, &str)], is_cardinality_n: bool, ) -> Vec<ConflictCandidate>
Detect implicit conflict candidates for a new predicate against existing ones.
Returns pairs where normalized Levenshtein similarity is
>= conflict_similarity_threshold and the predicates differ (identical
predicates are already handled by APEX-MEM explicit supersession).
Returns an empty vec when enabled = false or when the cardinality flag
is_cardinality_n is set (FR-011).
§Arguments
new_edge_id— database ID of the newly inserted edgenew_predicate— canonical relation of the new edgeexisting— slice of(edge_id, canonical_relation)for all other active edges on the same source entityis_cardinality_n— set totruefor multi-valued predicates; skips detection
Sourcepub async fn stage_candidates(
&self,
candidates: &[ConflictCandidate],
tx: &mut DbTransaction<'_>,
ttl_days: u32,
) -> Result<(), MemoryError>
pub async fn stage_candidates( &self, candidates: &[ConflictCandidate], tx: &mut DbTransaction<'_>, ttl_days: u32, ) -> Result<(), MemoryError>
Persist conflict candidates into implicit_conflict_candidates.
Each candidate is inserted with status = 'pending' and an expiry of
now + ttl_days * 86400 seconds.
§Errors
Returns a MemoryError on database write failure.
Sourcepub fn normalized_levenshtein(a: &str, b: &str) -> f64
pub fn normalized_levenshtein(a: &str, b: &str) -> f64
Compute normalized Levenshtein similarity between two strings.
Returns a value in [0.0, 1.0] where 1.0 means identical.
Returns 1.0 if both strings are empty, 0.0 if only one is empty.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true when detection is enabled.
Sourcepub fn candidate_ttl_days(&self) -> u32
pub fn candidate_ttl_days(&self) -> u32
Returns the configured TTL for conflict candidates, in days.
Auto Trait Implementations§
impl Freeze for ImplicitConflictDetector
impl RefUnwindSafe for ImplicitConflictDetector
impl Send for ImplicitConflictDetector
impl Sync for ImplicitConflictDetector
impl Unpin for ImplicitConflictDetector
impl UnsafeUnpin for ImplicitConflictDetector
impl UnwindSafe for ImplicitConflictDetector
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request