Skip to main content

Crate terraphim_types

Crate terraphim_types 

Source
Expand description

Core type definitions for the Terraphim AI system.

The implementation is decomposed into cohesive domain modules; every historical public path is preserved through explicit re-exports at the crate root so existing consumers continue to compile unchanged:

§Features

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

§Examples

§Creating a Search Query

use terraphim_types::{SearchQuery, NormalizedTermValue, Layer, 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")),
    layer: Layer::default(),
    include_pinned: false,
    min_quality: None,
};

// 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, DocumentType};

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,
    doc_type: DocumentType::KgEntry,
    synonyms: None,
    route: None,
    priority: None,
    quality_score: 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::with_auto_id(NormalizedTermValue::from("rust programming language"))
        .with_url("https://rust-lang.org".to_string())
);

Re-exports§

pub use role::RoleName;
pub use term::Concept;
pub use term::NormalizedTerm;
pub use term::NormalizedTermValue;
pub use graph::Edge;
pub use graph::Node;
pub use graph::Thesaurus;
pub use document::Document;
pub use document::DocumentType;
pub use document::Index;
pub use document::IndexedDocument;
pub use document::QualityScore;
pub use document::extract_first_paragraph;
pub use document::MarkdownDirectives;
pub use route::RouteDirective;
pub use search::KnowledgeGraphInputType;
pub use search::Layer;
pub use search::LogicalOperator;
pub use search::RelevanceFunction;
pub use search::SearchQuery;
pub use conversation::ChatMessage;
pub use conversation::ContextHistory;
pub use conversation::ContextHistoryEntry;
pub use conversation::ContextItem;
pub use conversation::ContextType;
pub use conversation::ContextUsageType;
pub use conversation::Conversation;
pub use conversation::ConversationId;
pub use conversation::ConversationSummary;
pub use conversation::KGIndexInfo;
pub use conversation::KGTermDefinition;
pub use conversation::MessageId;
pub use conversation::RotStatus;
pub use routing::PatternMatch;
pub use routing::Priority;
pub use routing::RoutingDecision;
pub use routing::RoutingRule;
pub use routing::RoutingScenario;
pub use agent::AgentCommunication;
pub use agent::AgentInfo;
pub use agent::MultiAgentContext;
pub use ontology::CoverageSignal;
pub use ontology::ExtractedEntity;
pub use ontology::ExtractedRelationship;
pub use ontology::GroundingMetadata;
pub use ontology::NormalizationMethod;
pub use ontology::OntologyAntiPattern;
pub use ontology::OntologyEntityType;
pub use ontology::OntologyRelationshipType;
pub use ontology::OntologySchema;
pub use ontology::SchemaSignal;
pub use validation::ValidationError;
pub use validation::preview;
pub use validation::stable_id;
pub use validation::truncate_utf8_safe;
pub use validation::validate_score;
pub use persona::CharacteristicDef;
pub use persona::PersonaDefinition;
pub use persona::PersonaLoadError;
pub use persona::SfiaSkillDef;
pub use llm_usage::LlmResult;
pub use llm_usage::LlmUsage;
pub use llm_usage::ModelPricing;
pub use review::FindingCategory;
pub use review::FindingSeverity;
pub use review::ReviewAgentOutput;
pub use review::ReviewFinding;
pub use review::deduplicate_findings;
pub use capability::*;
pub use mcp_tool::*;
pub use procedure::*;

Modules§

agent
Multi-agent coordination domain.
capability
Capability-based routing types for unified LLM and Agent providers.
conversation
Conversation domain: LLM conversations, context items and usage history.
document
Document domain: indexed content documents and quality scoring.
graph
Graph domain: knowledge graph nodes, edges and thesauri.
llm_usage
LLM usage tracking types for cost monitoring across providers.
mcp_tool
MCP Tool types for indexing and discovery.
ontology
Ontology domain: schema-first knowledge graph definitions and grounding metadata.
persona
Persona definition types for agent personas with SFIA skill framework support.
procedure
Procedure capture types for the learning system.
review
Review finding types for multi-agent code review.
role
Role domain: user profile / persona naming types.
route
Routing directive types parsed from markdown KG entry front matter.
routing
Routing domain: priority, routing rules, matches and decisions.
score
Scoring algorithms and query types for document relevance ranking. Scoring algorithms and query types for document relevance ranking.
search
Search domain: queries, logical operators, output layers and relevance functions.
term
Term domain: normalised term values, normalised terms and concepts.
validation
Core type invariants: validated construction, stable identity derivation and UTF-8-safe preview helpers.