EntityExtractor

Struct EntityExtractor 

Source
pub struct EntityExtractor<P: LLMProvider> { /* private fields */ }
Expand description

Entity extractor using LLM.

TigerStyle: Generic over provider for sim/production flexibility.

§Example

use umi_memory::extraction::{EntityExtractor, ExtractionOptions};
use umi_memory::llm::SimLLMProvider;

#[tokio::main]
async fn main() {
    // Simulation provider for testing
    let provider = SimLLMProvider::with_seed(42);
    let extractor = EntityExtractor::new(provider);

    let result = extractor
        .extract("Alice works at Acme Corp", ExtractionOptions::default())
        .await
        .unwrap();

    // Result contains entities and relations
    assert!(!result.is_empty());
}

Implementations§

Source§

impl<P: LLMProvider> EntityExtractor<P>

Source

pub fn new(provider: P) -> Self

Create a new entity extractor with the given LLM provider.

Source

pub async fn extract( &self, text: &str, options: ExtractionOptions, ) -> Result<ExtractionResult, ExtractionError>

Extract entities and relations from text.

§Arguments
  • text - Text to extract from
  • options - Extraction options (existing entities, min confidence)
§Returns

ExtractionResult with entities, relations, and raw text.

§Errors

Returns ExtractionError if text is empty or too long.

§Graceful Degradation

If the LLM fails or returns invalid JSON, a fallback “note” entity is created from the input text. This ensures extraction never fails due to LLM issues.

Source

pub async fn extract_entities_only( &self, text: &str, ) -> Result<Vec<ExtractedEntity>, ExtractionError>

Extract only entities (convenience method).

§Arguments
  • text - Text to extract from
§Returns

Vector of extracted entities.

Source

pub fn provider(&self) -> &P

Get a reference to the underlying provider.

Trait Implementations§

Source§

impl<P: Debug + LLMProvider> Debug for EntityExtractor<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for EntityExtractor<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for EntityExtractor<P>
where P: RefUnwindSafe,

§

impl<P> Send for EntityExtractor<P>

§

impl<P> Sync for EntityExtractor<P>

§

impl<P> Unpin for EntityExtractor<P>
where P: Unpin,

§

impl<P> UnwindSafe for EntityExtractor<P>
where P: UnwindSafe,

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, 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