Skip to main content

EntityExtractor

Trait EntityExtractor 

Source
pub trait EntityExtractor: Send + Sync {
    // Required method
    fn extract<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
        hints: &'life2 [EntityRef],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<EntityRef>, MemoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided method
    fn id(&self) -> Cow<'static, str> { ... }
}
Expand description

Extracts typed entity references from text.

Implementations include BuiltinExtractor (regex, M2), LlmEntityExtractor (M2), FallbackExtractor (chain primary→secondary on empty, M2). Tests use a FakeExtractor returning a fixed set.

Required Methods§

Source

fn extract<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, text: &'life1 str, hints: &'life2 [EntityRef], ) -> Pin<Box<dyn Future<Output = Result<Vec<EntityRef>, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Extract entities from text, merging with caller-supplied hints.

Hints take precedence — extractor implementations dedupe by (EntityType::as_str(), name) and never drop a hint silently.

Provided Methods§

Source

fn id(&self) -> Cow<'static, str>

Stable identity of this extractor, including anything it wraps.

Exists for memoising decorators. A cache keyed on the text, the hints and a caller-supplied model string but not on the extractor it decorates serves the previous extractor’s entries when the extractor is swapped: the second arm of an A/B reads the first arm’s cache, both arms report identical numbers at full speed, and the run reads as “the extractor makes no difference” rather than “the second arm never ran”. Fold this into the key instead.

The default is the concrete type name, which distinguishes swaps between extractor types. Override when two instances of the same type differ in a way that changes output — a different model, a different prompt, a different regex table — and compose the inner ids in decorators so the whole chain is named.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§