pub struct LLMEntityExtractor { /* private fields */ }Expand description
LLM-based entity extractor that uses actual language model calls
Implementations§
Source§impl LLMEntityExtractor
impl LLMEntityExtractor
Sourcepub fn new(ollama_client: OllamaClient, entity_types: Vec<String>) -> Self
pub fn new(ollama_client: OllamaClient, entity_types: Vec<String>) -> Self
Create a new LLM-based entity extractor
§Arguments
ollama_client- Ollama client for LLM inferenceentity_types- List of entity types to extract (e.g., [“PERSON”, “LOCATION”, “ORGANIZATION”])
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Set temperature for LLM generation (default: 0.1)
Sourcepub fn with_max_tokens(self, max_tokens: usize) -> Self
pub fn with_max_tokens(self, max_tokens: usize) -> Self
Set maximum tokens for LLM generation (default: 1500)
Sourcepub fn with_keep_alive(self, keep_alive: Option<String>) -> Self
pub fn with_keep_alive(self, keep_alive: Option<String>) -> Self
Set keep_alive for KV cache persistence (e.g. “1h”, “30m”).
Sourcepub fn estimate_tokens(text: &str) -> u32
pub fn estimate_tokens(text: &str) -> u32
Estimate token count from text length (≈ 1 token per 4 chars).
Sourcepub fn calculate_entity_num_ctx(
built_prompt: &str,
max_output_tokens: u32,
) -> u32
pub fn calculate_entity_num_ctx( built_prompt: &str, max_output_tokens: u32, ) -> u32
Calculate the required num_ctx for one entity-extraction LLM call.
Formula (mirrors ContextualEnricher::calculate_num_ctx):
num_ctx = tokens(built_prompt) // instructions + entity types + chunk text
+ max_output_tokens // JSON with entities + relationships
+ 20% safety margin // avoids silent truncationResult is rounded up to the nearest 1024 and clamped to [4096, 131072].
Sourcepub async fn extract_from_chunk(
&self,
chunk: &TextChunk,
) -> Result<(Vec<Entity>, Vec<Relationship>)>
pub async fn extract_from_chunk( &self, chunk: &TextChunk, ) -> Result<(Vec<Entity>, Vec<Relationship>)>
Extract entities and relationships from a text chunk using LLM
This is the REAL extraction that makes actual LLM API calls. Expected time: 15-30 seconds per chunk depending on chunk size and model.
Sourcepub async fn extract_additional(
&self,
chunk: &TextChunk,
previous_entities: &[EntityData],
previous_relationships: &[RelationshipData],
) -> Result<(Vec<Entity>, Vec<Relationship>)>
pub async fn extract_additional( &self, chunk: &TextChunk, previous_entities: &[EntityData], previous_relationships: &[RelationshipData], ) -> Result<(Vec<Entity>, Vec<Relationship>)>
Extract additional entities in a gleaning round (continuation)
This is used after the initial extraction to catch missed entities.
Sourcepub async fn check_completion(
&self,
chunk: &TextChunk,
entities: &[EntityData],
relationships: &[RelationshipData],
) -> Result<bool>
pub async fn check_completion( &self, chunk: &TextChunk, entities: &[EntityData], relationships: &[RelationshipData], ) -> Result<bool>
Check if extraction is complete using LLM judgment
Uses the LLM to determine if all significant entities have been extracted.
Auto Trait Implementations§
impl Freeze for LLMEntityExtractor
impl !RefUnwindSafe for LLMEntityExtractor
impl Send for LLMEntityExtractor
impl Sync for LLMEntityExtractor
impl Unpin for LLMEntityExtractor
impl UnsafeUnpin for LLMEntityExtractor
impl !UnwindSafe for LLMEntityExtractor
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 more