Expand description
Core type definitions for the Terraphim AI system.
This crate provides the fundamental data structures used throughout the Terraphim ecosystem:
- Knowledge Graph Types:
Concept,Node,Edge,Thesaurus - Document Management:
Document,Index,IndexedDocument - Search Operations:
SearchQuery,LogicalOperator,RelevanceFunction - Conversation Context:
Conversation,ChatMessage,ContextItem - LLM Routing:
RoutingRule,RoutingDecision,Priority - Multi-Agent Coordination:
MultiAgentContext,AgentInfo
§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§
- Agent
Communication - Communication between agents in a multi-agent context
- Agent
Info - Information about an AI agent in a multi-agent context
- Chat
Message - Concept
- A concept is a higher-level, normalized term.
- Context
History - Context history that tracks what context has been used across conversations
- Context
History Entry - Entry in context usage history
- Context
Item - Context item that can be added to LLM conversations
- Conversation
- A conversation containing multiple messages and context
- Conversation
Id - Unique identifier for conversations
- Conversation
Summary - 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
- Indexed
Document - Reference to external storage of documents
- KGIndex
Info - Knowledge Graph index information
- KGTerm
Definition - Knowledge Graph term definition with comprehensive metadata
- Message
Id - Unique identifier for messages within conversations
- Multi
Agent Context - Multi-agent context for coordinating between different AI agents
- Node
- A
Noderepresents single concept and its connections to other concepts. - Normalized
Term - A normalized term is a higher-level term that has been normalized
- Normalized
Term Value - The value of a normalized term
- Pattern
Match - Result of pattern matching with priority scoring
- Priority
- Priority level for routing rules and decisions Higher numeric values indicate higher priority
- Role
Name - A role name with case-insensitive lookup support.
- Routing
Decision - Routing decision with priority information
- Routing
Rule - A routing rule with pattern matching and priority
- Search
Query - 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§
- Context
Type - Types of context that can be added to conversations
- Context
Usage Type - How a context item was used
- Knowledge
Graph Input Type - Defines all supported inputs for the knowledge graph.
- Logical
Operator - Logical operators for combining multiple search terms
- Relevance
Function - Defines the relevance function (scorer) to be used for ranking search
results for the
Role. - Routing
Scenario - Routing scenario types