Skip to main content

๐Ÿ›๏ธ TelaMentis Architecture Deep-Dive

This document provides a comprehensive overview of TelaMentis's architecture, design principles, components, and data flows as implemented in Phase 1.

1. Vision & Design Principlesโ€‹

Mission: Offer an open, composable, realโ€‘time knowledge graph that any AI agent can treat as durable, searchable memory.

TelaMentis is built upon a set of guiding principles:

PrincipleWhy it MattersCurrent Implementation (Phase 1)
Pluggability Over CompletenessThe AI and data landscape evolves rapidly; no single solution fits all.โœ… Trait-based adapter system with Neo4j, OpenAI, and FastAPI adapters implemented.
Realโ€‘time FirstAI agents require millisecond-scale feedback loops for effective interaction.โœ… Async Rust core with millisecond graph operations via Neo4j.
Thin Core, Fat EdgesKeep the invariant kernel small, stable, and secure, allowing plugins to innovate quickly.โœ… Core defines abstract types and business logic; adapters handle implementation details.
Dogโ€‘foodable Locally, Scalable in the CloudOSS adoption often begins on a developer's laptop and must scale to production.โœ… docker-compose for local dev; cloud deployment patterns documented.
Memory Safety & ConcurrencyReliability and performance are paramount for a core infrastructure piece.โœ… Rust's ownership model prevents data races; extensive async/await usage.
Code is the SpecWritten documentation can drift; traits and tests provide the ground truth.โœ… Comprehensive trait definitions with test coverage.

2. System Diagramโ€‹

The following diagram illustrates the current Phase 1 architecture:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      HTTP/JSON (FastAPI)       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ โ”‚
โ”‚ AI Agents / โ”‚ Direct Binary (kgctl) โ”‚ Presentation Layer โ”‚
โ”‚ External Systems โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ (Adapters) โ”‚
โ”‚ โ”‚ โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ (GraphService trait)
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚
โ”‚ TelaMentis Core โ”‚
โ”‚ (Rust) โ”‚
โ”‚ - Domain Types โ”‚
โ”‚ - Business Logic โ”‚
โ”‚ - Trait Definitionsโ”‚
โ”‚ - Tenant Managementโ”‚
โ”‚ - Temporal Logic โ”‚
โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ (GraphStore, LlmConnector traits)
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ Storage Adapters โ”‚ โ”‚ LLM Connector Adapters โ”‚ โ”‚ Source/Ingest Adapters โ”‚
โ”‚ โœ… Neo4j โ”‚ โ”‚ โœ… OpenAI โ”‚ โ”‚ โœ… CSV (via kgctl) โ”‚
โ”‚ ๐Ÿ”„ In-Memory (Phase 2) โ”‚ โ”‚ ๐Ÿ”„ Anthropic (Phase 2) โ”‚ โ”‚ ๐Ÿ”„ Kafka (Phase 2) โ”‚
โ”‚ ๐Ÿ”„ Memgraph (Community) โ”‚ โ”‚ ๐Ÿ”„ Gemini (Phase 2) โ”‚ โ”‚ ๐Ÿ”„ MCP (Phase 2) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ bolt / sdk โ”‚ HTTP API โ”‚ File/Stream
โ”‚ โ”‚ โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ Neo4j Database โ”‚ โ”‚ OpenAI API โ”‚ โ”‚ Data Sources โ”‚
โ”‚ (bolt://localhost:7687)โ”‚ โ”‚ (api.openai.com) โ”‚ โ”‚ (CSV, JSON, etc.) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Legend:

  • โœ… Implemented in Phase 1
  • ๐Ÿ”„ Planned for Phase 2
  • ๐Ÿ”ฎ Future phases

3. Component Breakdownโ€‹

3.1. TelaMentis Core (telamentis-core)โ€‹

Status: โœ… Complete

The heart of the system, implemented in Rust. Current capabilities:

  • Domain Model: Complete implementation of Node, TimeEdge, TenantId, GraphQuery, and Path types.
  • Business Logic: Core operations for graph management, temporal reasoning, and multi-tenancy enforcement.
  • Trait Definitions: Well-defined contracts for all pluggable components:
    • GraphStore: Storage backend interface
    • LlmConnector: LLM service interface
    • PresentationAdapter: Network transport interface
    • SourceAdapter: Data ingestion interface
  • Configuration Management: Environment variable and file-based configuration.
  • Error Handling: Comprehensive error types for all operations.
  • Temporal Utilities: Allen's Interval Algebra and temporal reasoning helpers.

3.2. Presentation Layer (Adapters)โ€‹

FastAPI Bridge (โœ… Implemented)โ€‹

  • Python FastAPI wrapper for HTTP/JSON API
  • Rust Axum server for high-performance HTTP handling
  • Complete REST API for all CRUD operations
  • OpenAPI documentation auto-generated
  • CORS support for web applications
  • Comprehensive error handling and response formatting

Future Adapters (๐Ÿ”„ Phase 2)โ€‹

  • gRPC (Rust): For high-performance, low-latency communication
  • Unix Domain Sockets (UDS): For same-host IPC with minimal overhead

3.3. Storage Layer (Adapters)โ€‹

Neo4j Adapter (โœ… Implemented)โ€‹

  • Complete GraphStore implementation with all required methods
  • Tenant isolation via _tenant_id property on all nodes and edges
  • Bitemporal support with valid_from/valid_to on relationships
  • Automatic indexing for performance optimization
  • Query translation from GraphQuery to Cypher
  • Connection pooling and error handling
  • Health checks and monitoring

Sample Neo4j Integration:

// Create store with configuration
let config = Neo4jConfig::new("bolt://localhost:7687")
.with_auth("neo4j", "telamentis123")
.with_max_connections(10);

let store = Neo4jStore::new(config).await?;

// All operations are tenant-scoped
let tenant = TenantId::new("my_tenant");
let node_id = store.upsert_node(&tenant, node).await?;

Future Adapters (๐Ÿ”„ Phase 2)โ€‹

  • In-Memory: For testing and development
  • Memgraph: Community-driven adapter
  • Neptune: For AWS environments

3.4. LLM Connector Adaptersโ€‹

OpenAI Connector (โœ… Implemented)โ€‹

  • Complete LlmConnector implementation for OpenAI models
  • Structured extraction with JSON schema validation
  • Cost tracking and token usage monitoring
  • Configurable models (GPT-4, GPT-3.5-turbo, etc.)
  • Error handling for API failures and rate limiting
  • Confidence scoring integration

Sample OpenAI Integration:

// Configure OpenAI connector
let config = OpenAiConfig::new(api_key)
.with_model("gpt-4")
.with_max_tokens(1000)
.with_temperature(0.1);

let connector = OpenAiConnector::new(config)?;

// Extract structured knowledge
let context = ExtractionContext {
messages: vec![LlmMessage {
role: "user".to_string(),
content: "Alice works at Acme Corp".to_string(),
}],
system_prompt: Some("Extract entities and relationships".to_string()),
// ...
};

let envelope = connector.extract(&tenant, context).await?;

Future Connectors (๐Ÿ”„ Phase 2)โ€‹

  • Anthropic: For Claude models
  • Gemini: For Google's models
  • Local/Open Source: For on-premise deployments

3.5. Source/Ingest Adaptersโ€‹

CSV Loader (โœ… Implemented via kgctl)โ€‹

  • Flexible CSV parsing with configurable delimiters
  • Batch processing for large datasets
  • Column mapping for nodes and relationships
  • Temporal data support with date parsing
  • Error handling and validation

Future Adapters (๐Ÿ”„ Phase 2)โ€‹

  • Kafka Consumer: For real-time data streams
  • MCP (Message Change Protocol): For event-driven architectures
  • Generic REST: For pulling data from APIs

3.6. kgctl (Command-Line Interface)โ€‹

Status: โœ… Complete

A comprehensive CLI tool for all TelaMentis operations:

  • Tenant Management: Create, list, describe, delete tenants
  • Data Ingestion: CSV import with flexible configuration
  • Data Export: Multiple formats (GraphML, JSON, Cypher, CSV)
  • Query Execution: Both structured and raw queries
  • Health Monitoring: System health checks
  • Configuration: File-based and environment variable configuration

Example Usage:

# Create tenant
kgctl tenant create demo --name "Demo Tenant"

# Import data
kgctl ingest csv --tenant demo --file data.csv --id-col id --label Person

# Query data
kgctl query nodes --tenant demo --labels Person --limit 10

# Export data
kgctl export --tenant demo --format graphml --output graph.xml

4. Key Trait Signaturesโ€‹

These Rust traits define the extension points of TelaMentis (simplified for clarity):

#[async_trait]
pub trait GraphStore: Send + Sync {
async fn upsert_node(&self, tenant: &TenantId, node: Node) -> Result<Uuid, GraphError>;
async fn upsert_edge(&self, tenant: &TenantId, edge: TimeEdge) -> Result<Uuid, GraphError>;
async fn query(&self, tenant: &TenantId, query: GraphQuery) -> Result<Vec<Path>, GraphError>;
async fn get_node(&self, tenant: &TenantId, id: Uuid) -> Result<Option<Node>, GraphError>;
async fn delete_node(&self, tenant: &TenantId, id: Uuid) -> Result<bool, GraphError>;
async fn health_check(&self) -> Result<(), GraphError>;
}

#[async_trait]
pub trait LlmConnector: Send + Sync {
async fn extract(&self, tenant: &TenantId, context: ExtractionContext) -> Result<ExtractionEnvelope, LlmError>;
async fn complete(&self, tenant: &TenantId, request: CompletionRequest) -> Result<CompletionResponse, LlmError>;
}

#[async_trait]
pub trait PresentationAdapter: Send + Sync {
async fn start(&self, core_service: Arc<dyn GraphService>) -> Result<(), PresentationError>;
async fn stop(&self) -> Result<(), PresentationError>;
}

5. Data Flow Example: LLM-based Knowledge Extractionโ€‹

Here's how knowledge extraction works in the current implementation:

  1. Agent Request: AI agent sends HTTP POST to FastAPI endpoint /v1/llm/{tenant_id}/extract
  2. Request Validation: FastAPI bridge validates tenant ID and request format
  3. Core Service: Request forwarded to TelaMentis core GraphService
  4. LLM Connector: Core selects OpenAI connector based on configuration
  5. API Call: OpenAI connector formats prompt and calls OpenAI API
  6. Response Parsing: JSON response parsed into ExtractionEnvelope
  7. Validation: Schema validation and confidence scoring applied
  8. Graph Updates: Extracted nodes and edges upserted to Neo4j via GraphStore
  9. Response: Success response returned to agent with metadata

6. Current Workspace Structureโ€‹

TelaMentis/
โ”œโ”€โ”€ Cargo.toml # โœ… Workspace definition
โ”œโ”€โ”€ core/ # โœ… TelaMentis-core implementation
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ lib.rs # โœ… Core library
โ”‚ โ”‚ โ”œโ”€โ”€ types.rs # โœ… Domain types
โ”‚ โ”‚ โ”œโ”€โ”€ traits.rs # โœ… Plugin interfaces
โ”‚ โ”‚ โ”œโ”€โ”€ errors.rs # โœ… Error handling
โ”‚ โ”‚ โ”œโ”€โ”€ temporal.rs # โœ… Temporal utilities
โ”‚ โ”‚ โ””โ”€โ”€ tenant.rs # โœ… Multi-tenancy
โ”œโ”€โ”€ adapters/
โ”‚ โ””โ”€โ”€ neo4j/ # โœ… Neo4j GraphStore adapter
โ”‚ โ””โ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ lib.rs # โœ… Main implementation
โ”‚ โ”œโ”€โ”€ config.rs # โœ… Configuration
โ”‚ โ”œโ”€โ”€ queries.rs # โœ… Cypher queries
โ”‚ โ””โ”€โ”€ utils.rs # โœ… Utilities
โ”œโ”€โ”€ connectors/
โ”‚ โ””โ”€โ”€ openai/ # โœ… OpenAI LlmConnector
โ”‚ โ””โ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ lib.rs # โœ… Main implementation
โ”‚ โ”œโ”€โ”€ config.rs # โœ… Configuration
โ”‚ โ””โ”€โ”€ models.rs # โœ… API models
โ”œโ”€โ”€ presentation/
โ”‚ โ””โ”€โ”€ fastapi-bridge/ # โœ… FastAPI PresentationAdapter
โ”‚ โ”œโ”€โ”€ src/ # โœ… Rust Axum server
โ”‚ โ”œโ”€โ”€ main.py # โœ… Python FastAPI wrapper
โ”‚ โ””โ”€โ”€ Dockerfile # โœ… Container setup
โ”œโ”€โ”€ kgctl/ # โœ… CLI tool
โ”‚ โ””โ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ main.rs # โœ… CLI entry point
โ”‚ โ”œโ”€โ”€ cli.rs # โœ… Argument parsing
โ”‚ โ”œโ”€โ”€ config.rs # โœ… Configuration
โ”‚ โ”œโ”€โ”€ client.rs # โœ… HTTP client
โ”‚ โ””โ”€โ”€ commands/ # โœ… Command implementations
โ”œโ”€โ”€ docs/ # โœ… Documentation
โ”œโ”€โ”€ docker-compose.yml # โœ… Development environment
โ””โ”€โ”€ Makefile # โœ… Development tasks

7. Configuration Strategyโ€‹

TelaMentis uses a layered configuration approach:

  1. Environment Variables (Highest precedence): TELAMENTIS_* prefixed variables
  2. Configuration Files: YAML/TOML files (e.g., kgctl.yaml)
  3. Code Defaults: Sensible fallbacks

Example Configuration:

# kgctl.yaml
default_endpoint: "http://localhost:8000"
default_tenant: "my_tenant"
timeout: 30

# Environment variables
TELAMENTIS_NEO4J_URL=bolt://localhost:7687
TELAMENTIS_NEO4J_PASSWORD=telamentis123
OPENAI_API_KEY=sk-...

8. Current Deployment Topologiesโ€‹

8.1. Local Development (โœ… Implemented)โ€‹

+-----------------------------------------------------+
| Host Machine (Docker) |
| +-------------------+ HTTP +--------------------+ |
| | AI Agent / kgctl | โ‡„ ---- | FastAPI (Python) | |
| | | | (Port 8000) | |
| +-------------------+ +--------โ”ฌ-----------+ |
| โ”‚ IPC |
| +--------โ–ผ-----------+ |
| | TelaMentis Core | |
| | (Rust, embedded) | |
| +--------โ”ฌ-----------+ |
| โ”‚ Bolt |
| +--------โ–ผ-----------+ |
| | Neo4j (Docker) | |
| | (Port 7687) | |
| +--------------------+ |
+-----------------------------------------------------+

8.2. Future Production Deployment (๐Ÿ”„ Phase 2)โ€‹

  • Kubernetes: Helm charts for scalable deployment
  • Docker Swarm: Multi-node development clusters
  • Cloud Services: Integration with managed Neo4j, Redis, etc.

9. Performance Characteristics (Phase 1)โ€‹

Based on initial testing with the current implementation:

OperationTypical LatencyThroughputNotes
Node Upsert1-5ms1K-5K ops/secVia Neo4j adapter
Edge Upsert2-8ms500-2K ops/secWith relationship creation
Simple Query5-20ms200-1K queries/secDepends on complexity
LLM Extraction1-5 secondsLimited by OpenAI APIIncludes network latency
CSV ImportVariable1K-10K records/secBatch processing

Performance will be optimized and benchmarked more thoroughly in Phase 2.

10. What's Next (Phase 2 Roadmap)โ€‹

The current architecture provides a solid foundation for Phase 2 enhancements:

  • Request Processing Pipeline: Internal plugin system for request lifecycle
  • Additional Adapters: In-memory storage, gRPC transport, more LLM connectors
  • Advanced Temporal Features: Transaction time support, complex temporal queries
  • Performance Optimizations: Connection pooling, caching, query optimization
  • Monitoring & Observability: Metrics, tracing, health dashboards

The modular architecture ensures these enhancements can be added without breaking existing functionality.


This architecture documentation reflects the current Phase 1 implementation. As TelaMentis evolves, this document will be updated to reflect new capabilities and architectural decisions.