pub struct ContextBuilder { /* private fields */ }Expand description
Builds LLM context from a knowledge graph by extracting relevant subgraphs.
Implementations§
Source§impl ContextBuilder
impl ContextBuilder
Sourcepub fn with_config(config: ContextBuilderConfig) -> Self
pub fn with_config(config: ContextBuilderConfig) -> Self
Create with a custom configuration.
Sourcepub fn extract_neighborhood(
&self,
kg: &KnowledgeGraph,
entity: &str,
max_hops: Option<usize>,
) -> Vec<ContextTriple>
pub fn extract_neighborhood( &self, kg: &KnowledgeGraph, entity: &str, max_hops: Option<usize>, ) -> Vec<ContextTriple>
Extract the N-hop neighborhood around entity.
Sourcepub fn entity_neighborhood(
&self,
kg: &KnowledgeGraph,
entity: &str,
) -> Vec<ContextTriple>
pub fn entity_neighborhood( &self, kg: &KnowledgeGraph, entity: &str, ) -> Vec<ContextTriple>
Retrieve direct connections of an entity (1-hop neighborhood).
Sourcepub fn relation_context(
&self,
kg: &KnowledgeGraph,
predicate: &str,
) -> Vec<ContextTriple>
pub fn relation_context( &self, kg: &KnowledgeGraph, predicate: &str, ) -> Vec<ContextTriple>
Retrieve all triples involving a specific predicate.
Sourcepub fn rank_triples(
&self,
triples: &[ContextTriple],
seed_entities: &[&str],
) -> Vec<ScoredTriple>
pub fn rank_triples( &self, triples: &[ContextTriple], seed_entities: &[&str], ) -> Vec<ScoredTriple>
Rank triples by relevance to a set of seed entities.
Triples mentioning more seed entities score higher.
Sourcepub fn truncate_to_budget(
&self,
triples: &[ContextTriple],
) -> Vec<ContextTriple>
pub fn truncate_to_budget( &self, triples: &[ContextTriple], ) -> Vec<ContextTriple>
Truncate a list of triples to fit within the token budget.
Sourcepub fn format_triples(&self, triples: &[ContextTriple]) -> String
pub fn format_triples(&self, triples: &[ContextTriple]) -> String
Format a list of triples using the configured template.
Sourcepub fn merge_contexts(
&self,
contexts: &[Vec<ContextTriple>],
) -> Vec<ContextTriple>
pub fn merge_contexts( &self, contexts: &[Vec<ContextTriple>], ) -> Vec<ContextTriple>
Merge contexts extracted for multiple entities, deduplicating triples.
Sourcepub fn deduplicate(&self, triples: &[ContextTriple]) -> Vec<ContextTriple>
pub fn deduplicate(&self, triples: &[ContextTriple]) -> Vec<ContextTriple>
Deduplicate a list of triples (preserving order).
Sourcepub fn build(&self, kg: &KnowledgeGraph, entity: &str) -> BuiltContext
pub fn build(&self, kg: &KnowledgeGraph, entity: &str) -> BuiltContext
Build context for a single entity.
Sourcepub fn build_multi(
&self,
kg: &KnowledgeGraph,
entities: &[&str],
) -> BuiltContext
pub fn build_multi( &self, kg: &KnowledgeGraph, entities: &[&str], ) -> BuiltContext
Build context for multiple entities, merging and deduplicating.
Sourcepub fn config(&self) -> &ContextBuilderConfig
pub fn config(&self) -> &ContextBuilderConfig
Access the configuration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContextBuilder
impl RefUnwindSafe for ContextBuilder
impl Send for ContextBuilder
impl Sync for ContextBuilder
impl Unpin for ContextBuilder
impl UnsafeUnpin for ContextBuilder
impl UnwindSafe for ContextBuilder
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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