Crate terraphim_types

Crate terraphim_types 

Source
Expand description

Core type definitions for the Terraphim AI system.

This crate provides the fundamental data structures used throughout the Terraphim ecosystem:

§Features

  • typescript: Enable TypeScript type generation via tsify for WASM compatibility

§Examples

§Creating a Search Query

use terraphim_types::{SearchQuery, NormalizedTermValue, LogicalOperator, RoleName};

// Simple single-term query
let query = SearchQuery {
    search_term: NormalizedTermValue::from("rust"),
    search_terms: None,
    operator: None,
    skip: None,
    limit: Some(10),
    role: Some(RoleName::new("engineer")),
};

// Multi-term AND query
let multi_query = SearchQuery::with_terms_and_operator(
    NormalizedTermValue::from("async"),
    vec![NormalizedTermValue::from("programming")],
    LogicalOperator::And,
    Some(RoleName::new("engineer")),
);

§Working with Documents

use terraphim_types::Document;

let document = Document {
    id: "doc-1".to_string(),
    url: "https://example.com/article".to_string(),
    title: "Introduction to Rust".to_string(),
    body: "Rust is a systems programming language...".to_string(),
    description: Some("A guide to Rust".to_string()),
    summarization: None,
    stub: None,
    tags: Some(vec!["rust".to_string(), "programming".to_string()]),
    rank: None,
    source_haystack: None,
};

§Building a Knowledge Graph

use terraphim_types::{Thesaurus, NormalizedTermValue, NormalizedTerm};

let mut thesaurus = Thesaurus::new("programming".to_string());
thesaurus.insert(
    NormalizedTermValue::from("rust"),
    NormalizedTerm::new(1, NormalizedTermValue::from("rust programming language"))
        .with_url("https://rust-lang.org".to_string())
);

Structs§

AgentCommunication
Communication between agents in a multi-agent context
AgentInfo
Information about an AI agent in a multi-agent context
ChatMessage
Concept
A concept is a higher-level, normalized term.
ContextHistory
Context history that tracks what context has been used across conversations
ContextHistoryEntry
Entry in context usage history
ContextItem
Context item that can be added to LLM conversations
Conversation
A conversation containing multiple messages and context
ConversationId
Unique identifier for conversations
ConversationSummary
Summary of a conversation for listing purposes
Document
The central document type representing indexed and searchable content.
Edge
Index
An index is a hashmap of documents
IndexedDocument
Reference to external storage of documents
KGIndexInfo
Knowledge Graph index information
KGTermDefinition
Knowledge Graph term definition with comprehensive metadata
MessageId
Unique identifier for messages within conversations
MultiAgentContext
Multi-agent context for coordinating between different AI agents
Node
A Node represents single concept and its connections to other concepts.
NormalizedTerm
A normalized term is a higher-level term that has been normalized
NormalizedTermValue
The value of a normalized term
PatternMatch
Result of pattern matching with priority scoring
Priority
Priority level for routing rules and decisions Higher numeric values indicate higher priority
RoleName
A role name with case-insensitive lookup support.
RoutingDecision
Routing decision with priority information
RoutingRule
A routing rule with pattern matching and priority
SearchQuery
A search query for finding documents in the knowledge graph.
Thesaurus
A thesaurus is a dictionary with synonyms which map to upper-level concepts.

Enums§

ContextType
Types of context that can be added to conversations
ContextUsageType
How a context item was used
KnowledgeGraphInputType
Defines all supported inputs for the knowledge graph.
LogicalOperator
Logical operators for combining multiple search terms
RelevanceFunction
Defines the relevance function (scorer) to be used for ranking search results for the Role.
RoutingScenario
Routing scenario types