Skip to main content

Crate motedb

Crate motedb 

Source
Expand description

§MoteDB

AI-native embedded multimodal database for embodied intelligence (robots, AR glasses, industrial arms). A single embedded Rust library providing columnar storage with ACID transactions, vector search, full-text search, and spatial indexing.

§Status

Pre-1.0. The Database embedding API and the storage/transaction engine are stable and heavily tested. The SQL surface and the FFI bindings (ffi, tokenizers) are still evolving — see the crate README for the supported SQL subset. The internal modules (storage, index, txn, database) are exposed for advanced/embedded use but their exact types are not part of the stable API yet.

§Quick start

use motedb::{Database, QueryResult};

let db = Database::create("my_data")?;
db.execute("CREATE TABLE t (id INT PRIMARY KEY, v INT)")?;
db.execute("INSERT INTO t VALUES (1, 100)")?;
let r = db.execute("SELECT * FROM t")?;
if let QueryResult::Select { rows, .. } = r.materialize()? {
    println!("{:?}", rows);
}

§Architecture

  • Storage: append-only columnar segments (source of truth) + WAL for durability, with Snappy/Zstd compression and mmap zero-copy reads.
  • Indexes: DiskANN/Vamana (vector) + i-Octree (spatial) + inverted index (text) + B+Tree (column/timestamp).
  • Transactions: MVCC version store with snapshot isolation and write-ahead logging for crash recovery.

§Performance (indicative, Apple Silicon)

On a 300K-row × 4-column workload vs SQLite WAL: COUNT/SUM under WHERE ~5×, ORDER BY + LIMIT ~2.5×, PK point lookup sub-microsecond. See BENCHMARK.md and the docs for methodology and full numbers.

Re-exports§

pub use config::AutoCheckpointConfig;
pub use config::DBConfig;
pub use config::DurabilityLevel;
pub use config::LSMConfig;
pub use config::WALConfig;
pub use catalog::TableRegistry;
pub use database::MoteDB;
pub use database::QueryProfile;
pub use database::TransactionStats;
pub use sql::ForEachResult;
pub use sql::QueryResult;
pub use sql::StreamingControl;
pub use sql::StreamingQueryResult;

Modules§

cache
Cache module - LRU caches for performance optimization
catalog
config
Database configuration and durability levels
database
Database Module - Modularized Architecture
distance
Distance metrics for vector similarity computation
ffi
FFI (Foreign Function Interface) for C/Python/Node.js
index
Index layer implementation
sql
storage
Storage layer implementation
tokenizers
txn
Transaction layer implementation
types
Multi-modal data types for MoteDB

Macros§

debug_log
Debug-level log. Compiled in but a no-op unless a logger is installed and debug level is enabled for the motedb target.
error_log
Error-level log (operation failed; the calling path returns an error too).
info_log
Info-level log (e.g. lifecycle events: open/close/checkpoint).
warn_log
Warn-level log (degraded-but-functional conditions, retries, fallbacks).

Structs§

Database
MoteDB 数据库实例

Enums§

StorageError

Functions§

fsync_dir
Explicitly purge jemalloc’s dirty pages back to the OS. Fsync the parent directory of a file path. This ensures that a file rename or creation is durable across crashes on POSIX systems (Linux ext4/xfs, macOS APFS). Without this, a rename is not guaranteed to survive a crash even if the file itself was fsync’d.
purge_memory_to_os
Call after bulk operations (CREATE INDEX, compaction) that create large transient allocations, to keep RSS low on edge devices. No-op when jemalloc is not enabled.

Type Aliases§

MoteDBError
Result