Four-in-One Embedded DB · Built for Agenvoy

One Import.
KV, JSON, and Vector Search.

ToriiDB is a four-in-one embedded Go database — Redis-style commands, MongoDB-style JSON queries, and OpenAI-powered semantic search, all persisted by an append-only log behind a single import.

go get github.com/agenvoy/toriidb
toriidb
make test
  toriidb 16 databases · ./temp · embed dim 256
 
toriidb[0] SET user:1 {"name":"Pardn","plan":"pro"}
  OK
toriidb[0] GET user:1.name
  Pardn
toriidb[0] QUERY plan == "pro" AND name LIKE "P*"
  1) user:1
 
toriidb[0] SET doc:1 "exponential backoff with jitter" VECTOR
  OK
toriidb[0] VSEARCH retry strategy LIMIT 3
  1) doc:1
Features

Three Databases, One Binary

Cache, documents, and vectors behind a single command surface — a single Go import with no external services.

Redis × Mongo × Vector

Redis-style KV commands, MongoDB-style field predicates, and semantic search behind one API — cache, document lookup, and similarity retrieval together.

Inline Per-Key Vectors

SET ... VECTOR attaches an OpenAI embedding directly to the key — no sidecar store. The vector rides AOF and compaction alongside the value.

Content-Addressed Cache

Embeddings cache under __torii:embed:<sha256>. Identical text never hits the OpenAI API twice — even across restarts.

🔍

Top-K Cosine Search

VSEARCH linear-scans with a min-heap, filters by glob MATCH, honours LIMIT, and skips expired or dimension-mismatched entries.

16 Databases, Lazy Replay

Redis-compatible DB 0-15 namespaces, each with its own memory and AOF. Replay happens only on first access — startup stays free.

💾

Dual Persistence

AOF appends every write in order, while each key also lands as a JSON snapshot under an MD5 three-level directory for external tooling.

{}

In-Place JSON Field Ops

GET / SET / DEL / INCR operate on nested fields via dot-notation — no read-modify-write round trips.

∧∨

Infix Query Expression

QUERY supports AND / OR / NOT with parentheses, exposed both as composable structs and as string expressions for untrusted input.

🔒

Reserved Namespace

Scan commands skip the __torii:* prefix, so internal keys like the embedding cache never leak into KEYS, FIND, QUERY, or VSEARCH.

Write Path

One Way In, by Design

Every mutation flows through a single Exec router, then fans out to memory, the append log, and a JSON snapshot — no side doors.

Step 1

Exec

Parse the command and route it through the single uppercase command switch.

exec.go
Step 2

Memory

Apply to the per-DB in-memory map and warm the parsed JSON cache.

map[string]*Entry
Step 3

AOF

Append the record — with optional base64 vector — to the per-DB log.

record.aof
Step 4

Snapshot

Mirror the key as a JSON file under an MD5 three-level directory tree.

md5 snapshot
Types

Automatic Type Detection

Values are classified on write and reported by TYPE — no schema, no declarations.

{}

JSON

Objects and arrays, validated on write

Aa

String

UTF-8 text fallback

42

Int

Whole numbers via ParseInt

.5

Float

Decimals via ParseFloat

Bool

true / false literals

📅

Date

RFC3339 or YYYY-MM-DD

Commands

One Command Surface

Redis-familiar verbs route through a single Exec switch — dot-notation keys turn any value op into a JSON field op.

Core & Lifecycle

Set, read, and expire values. A dot in the key (user:1.name) targets a nested JSON field.

SET <k> <v> [NX|XX] [secs] [VECTOR] GET <k> DEL <k> [k2 ...] EXIST <k> TYPE <k> INCR <k> [delta] KEYS <pattern> TTL · EXPIRE · EXPIREAT · PERSIST SELECT <db> (0-15)

Query & Vector

Scan documents by predicate and search by meaning. FIND/QUERY take an optional LIMIT.

FIND <op> <value> [LIMIT n] QUERY <expression> [LIMIT n] VSEARCH <text> [MATCH p] [LIMIT n] VSIM <k1> <k2> VGET <k>
Under the Hood

Lean Stack, Two Dependencies

Personal-scale data needs a linear scan and a good cache — not a distributed cluster behind a network.

Go 1.25
Single import, no service
Standard Library
Storage · AOF · HTTP
OpenAI
embedding-3-small · 256
go-pkg
keychain · env utils
godotenv
.env loader
AOF
Append log + compaction
MD5 Snapshot
JSON file per key
Vector
Self-implemented cosine
Get Started

From Import to Search in Four Steps

Add the module, launch the REPL, store a key, and search by meaning.

1

Install

Add ToriiDB to your Go module. macOS, Linux, Windows.

go get github.com/agenvoy/toriidb
2

Launch the REPL

Boots a Store with 16 databases under ./temp.

make test
3

Store a Key

Auto-detected as JSON; query nested fields by dot-notation.

SET user:1 {"name":"Pardn"}
4

Search by Meaning

Set OPENAI_API_KEY, attach a vector, then VSEARCH.

VSEARCH retry strategy LIMIT 3

Replace Three Databases with One Import

KV, documents, and vectors — embedded, persisted, and built for Agenvoy.