terraphim_types
Core type definitions for the Terraphim AI system.
Overview
terraphim_types provides the fundamental data structures used throughout the Terraphim ecosystem for knowledge graph management, document indexing, search operations, and LLM-powered conversations.
Features
- Knowledge Graph Types: Build and query semantic knowledge graphs
- Document Management: Index and search documents from multiple sources
- Search Operations: Flexible queries with logical operators (AND/OR)
- Conversation Context: Manage LLM conversations with rich context
- LLM Routing: Priority-based routing to different AI providers
- Multi-Agent Coordination: Coordinate multiple AI agents
- WASM Support: TypeScript type generation for browser integration
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
For TypeScript/WASM support:
[]
= { = "1.0.0", = ["typescript"] }
Quick Start
Creating a Search Query
use ;
// Simple single-term query
let query = SearchQuery ;
// Multi-term AND query
let multi_query = with_terms_and_operator;
println!; // 3
Working with Documents
use Document;
let document = Document ;
println!;
Building a Knowledge Graph
use ;
let mut thesaurus = new;
// Add normalized terms
thesaurus.insert;
thesaurus.insert;
println!;
Managing Conversations
use ;
// Create a new conversation
let mut conversation = new;
// Add a user message
let mut user_msg = user;
// Add context from a document
let doc = Document ;
user_msg.add_context;
conversation.add_message;
// Add assistant response
let assistant_msg = assistant;
conversation.add_message;
println!;
LLM Routing with Priorities
use ;
// Create a high-priority routing rule for code tasks
let code_rule = new
.with_description
.with_tag;
// Create a routing decision
let decision = with_rule;
println!;
Type Categories
Knowledge Graph Types
NormalizedTermValue: Normalized, lowercase string valuesNormalizedTerm: Terms with unique IDs and URLsConcept: Abstract ideas in the knowledge graphNode: Graph nodes representing conceptsEdge: Connections between nodesThesaurus: Dictionary mapping terms to normalized concepts
Document Types
Document: Primary content unit with metadataIndex: Collection of indexed documentsIndexedDocument: Document reference with graph embeddings
Search Types
SearchQuery: Flexible search with logical operatorsLogicalOperator: AND/OR operators for multi-term queriesRelevanceFunction: Scoring algorithms (TitleScorer, BM25, TerraphimGraph)KnowledgeGraphInputType: Input source types (Markdown, JSON)
Context Management Types
Conversation: Multi-message conversation with contextChatMessage: Single message in a conversationContextItem: Contextual information for LLMContextType: Types of context (Document, SearchResult, KGTermDefinition, etc.)ConversationId,MessageId: Unique identifiers
Routing Types
Priority: Priority levels (0-100) for routing decisionsRoutingRule: Pattern-based routing rulesRoutingDecision: Final routing decisionRoutingScenario: Routing scenarios (Think, LongContext, WebSearch, etc.)PatternMatch: Pattern match results with scores
Multi-Agent Types
MultiAgentContext: Coordination between multiple agentsAgentInfo: Information about an AI agentAgentCommunication: Messages between agents
Features
TypeScript Support
Enable TypeScript type generation for WASM compatibility:
[]
= { = "1.0.0", = ["typescript"] }
This enables #[derive(Tsify)] on types, generating TypeScript definitions automatically.
Examples
See the examples directory in the main repository for more comprehensive examples:
- Knowledge graph construction
- Multi-term search queries
- Context-aware conversations
- LLM routing strategies
- Multi-agent coordination
Documentation
Full API documentation is available on docs.rs.
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.70 or later.
License
Licensed under Apache-2.0. See LICENSE for details.
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
Related Crates
- terraphim_automata: Text matching and autocomplete engine
- terraphim_rolegraph: Knowledge graph implementation
- terraphim_service: Main service layer
- terraphim_server: HTTP API server
Support
- Discord: https://discord.gg/VPJXB6BGuY
- Discourse: https://terraphim.discourse.group
- Issues: https://github.com/terraphim/terraphim-ai/issues