Skip to main content

TerraphimService

Struct TerraphimService 

Source
pub struct TerraphimService { /* private fields */ }

Implementations§

Source§

impl TerraphimService

Source

pub fn new(config_state: ConfigState) -> Self

Create a new TerraphimService

Source

pub async fn ensure_thesaurus_loaded( &mut self, role_name: &RoleName, ) -> Result<Thesaurus>

load thesaurus from config object and if absent make sure it’s loaded from automata_url

Source

pub async fn preprocess_document_content( &mut self, document: Document, role: &Role, ) -> Result<Document>

Preprocess document content to create clickable KG links when terraphim_it is enabled

This function replaces KG terms in the document body with markdown links in the format term which can be intercepted by the frontend to display KG documents when clicked.

Preprocess document content with both KG linking and search term highlighting

Source

pub async fn create_document(&mut self, document: Document) -> Result<Document>

Create document

Source

pub async fn get_document_by_id( &mut self, document_id: &str, ) -> Result<Option<Document>>

Get document by ID

This method supports both normalized IDs (e.g., “haystackmd”) and original filenames (e.g., “haystack.md”). It tries to find the document using the provided ID first, then tries with a normalized version, and finally falls back to searching by title.

Source

pub async fn apply_logical_operators_to_documents( &mut self, search_query: &SearchQuery, documents: Vec<Document>, ) -> Result<Vec<Document>>

Apply logical operators (AND/OR) to filter documents based on multiple search terms

Source

pub async fn search_documents_selected_role( &mut self, search_term: &NormalizedTermValue, ) -> Result<Vec<Document>>

search for documents in the haystacks with selected role from the config and return the documents sorted by relevance

Source

pub async fn search( &mut self, search_query: &SearchQuery, ) -> Result<Vec<Document>>

Search for documents in the haystacks

Source

pub async fn find_documents_for_kg_term( &mut self, role_name: &RoleName, term: &str, ) -> Result<Vec<Document>>

Find documents that contain a given knowledge graph term

This method searches for documents that were the source of a knowledge graph term. For example, given “haystack”, it will find documents like “haystack.md” that contain this term or its synonyms (“datasource”, “service”, “agent”).

For KG protocol resolution, this method also directly looks for KG definition documents when the term appears to be a KG concept (like “terraphim-graph” -> “./docs/src/kg/terraphim-graph.md”).

Returns a vector of Documents that contain the term, with KG preprocessing applied if enabled for the role.

Source

pub async fn generate_document_summary( &self, _document: &Document, _api_key: &str, _model: &str, _max_length: usize, ) -> Result<String>

Generate a summary for a document using OpenRouter (stub when feature is disabled)

Source

pub async fn fetch_config(&self) -> Config

Fetch the current config

Source

pub async fn update_config(&self, config: Config) -> Result<Config>

Update the config

Overwrites the config in the config state and returns the updated config.

Source

pub async fn update_selected_role(&self, role_name: RoleName) -> Result<Config>

Update only the selected_role in the config without mutating the rest of the configuration. Returns the up-to-date Config object.

Auto Trait Implementations§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> MaybeSend for T
where T: Send,