Documentation

Getting Started

Install ToriiDB, create an embedded store, and run the interactive command client.

Requirements

Requirement Version or purpose
Go 1.25 or later
Local filesystem Stores AOF logs and per-key JSON cache files
OPENAI_API_KEY Optional; required only for vector operations

Install the Module

Add ToriiDB to an existing Go module:

go get github.com/pardnchiu/toriidb

Or clone the repository and build every package:

git clone https://github.com/pardnchiu/toriidb
cd toriidb
go build ./...

Create a Store

store.New accepts zero or one storage path. With no argument, ToriiDB uses ./temp relative to the process working directory.

package main

import (
    "fmt"
    "log"

    "github.com/pardnchiu/toriidb/core/store"
)

func main() {
    db, err := store.New("./data")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    fmt.Println(db.Exec("SET greeting hello"))
    fmt.Println(db.Exec("GET greeting"))
}

Always call Close before shutdown. It waits for background vector attachment work and compacts each loaded database's append-only log.

Run the REPL

The repository includes a small interactive client:

go run cmd/test/main.go

A minimal session looks like this:

toriidb[0]> SET counter 1
OK
toriidb[0]> INCR counter
2
toriidb[0]> GET counter
2

Type quit or exit to stop the client. SIGINT and SIGTERM also close the store before the process exits.

Work with JSON Documents

Dot notation addresses nested object fields and array indexes:

SET user {"name":"Torii","profile":{"level":1}}
GET user.name
SET user.profile.level 2
INCR user.profile.level
GET user.profile.level

A field-level SET creates missing object maps, but it does not replace scalar intermediate values. Array indexes must already be valid.

Use Expiration and Databases

SET session abc123 300
TTL session
SELECT 1
SET cache warm
KEYS *

ToriiDB provides 16 logical databases numbered 0 through 15. Each session tracks its own active database while sharing the underlying store.

Enable Vector Operations

Export an OpenAI API key before starting the process, then add VECTOR to a SET command:

export OPENAI_API_KEY="your-api-key"
export TORIIDB_EMBED_DIM="256"
go run cmd/test/main.go
SET article:1 Redis-style embedded storage VECTOR
SET article:2 JSON document database VECTOR
VSEARCH embedded vector search LIMIT 2
VSIM article:1 article:2
VGET article:1

Vector attachment runs in the background after SET succeeds. A newly written entry may therefore become searchable shortly after the command returns.

Build and Test

go build ./...
go test ./... -count=1
go vet ./...

The repository Makefile also provides:

Target Action
make test Run the interactive client
make unit Run core tests with coverage
make embed Run the OpenAI embedding integration test

Next Steps

中文