TreeDB · Next-Generation B+Tree Engine

Compressed copy-on-write B+Tree engine built for speed, durability, and RAM and disk efficiency.

The TreeDB compression engine gets more out of every machine. Documents, key-value data, and secondary, natural language text, and HNSW vector indexes are highly compressed, stretching capacity and making the most of your I/O bandwidth.

Set TreeDB up as a multi-node Raft cluster, a Mongo-compatible gateway, a faster native wire API, or an embedded Go engine.

vs. MongoDB 9
1.5×–4.4× faster
Wins all 0..32 index counts · 14× smaller gateway disk
vs. SQLite WAL
983k/s · 15.5 B/doc
2.7× faster insert & 10.1× smaller compacted (2 idx)
vs. Milvus Server
10,853 QPS · 4.9 ms
4.8× QPS & 5.2× lower p95 @ .9525 recall (100k)
vs. XERJ
153 MiB · 6.2× faster
18.3× less RAM · 6/6 BEIR nDCG@10 sweep
Architecture · Memtable + Copy-on-Write B+Tree + Command WAL

TreeDB pairs LSM memtable and WAL best practices with a compressed copy-on-write B+Tree storage engine.

LSM engines absorb write bursts well by appending to a WAL and sorting in a memtable, but they pay a recurring cost in the background: keys are rewritten across multiple SSTable levels during compaction, and point lookups or range scans must merge across overlapping files. Traditional B+Trees keep every key in a single ordered tree for direct reads, but random updates rewrite whole pages in place and uncompressed secondary indexes quickly outgrow memory.

TreeDB keeps the write-buffering front end of an LSM and replaces multi-level SSTables with one copy-on-write B+Tree. Mutations append to a segmented Command WAL, batch inside an arena-allocated memtable, and flush into the B+Tree in sorted passes. Outer leaf pages and secondary, lexical text, and HNSW vector indexes are packed with dictionary ZSTD in a persistent value log, keeping internal routing pages small enough to stay resident in RAM.

01

High-Throughput Reads & Writes

Sequential Command WAL + arena memtable absorb write bursts and flush via sorted batched zipper splits, while queries hit one canonical B+Tree with lock-free snapshots and zero SSTable level merges.

4.94M reads/s202.6 ns/op concurrent · 0 B/op
02

Compressed Outer Leaves & Indexes

Dictionary-ZSTD K=32 packed outer leaves live in a persistent value log alongside compressed secondary, text, and vector indexes so internal B+Tree routing nodes stay hot in RAM.

15.5 B/docvs. 156.7 B/doc SQLite VACUUM (2 idx)
03

Crash-Safe Durability & Value-Log GC

Checksummed segmented Command WAL redo paired with atomic copy-on-write root publishing means live pages are never overwritten in place, backed by online reachability GC.

Zero torn pagescommand_wal_durable default
04

Multi-Node Raft Consensus & Scale

Built-in Raft replication, snapshot-boundary streaming, and placement routing scale from a single local directory to a multi-node cluster without external coordination services.

Native RaftClustered & single-node modes
Dimension Classic Mutable B+Tree Multi-Level LSM-Tree TreeDB (Memtable + COW B+Tree + WAL)
Point & Range Retrieval Single ordered tree walk Merges across Memtable + L0 + multi-level SSTables Single canonical COW B+Tree, lock-free snapshots, hot RAM routing pages
Random Write Path Full-page in-place rewrites & page latches Fast ingest, followed by recurring L0→L6 compaction rewrites Sequential Command WAL + arena Memtable flushed via sorted batched splits
Index & Leaf Footprint 30%–50% page slack; uncompressed secondary indexes Block-compressed SSTables across levels Dictionary-ZSTD outer leaves + compressed secondary, text & vector indexes
Crash Recovery & GC Page journals / double-write buffers WAL + multi-file MANIFEST replay Segmented Command WAL + atomic root publish + persistent value-log GC
Batteries Included · One Cohesive Stack

Ready for real workloads out of the box.

Most storage engines stop at raw byte slices and leave indexing, search, replication, and wire protocols up to you. Every capability on the right runs natively on TreeDB's compressed, durable core.

Documents & KV

Compressed Secondary Indexes

Typed template-v1, BSON, and JSON collections with unique and non-unique secondary indexes.

Lexical Search

Block-Max WAND Text-v2

Code-aware BM25F, Porter2 stemming, fuzzy lexicon expansion, and streaming exact phrase search.

Vector & Hybrid

Column-Graph HNSW + SQ8

Persisted cosine HNSW with scalar_u8 candidate scoring + FP32 rerank at 0 B/op.

Cluster & Wire

Multi-Node Raft & Mongo Gateway

Connect standard MongoDB drivers, run the faster native TCP server, or replicate across Raft peers.

Pre-alpha status: on-disk layouts evolve rapidly. Standalone root module extraction (treedb.dev) is tracked in snissn/gomap#5972.

package main

import (
	"fmt"
	"log"

	treedb "github.com/snissn/gomap/TreeDB"
)

func main() {
	opts := treedb.OptionsFor(treedb.ProfileCommandWALDurable, "./my-db")
	db, err := treedb.Open(opts)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	if err := db.Set([]byte("commit:head"), []byte("deadbeef2")); err != nil {
		log.Fatal(err)
	}
	val, err := db.Get([]byte("commit:head"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(val))
}
# Run the faster native wire server
go build -o bin/treedb-native-server ./cmd/treedb-native-server
./bin/treedb-native-server \
  -dir ./data-native \
  -profile command_wal_durable \
  -addr 127.0.0.1:17130

# Or run the Mongo-compatible wire gateway (standard BSON drivers)
go build -o bin/treedb-mongo-gateway ./TreeDB/mongo_gateway/server.go
./bin/treedb-mongo-gateway \
  -dir ./data-mongo \
  -profile command_wal_durable \
  -document-format bson \
  -addr 127.0.0.1:27130
# Install static CGO_ENABLED=0 binary (macOS & Linux, SHA-256 verified)
curl -fsSL https://treedb.dev/install.sh | sh

# Register multiple repositories under one daemon
treedb-repo-mcp repo add ~/dev/repo-a
treedb-repo-mcp repo add ~/dev/repo-b --no-github
treedb-repo-mcp sync --config ~/.config/treedb-mcp/repos.toml

# Commit-pinned query (verifies exact git ref or overlays diff-tree delta)
treedb-repo-mcp query --repo owner/repo-a --ref HEAD "InstalledSnapshotBoundary"
Measured Performance

Scoped, reproducible benchmarks — caveats included.

Every row below comes from checked-in harnesses against MongoDB 9, SQLite, Milvus, Qdrant, and XERJ with explicit durability and topology boundaries.

Workload Boundary / Profile TreeDB Comparator Headline Delta
Mongo API 0..32 Secondary Indexes (100k BSON) Mongo gateway · relaxed / durable 607,941 docs/s @ 2 idx (81 B/doc du) 219,095 docs/s (MongoDB 9.0.8) 1.54×–4.40× faster across all 0..32 idx; 14× smaller gateway du
Indexed Collection Insert (100k docs, 2 idx) template-v1 · outer leaves in vlog 983,445 docs/s · 15.5 B/doc 370,370 docs/s · 156.7 B/doc (SQLite WAL) 2.66× faster insert, 10.1× smaller compacted; 4.94M reads/s
Vector Server Matched-Recall (100k × 128d, c=32) Single daemon vs. containerized server 10,853 QPS · 4.87 ms p95 (.9525) 2,257 QPS · 25.41 ms p95 (Milvus, .9210) 4.8× higher QPS, 5.2× lower p95 (2.9× vs. pgvector 3,746 QPS)
Same-Host 500K × 768d Vector Search SQ8 + FP32 rerank · 6-CPU budget 2,522 QPS @ 97.50% recall@10 2,197 QPS @ 95.55% (Qdrant 1.19 gRPC) +19.1% 1-client / +14.8% 6-client QPS at higher recall
Agent Repo + GitHub Search (1.06 GiB + 500 PRs) command_wal_durable 153 MiB RSS (6.6 ms p50) 2.73 GiB RSS (XERJ, 120 ms p50) 18.3× less RAM, 6.2× faster ingest, 14.5× fewer agent tokens

Full host configurations, server vs. in-process boundaries, and workload trade-offs are documented on /benchmarks.

For AI Coding Agents

Stop feeding stale branches and 20k-token file dumps to your agent.

Install treedb-repo-mcp or @snissn/pi-treedb for commit-verified code search, pure-Go AST symbols, GitHub history, and code-linked memory in one static binary at 47 MiB idle RAM.

Explore TreeDB for Agents →
For Systems & Application Engineers

Run TreeDB embedded, as a Mongo gateway, or as a Raft cluster.

Read the durability profile guide, embedded Go quickstart, and server flags — or inspect the standalone module extraction roadmap.

Read Documentation →