pub struct OntologyTable { /* private fields */ }Expand description
The loaded APEX-MEM ontology table plus bounded LRU cache for resolved mappings.
Designed for read-heavy workloads: the static table and cardinality map are behind
ArcSwap for lock-free reads; the LRU cache is behind a Mutex (written only on
misses and LLM fallback results).
Implementations§
Source§impl OntologyTable
impl OntologyTable
Sourcepub fn from_default(cache_max: usize) -> Self
pub fn from_default(cache_max: usize) -> Self
Create from the embedded default ontology table.
Sourcepub async fn from_path(
path: &Path,
cache_max: usize,
) -> Result<Self, MemoryError>
pub async fn from_path( path: &Path, cache_max: usize, ) -> Result<Self, MemoryError>
Load from a TOML file at path, or fall back to embedded defaults when path is empty.
§Errors
Returns an error if the file exists but cannot be parsed.
Sourcepub async fn reload(&self, path: &Path) -> Result<(), MemoryError>
pub async fn reload(&self, path: &Path) -> Result<(), MemoryError>
Reload the ontology table from path (or embedded defaults if path is empty).
The LRU cache is cleared atomically with the table swap so stale mappings from the old table cannot win over new canonical forms.
§Errors
Returns an error if the new TOML cannot be parsed.
Sourcepub async fn resolve(&self, raw_predicate: &str) -> (String, bool)
pub async fn resolve(&self, raw_predicate: &str) -> (String, bool)
Resolve raw_predicate to its canonical form.
Resolution order:
- LRU cache hit
- Static table lookup
- Miss: return raw as canonical (cardinality-n default)
Returns (canonical, was_unmapped). was_unmapped is true when the predicate
had no entry in the static table; callers should increment the unmapped counter.
§Examples
use zeph_memory::graph::ontology::OntologyTable;
let table = OntologyTable::from_default(64);
let (canonical, unmapped) = table.resolve("employed_by").await;
assert_eq!(canonical, "works_at");
assert!(!unmapped);Sourcepub fn cardinality(&self, canonical_predicate: &str) -> Cardinality
pub fn cardinality(&self, canonical_predicate: &str) -> Cardinality
Return the cardinality for canonical_predicate.
Defaults to Cardinality::Many for predicates not in the ontology table.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for OntologyTable
impl !RefUnwindSafe for OntologyTable
impl Send for OntologyTable
impl Sync for OntologyTable
impl Unpin for OntologyTable
impl UnsafeUnpin for OntologyTable
impl !UnwindSafe for OntologyTable
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
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