Documentation Index
Fetch the complete documentation index at: https://mintlify.com/S1LV4/th0th/llms.txt
Use this file to discover all available pages before exploring further.
Overview
th0th is built on a 4-layer architecture that separates concerns and enables protocol-agnostic integration. The core business logic is independent of transport protocols (MCP, HTTP), making it easy to extend and maintain.Core Layers
The@th0th-ai/core package implements a clean 4-layer architecture:
Tools Layer
Thin MCP handlers with schema validation and delegation to controllers
Controllers Layer
Orchestration logic that composes services and manages side effects
Services Layer
Domain logic for scoring, embedding, graph analysis, and compression
Data Layer
Persistence with SQLite, FTS5, and migrations
Layer Responsibilities
1. Tools Layer (packages/core/src/tools/)
- Schema definition and validation
- Protocol-specific request/response handling
- Thin delegation to controllers
- No business logic
packages/core/src/controllers/)
- Composes multiple services
- Manages side effects (logging, metrics)
- Transaction coordination
- Error handling and recovery
packages/core/src/services/)
- Pure domain logic
- Search algorithms (vector + keyword)
- Compression strategies
- Memory ranking and scoring
- No I/O dependencies
packages/core/src/data/)
- SQLite persistence
- Vector and keyword indexing
- Schema migrations
- Query optimization
This layered architecture allows th0th to support multiple protocols (MCP, HTTP, CLI) without duplicating business logic. The core package is protocol-agnostic.
Component Architecture
Semantic Search
The search system uses hybrid retrieval:- Vector search: Semantic similarity via embeddings (SQLite)
- Keyword search: BM25/FTS5 for exact matches
- RRF fusion: Reciprocal Rank Fusion with k=60 for optimal ranking
- Multi-level cache: L1 (memory) + L2 (SQLite) for 50%+ cache hit rate
Compression Pipeline
The compression system uses structure-preserving strategies:- Extracts imports, interfaces, classes, functions
- Keeps signatures and type definitions
- Removes implementation details
- Maintains code hierarchy and relationships
Memory System
Memories are organized in a hierarchical level system:- L0 (Persistent): Cross-session decisions and patterns
- L1 (Project): Project-specific code and architecture
- L2 (User): User preferences and settings
- L3 (Session): Conversation context (temporary)
Data Flow
Indexing Flow
File Discovery
Smart chunker scans project directory, respects
.gitignore, filters by allowed extensionsSmart Chunking
Language-aware splitting:
- Markdown: By headings with hierarchy
- JSON/YAML: By top-level keys
- Code: By functions/classes with comments
Dual Indexing
Parallel insertion into:
- Vector store (embeddings + metadata)
- Keyword search (FTS5 index)
Search Flow
Parallel Retrieval
If cache miss:
- Vector search (semantic similarity)
- Keyword search (BM25 scoring) Both run in parallel for speed
Storage Architecture
SQLite as the Foundation
th0th uses SQLite exclusively for all persistence:Vector Documents Table
Vector Documents Table
Keyword Search (FTS5)
Keyword Search (FTS5)
Search Cache Table
Search Cache Table
Memory Repository
Memory Repository
Why SQLite? It provides FTS5 for keyword search, JSON support for flexible metadata, BLOB storage for embeddings, and excellent performance for local-first applications.
Embedding Strategy
Provider Flexibility
th0th supports multiple embedding providers through a unified interface:| Provider | Model | Dimensions | Cost | Speed |
|---|---|---|---|---|
| Ollama (default) | nomic-embed-text | 768 | Free | Fast (local) |
| Ollama | bge-m3 | 1024 | Free | Fast (local) |
| Mistral | mistral-embed | 1024 | $$ | API |
| OpenAI | text-embedding-3-small | 1536 | $$ | API |
Batching Strategy
To prevent Ollama crashes on large files, th0th uses sub-batching:Performance Characteristics
Indexing
10 files/second with batched embedding and parallel FTS5 insertion
Search (cached)
< 5ms for L1 cache hits, < 20ms for L2 cache hits
Search (cold)
50-200ms depending on index size and result count
Compression
70-98% token reduction with structure preservation
Scalability
Project Isolation
Each project is namespaced byprojectId:
- Vector documents tagged with
project_id - Keyword search uses metadata filtering
- Cache entries scoped per project
- Memories can be project-level (L1)
Incremental Reindexing
TheIndexManager tracks file metadata to enable incremental updates:
Extension Points
Custom Compressors
ImplementICompressor interface:
Custom Vector Stores
ImplementIVectorStore interface to swap SQLite for ChromaDB, Pinecone, etc.:
Related Topics
Semantic Search
Deep dive into hybrid search and RRF fusion
Compression
Structure-preserving code compression strategies
Memory System
Hierarchical memory levels and ranking
Deployment
Contributing and extending th0th