Skip to content

NexaDB - A lightweight NoSQL database with vector search, TOON format, and enterprise security built-in

Notifications You must be signed in to change notification settings

krishcdbry/nexadb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NexaDB - Database for AI Developers

A lightweight NoSQL database with multi-database support, vector search, TOON format, and enterprise security

License: MIT Python 3.8+ Node.js 14+ Version

Quick Start โ€ข NotesApp Demo โ€ข Features โ€ข Performance โ€ข Benchmarks โ€ข YCSB Benchmark โ€ข TOON Format โ€ข Admin Panel


๐Ÿš€ What is NexaDB?

NexaDB is a production-ready, high-performance NoSQL database built for AI developers with:

  • ๐Ÿ—„๏ธ Multi-database architecture (v3.0.0) - Isolated databases for multi-tenancy, staging/production separation
  • ๐ŸŽฏ Vector search for semantic similarity (RAG, recommendations)
  • ๐Ÿ“ฆ TOON format support (40-50% fewer LLM tokens)
  • โšก MessagePack binary protocol (10x faster than REST)
  • ๐ŸŽจ Enhanced admin panel with 25 API endpoints (v3.0.0)
  • ๐Ÿ—๏ธ Production-grade performance (25K+ ops/sec @ 1M scale via binary protocol, 124K+ via direct API)
  • ๐Ÿš€ High-performance storage (LSM-Tree with Bloom filters, dual MemTable, WAL batching)

Perfect for:

  • ๐Ÿค– AI/ML applications and RAG systems
  • ๐Ÿข Multi-tenant SaaS applications (NEW in v3.0.0)
  • ๐Ÿ” Semantic search and recommendations
  • ๐Ÿ“Š Real-time analytics and dashboards
  • ๐Ÿ”Œ Microservices and APIs
  • ๐ŸŽฏ Rapid prototyping and production MVPs
  • ๐Ÿ’ฐ Reducing LLM API costs by 40-50%
  • ๐Ÿ“ˆ Small-to-medium datasets (1K to 1M documents)

โžก๏ธ See NotesApp Example - Production-ready full-stack app showcasing all features


โœจ Features

๐Ÿ—„๏ธ Multi-Database Architecture (v3.0.0)

Isolate data across multiple databases in a single NexaDB instance:

  • Create and manage multiple independent databases
  • Complete data isolation between databases
  • Perfect for multi-tenant SaaS applications
  • Staging/production environment separation
  • Per-database collection management

Quick Example:

from nexaclient import NexaClient

client = NexaClient()
client.connect()

# Create separate databases for different tenants
client.create_database('tenant_acme')
client.create_database('tenant_globex')

# Each tenant has isolated data
client.insert('users', {'name': 'Alice'}, database='tenant_acme')
client.insert('users', {'name': 'Bob'}, database='tenant_globex')

# Queries are scoped to specific database
acme_users = client.query('users', database='tenant_acme')  # Returns only Alice
globex_users = client.query('users', database='tenant_globex')  # Returns only Bob

# List all databases
databases = client.list_databases()
print(f"Total databases: {len(databases)}")

# Get database statistics
stats = client.get_database_stats('tenant_acme')
print(f"Collections: {stats['num_collections']}, Documents: {stats['total_documents']}")

๐ŸŽฏ Built-in Vector Search

Semantic similarity search with cosine distance:

  • HNSW (Hierarchical Navigable Small World) algorithm
  • Perfect for RAG, recommendations, and semantic search
  • Store embeddings directly with your documents
  • No need for separate vector databases (Pinecone, Weaviate, etc.)

Quick Example:

from nexaclient import NexaClient

client = NexaClient()
client.connect()

# Create a vector collection
client.create_collection('movies', database='default', vector_dimensions=4)

# Store movies with semantic vectors [action, romance, sci-fi, drama]
client.insert('movies', {
    'title': 'The Matrix',
    'year': 1999,
    'vector': [0.9, 0.15, 0.97, 0.5]  # High action + sci-fi
}, database='default')

client.insert('movies', {
    'title': 'The Notebook',
    'year': 2004,
    'vector': [0.1, 0.98, 0.05, 0.85]  # Very high romance
}, database='default')

# Build HNSW index for fast search
client.build_hnsw_index('movies', database='default')

# Find sci-fi movies
results = client.vector_search(
    collection='movies',
    query_vector=[0.5, 0.2, 0.98, 0.5],  # Sci-fi query
    limit=3,
    database='default'
)

# Results show semantic similarity!
# 1. The Matrix - 97.88% similar
# 2. Blade Runner 2049 - 98.91% similar

๐Ÿš€ World's First Native TOON Support

What is TOON?

  • Token-Oriented Object Notation format optimized for LLMs
  • 40-50% fewer tokens than JSON
  • Reduces API costs for GPT-4, Claude, and other LLM services
  • Perfect for RAG (Retrieval-Augmented Generation) systems

TOON in NexaDB:

  • Native binary protocol support (MSG_QUERY_TOON, MSG_EXPORT_TOON, MSG_IMPORT_TOON)
  • Built-in TOON serialization and parsing
  • CLI tools for import/export
  • Admin panel with TOON export and visualization
  • Real-time token statistics

โšก High-Performance Binary Protocol

  • 3-10x faster than HTTP/REST
  • MessagePack-based encoding
  • Persistent TCP connections
  • Connection pooling with 1000+ concurrent connections
  • Automatic reconnection and retry logic

๐Ÿ“„ JSON Document Storage

  • Schema-free documents
  • MongoDB-style queries
  • Aggregation pipelines
  • Nested field support
  • Auto-generated IDs and timestamps

๐Ÿ’พ LSM-Tree Storage Engine

  • Write-Ahead Log (WAL) for durability
  • MemTable (in-memory sorted structure)
  • SSTables (Sorted String Tables on disk)
  • Automatic compaction
  • Crash recovery

๐ŸŽจ Modern Admin Panel

  • Beautiful dark/light theme
  • Real-time query editor with JSON/TOON toggle
  • One-click TOON export with token statistics
  • Collection management
  • Document CRUD operations
  • Performance monitoring

๐Ÿ“ฆ Official SDKs

  • Python client with TOON support
  • JavaScript/Node.js client with TOON support
  • TypeScript definitions included

๐ŸŽฏ Quick Start

Installation via Homebrew (macOS)

# Add the tap
brew tap krishcdbry/nexadb

# Install NexaDB
brew install nexadb

# Start all services (Binary + REST + Admin)
nexadb start

# That's it! Now you have:
# - Binary Protocol on port 6970 (10x faster!)
# - JSON REST API on port 6969 (REST fallback)
# - Admin Web UI on port 9999 (Web interface)
# - Nexa CLI (interactive terminal) - ready to use!

# Access admin panel
open http://localhost:9999

# Use interactive CLI
nexa -u root -p

What gets installed:

  • โœ… nexadb command - Start/stop server, manage services
  • โœ… nexa command - Interactive CLI terminal (Rust-based, zero dependencies)
  • โœ… Python server files and dependencies
  • โœ… Admin panel web interface

โš ๏ธ Troubleshooting: If Homebrew installation gets stuck at numpy/hnswlib or shows Xcode errors, use the Install Script instead (see below).

Installation via Install Script (macOS & Linux)

Recommended if Homebrew has issues. Uses pre-built pip wheels - no compilation needed!

# One-line install (macOS & Linux)
curl -fsSL https://raw.githubusercontent.com/krishcdbry/nexadb/main/install.sh | bash

# Reload your shell
source ~/.bashrc  # or ~/.zshrc

# Start all services
nexadb start

# Access admin panel
open http://localhost:9999

# Use interactive CLI
nexa -u root -p

# Uninstall (if needed)
curl -fsSL https://raw.githubusercontent.com/krishcdbry/nexadb/main/uninstall.sh | bash

What gets installed:

  • โœ… nexadb command - Start/stop server, manage services
  • โœ… nexa command - Interactive CLI terminal (Rust-based, auto-detects architecture)
  • โœ… Python server files and dependencies
  • โœ… Admin panel web interface

Supported Operating Systems:

  • macOS (Intel & Apple Silicon)
  • Ubuntu/Debian (18.04+)
  • Fedora/RHEL/CentOS (7+)
  • Arch Linux/Manjaro

Supported Architectures:

  • x86_64 (Intel/AMD 64-bit)
  • arm64/aarch64 (Apple Silicon, Raspberry Pi, AWS Graviton)

Installation via Docker (Windows, Mac, Linux)

# Pull and run (simplest)
docker run -d \
  -p 6970:6970 \
  -p 6969:6969 \
  -p 9999:9999 \
  -v nexadb-data:/data \
  --name nexadb \
  krishcdbry/nexadb:latest

# Or use docker-compose
curl -O https://raw.githubusercontent.com/krishcdbry/nexadb/main/docker-compose.yml
docker-compose up -d

# Access admin panel
open http://localhost:9999

# View logs
docker logs -f nexadb

# Stop
docker stop nexadb

# Remove
docker rm nexadb

# Use nexa CLI inside Docker
docker exec -it nexadb nexa -u root -p

What you get:

  • โœ… Works on Windows, Mac, Linux
  • โœ… Isolated environment
  • โœ… Persistent data volume
  • โœ… Auto-restart on reboot
  • โœ… Nexa CLI included (works inside container)
  • โœ… Easy updates: docker pull krishcdbry/nexadb:latest

Supported Docker Platforms:

  • Linux (x86_64, ARM64)
  • macOS (Intel, Apple Silicon)
  • Windows (WSL2)

Cloud Deployment (Railway, Render, Fly.io)

Deploy to Railway (1-Click):

# Clone and deploy
git clone https://github.com/krishcdbry/nexadb.git
cd nexadb
railway up

Deploy to Render:

  1. Fork the repository
  2. Connect to Render
  3. Select render.yaml for automatic configuration
  4. Deploy!

Deploy to Fly.io:

# Clone and deploy
git clone https://github.com/krishcdbry/nexadb.git
cd nexadb
fly launch
fly deploy

What you get:

  • โœ… Auto-scaling and load balancing
  • โœ… Persistent volumes for data
  • โœ… HTTPS endpoints
  • โœ… Global CDN distribution
  • โœ… Automatic backups

Manual Installation

# Clone the repository
git clone https://github.com/krishcdbry/nexadb.git
cd nexadb

# Install Python dependencies
pip3 install msgpack

# Start all services with one command
python3 nexadb_server.py

# This launches all three servers:
# - Binary Protocol (port 6970) - 10x faster performance
# - JSON REST API (port 6969) - REST fallback
# - Admin Web UI (port 9999) - Web interface

# Access admin panel
open http://localhost:9999

Interactive CLI (Nexa)

NEW: Rust-based CLI for blazing-fast performance!

Nexa is a zero-dependency, standalone CLI built in Rust. Think mysql for MySQL, but nexa for NexaDB.

# Start nexa interactive terminal (automatically installed with NexaDB)
nexa -u root -p
Password: ********

Connected to NexaDB v2.0.0 (Binary Protocol: localhost:6970)

nexa> collections
โœ“ Found 2 collection(s):
  [1] movies
  [2] users

nexa> use movies
โœ“ Switched to collection 'movies'

nexa(movies)> insert {"title": "The Matrix", "year": 1999, "vector": [0.9, 0.15, 0.97, 0.5]}
โœ“ Document created: doc_abc123

nexa(movies)> query {"year": {"$gte": 2000}}
โœ“ Found 5 document(s)

nexa(movies)> vector_search [0.5, 0.2, 0.98, 0.5] 3 4
โœ“ Found 3 similar document(s):
[1] 98.91% match - Blade Runner 2049

nexa(movies)> count
โœ“ Document count: 127

nexa(movies)> exit
Goodbye! ๐Ÿ‘‹

Nexa Features:

  • โœ… Zero dependencies - Single standalone binary
  • โœ… Blazing fast - Written in Rust, uses MessagePack binary protocol
  • โœ… Cross-platform - Works on macOS, Linux, Windows
  • โœ… Auto-installed - Comes with Homebrew, Docker, and Linux installer
  • โœ… Full-featured - All commands: insert, read, update, delete, query, vector search, count
  • โœ… History & completion - Readline support with command history

Also available: Python CLI (for scripting):

python3 nexadb_cli.py -u root -p

5-Minute Quick Start: Movie Semantic Search

Build a semantic search system in 5 minutes! This example shows how NexaDB's vector search finds similar movies by theme, not keywords.

from nexadb_client import NexaClient

# Connect to NexaDB
client = NexaClient()
client.connect()

# Add movies with semantic vectors: [action, romance, sci-fi, drama]
movies = [
    {
        'title': 'The Dark Knight',
        'year': 2008,
        'genre': 'Action/Thriller',
        'vector': [0.95, 0.1, 0.3, 0.7]  # High action, low romance
    },
    {
        'title': 'The Notebook',
        'year': 2004,
        'genre': 'Romance/Drama',
        'vector': [0.1, 0.98, 0.05, 0.85]  # Very high romance
    },
    {
        'title': 'The Matrix',
        'year': 1999,
        'genre': 'Sci-Fi/Action',
        'vector': [0.9, 0.15, 0.97, 0.5]  # High action + sci-fi
    },
    {
        'title': 'Blade Runner 2049',
        'year': 2017,
        'genre': 'Sci-Fi/Thriller',
        'vector': [0.65, 0.3, 0.92, 0.55]  # Moderate action, high sci-fi
    }
]

client.batch_write('movies', movies)

# Search for romantic movies
romance_results = client.vector_search(
    collection='movies',
    vector=[0.1, 0.95, 0.1, 0.8],  # Romance query
    limit=2,
    dimensions=4
)

print("๐Ÿ’• Romantic movies:")
for result in romance_results:
    movie = result['document']
    print(f"  {movie['title']} - {result['similarity']:.2%} match")
# Output:
#   The Notebook - 99.90% match
#   The Matrix - 35.12% match

# Search for sci-fi movies
scifi_results = client.vector_search(
    collection='movies',
    vector=[0.5, 0.2, 0.98, 0.5],  # Sci-fi query
    limit=2,
    dimensions=4
)

print("\n๐Ÿš€ Sci-Fi movies:")
for result in scifi_results:
    movie = result['document']
    print(f"  {movie['title']} - {result['similarity']:.2%} match")
# Output:
#   Blade Runner 2049 - 98.91% match
#   The Matrix - 97.88% match

# ๐ŸŽ‰ Semantic search in 5 minutes! No keyword matching - pure vector similarity!
client.disconnect()

Try the full demo:

python3 demo_vector_search.py

๐ŸŽฏ Production Examples

NotesApp - Full-Stack Note-Taking App

โžก๏ธ examples/NotesApp - Production-ready note-taking application with beautiful UI

NotesApp

Stack: FastAPI + React + TypeScript + Tailwind CSS + NexaDB Binary Protocol

Features:

  • โšก 10x faster performance with MessagePack binary protocol
  • ๐ŸŽฏ AI-powered semantic search - Find notes by meaning, not keywords
  • ๐ŸŽจ Modern three-column UI - Notion-inspired design with glass morphism
  • โŒจ๏ธ Keyboard shortcuts - โŒ˜K for search, โŒ˜N for new note, Escape to clear
  • ๐Ÿ“ฆ Complete CRUD operations - Create, read, update, delete, archive
  • ๐Ÿท๏ธ Tag management - Organize notes with tags and tag-based filtering
  • ๐Ÿ“Š Real-time statistics - Dashboard with note count and metrics
  • ๐Ÿ” Dual search modes - Text search and vector-based semantic search
  • ๐ŸŒˆ Smooth animations - Fade-in, slide-in effects throughout
  • ๐Ÿ“ฑ Responsive design - Works beautifully on all screen sizes

Try it now:

# Start NexaDB
nexadb start

# Start NotesApp API (Terminal 1)
cd examples/NotesApp
python3 main.py

# Start NotesApp UI (Terminal 2)
cd examples/NotesApp/ui
npm install
npm run dev

# Open http://localhost:5174

๐Ÿ“– Full NotesApp Documentation

Other Framework Examples

Explore NexaDB integrations with popular frameworks:

More examples coming soon: Next.js, Django, Spring Boot, and more!


๐Ÿ–ฅ๏ธ Admin Panel

Access the admin panel at http://localhost:9999

Features:

  • ๐Ÿ“Š Dashboard with real-time statistics
  • ๐Ÿ“š Collection browser with document viewer
  • ๐Ÿ” Query editor with JSON/TOON toggle
  • ๐Ÿ“ค One-click TOON export with token savings
  • ๐Ÿ“ˆ Performance monitoring
  • ๐ŸŽจ Beautiful dark/light themes
  • ๐Ÿ–ผ๏ธ Responsive design

TOON Export:

  1. Select a collection
  2. Click "Export TOON" button
  3. View token reduction statistics (36-50%)
  4. Copy TOON data or download as .toon file
  5. Use in your LLM applications to save costs!

๐ŸŽฏ TOON Format

What is TOON?

TOON (Token-Oriented Object Notation) is a compact data format optimized for Large Language Models:

JSON Format (2,213 bytes):

[
  {"_id": "abc123", "name": "Alice", "email": "alice@example.com", "age": 28, "city": "San Francisco"},
  {"_id": "def456", "name": "Bob", "email": "bob@example.com", "age": 34, "city": "New York"},
  ...
]

TOON Format (1,396 bytes - 36.9% reduction!):

collection: test_users
documents[11]{_id,name,email,age,city,role}:
  abc123,Alice,alice@example.com,28,San Francisco,engineer
  def456,Bob,bob@example.com,34,New York,manager
  ...
count: 11

Using TOON in NexaDB

Export to TOON (CLI):

python3 toon_cli.py export test_users output.toon

Import from TOON (CLI):

python3 toon_cli.py import input.toon new_collection

Query in TOON format (Python):

from nexaclient import NexaClient

client = NexaClient(host='localhost', port=6970)
client.connect()

# Query and get TOON format response
toon_data, stats = client.query_toon('test_users', {}, limit=100)

print(f"TOON Data:\n{toon_data}")
print(f"Token Reduction: {stats['reduction_percent']}%")
print(f"Savings (1M calls): ${stats['reduction_percent'] * 10:.2f}")

Export collection to TOON (Python):

toon_data, stats = client.export_toon('test_users')

# Save to file
with open('export.toon', 'w') as f:
    f.write(toon_data)

print(f"Exported with {stats['reduction_percent']}% token reduction!")

TOON Benefits

  • โœ… 40-50% fewer tokens for LLM APIs
  • โœ… Lower costs (GPT-4, Claude, etc.)
  • โœ… Faster processing (less data to parse)
  • โœ… More context fits in token limits
  • โœ… Perfect for RAG systems

๐Ÿ”Œ Python Client Usage

Installation

# Install the NexaDB Python client
pip install nexaclient

Basic Usage

from nexadb_client import NexaClient

# Connect to binary server (defaults: localhost:6970, root/nexadb123)
client = NexaClient()
client.connect()

# Or use context manager (auto-connect/disconnect)
with NexaClient() as db:
    # Create document
    result = db.create('users', {
        'name': 'Alice Johnson',
        'email': 'alice@example.com',
        'age': 28,
        'city': 'San Francisco'
    })
    doc_id = result['document_id']

    # Query documents
    results = db.query('users', {'age': {'$gt': 25}}, limit=10)
    for doc in results:
        print(f"{doc['name']} - {doc['age']}")

    # Update document
    db.update('users', doc_id, {'age': 29})

    # Delete document
    db.delete('users', doc_id)

    # Batch operations
    docs = [
        {'name': 'Bob', 'age': 30},
        {'name': 'Charlie', 'age': 35}
    ]
    db.batch_write('users', docs)

Vector Search

with NexaClient() as db:
    # Store documents with vectors
    db.create('products', {
        'name': 'Laptop',
        'vector': [0.1, 0.2, 0.3, 0.4]  # embedding from OpenAI/Cohere
    })

    # Search by vector similarity
    results = db.vector_search(
        collection='products',
        vector=[0.15, 0.22, 0.28, 0.38],  # query vector
        limit=10,
        dimensions=4
    )

    for result in results:
        print(f"{result['document']['name']} - {result['similarity']:.2%}")

Aggregation

# Group by city and count
pipeline = [
    {'$match': {'status': 'active'}},
    {'$group': {
        '_id': '$city',
        'count': {'$sum': 1},
        'avg_age': {'$avg': '$age'}
    }},
    {'$sort': {'count': -1}},
    {'$limit': 10}
]

results = client.aggregate('users', pipeline)
for result in results:
    print(f"{result['_id']}: {result['count']} users")

Change Streams (Real-Time Events)

Watch for database changes in real-time!

NexaDB provides powerful change streams for real-time notifications when data changes. Perfect for:

  • ๐Ÿ”” Real-time notifications
  • ๐Ÿ’พ Cache invalidation
  • ๐Ÿ“ Audit logging
  • ๐Ÿ”„ Data synchronization
  • ๐Ÿ“Š Real-time dashboards
  • โšก Event-driven architectures

Python Example:

from nexaclient import NexaClient

client = NexaClient(host='localhost', port=6970, username='root', password='nexadb123')
client.connect()

# Watch for changes on 'orders' collection
for change in client.watch('orders'):
    if change['operationType'] == 'insert':
        order = change['fullDocument']
        print(f"New order from {order['customer']}: ${order['total']}")
        # Send notification, update cache, trigger workflow, etc.

    elif change['operationType'] == 'update':
        doc_id = change['documentKey']['_id']
        updates = change['updateDescription']['updatedFields']
        print(f"Order {doc_id} updated: {updates}")

    elif change['operationType'] == 'delete':
        doc_id = change['documentKey']['_id']
        print(f"Order {doc_id} was deleted")

Real-World Use Cases:

# 1. Cache Invalidation
import redis

cache = redis.Redis()

for change in client.watch('products', operations=['update', 'delete']):
    product_id = change['documentKey']['_id']
    cache.delete(f"product:{product_id}")
    print(f"Invalidated cache for product: {product_id}")

# 2. Audit Logging
import logging

logger = logging.getLogger('audit')

for change in client.watch():  # Watch ALL collections
    logger.info(
        f"{change['operationType']} on {change['ns']['coll']} "
        f"(doc: {change['documentKey']['_id']})"
    )

# 3. Real-Time Notifications
import smtplib

for change in client.watch('orders', operations=['insert']):
    order = change['fullDocument']
    send_email(
        to=order['customer_email'],
        subject=f"Order {order['_id']} Confirmed",
        body=f"Thank you! Your order for ${order['total']} is confirmed."
    )

Change Event Format:

{
    'operationType': 'insert',  # insert, update, delete, dropCollection
    'ns': {
        'db': 'nexadb',
        'coll': 'orders'
    },
    'documentKey': {
        '_id': 'abc123def456'
    },
    'fullDocument': {  # Only for insert/update
        '_id': 'abc123def456',
        'customer': 'Alice',
        'total': 99.99,
        '_created_at': '2025-11-27T...',
        '_updated_at': '2025-11-27T...'
    },
    'updateDescription': {  # Only for update
        'updatedFields': {
            'status': 'shipped',
            'tracking': 'XYZ123'
        }
    },
    'timestamp': 1700000000.123
}

Key Features:

  • โœ… Works over network (no filesystem access needed)
  • โœ… Simple, intuitive API
  • โœ… Filter by collection and operation type
  • โœ… Can connect to remote NexaDB servers
  • โœ… Thread-safe implementation
  • โœ… Automatic cleanup on disconnect

๐Ÿ“š Complete Change Streams Guide


๐Ÿ”Œ JavaScript/Node.js Client Usage

Installation

npm install nexaclient

Basic Usage

const { NexaClient } = require('nexaclient');

async function main() {
    // Connect to binary server
    const client = new NexaClient({ host: 'localhost', port: 6970 });
    await client.connect();

    // Insert document
    const docId = await client.insert('users', {
        name: 'Alice Johnson',
        email: 'alice@example.com',
        age: 28,
        city: 'San Francisco'
    });

    // Query documents
    const results = await client.find('users', { age: { $gt: 25 } }, 10);
    results.forEach(doc => {
        console.log(`${doc.name} - ${doc.age}`);
    });

    // Update document
    await client.update('users', docId, { age: 29 });

    // Delete document
    await client.delete('users', docId);

    // Disconnect
    client.disconnect();
}

main();

TOON Support

// Query in TOON format
const { toonData, stats } = await client.queryToon('users', {}, 100);
console.log('Token Reduction:', stats.reduction_percent + '%');

// Export to TOON
const { toonData, stats } = await client.exportToon('users');
console.log('TOON Data:', toonData);
console.log('Savings (1M calls): $' + (stats.reduction_percent * 10).toFixed(2));

๐Ÿ“Š Binary Protocol

NexaDB uses a custom binary protocol built on MessagePack for maximum performance.

Message Types

0x01 - MSG_CONNECT       # Handshake
0x02 - MSG_INSERT        # Insert document
0x03 - MSG_FIND          # Query documents
0x04 - MSG_UPDATE        # Update document
0x05 - MSG_DELETE        # Delete document
0x06 - MSG_COUNT         # Count documents
0x07 - MSG_AGGREGATE     # Aggregation pipeline
0x08 - MSG_DROP          # Drop collection
0x09 - MSG_COLLECTIONS   # List collections
0x0A - MSG_STATS         # Server statistics

# TOON Protocol (World's First!)
0x0B - MSG_QUERY_TOON    # Query with TOON response
0x0C - MSG_EXPORT_TOON   # Export collection to TOON
0x0D - MSG_IMPORT_TOON   # Import TOON data

0x81 - MSG_SUCCESS       # Success response
0x82 - MSG_ERROR         # Error response

Message Format

[Header: 12 bytes]
- Magic number: 0x4E455841 (4 bytes) "NEXA"
- Version: 0x01 (1 byte)
- Message type: 0xXX (1 byte)
- Flags: 0x00 (2 bytes)
- Payload length: (4 bytes)

[Payload: N bytes]
- MessagePack encoded data

๐Ÿ” Query Language

Comparison Operators

{'age': {'$eq': 25}}      # Equal to
{'age': {'$ne': 25}}      # Not equal to
{'age': {'$gt': 25}}      # Greater than
{'age': {'$gte': 25}}     # Greater than or equal
{'age': {'$lt': 25}}      # Less than
{'age': {'$lte': 25}}     # Less than or equal

Array Operators

{'tags': {'$in': ['python', 'javascript']}}    # Contains any
{'tags': {'$nin': ['java', 'c++']}}            # Contains none

Text Operators

{'name': {'$regex': 'John'}}                   # Regex match

Logical Operators

{
    '$and': [
        {'age': {'$gt': 25}},
        {'city': 'San Francisco'}
    ]
}

{
    '$or': [
        {'status': 'active'},
        {'premium': True}
    ]
}

Nested Fields

{'profile.age': {'$gt': 25}}                   # Access nested field
{'address.city': 'San Francisco'}              # Nested object

๐Ÿ“ˆ Performance

Production-Scale Benchmarks (v2.1.0)

Tested with 1.13M total operations - 100% success rate!

Exceptional Throughput:

  • 1M Document Test: 25,543 ops/sec (Binary Protocol) - Production Scale! ๐Ÿš€
  • 100K Document Test: 29,505 ops/sec (Binary Protocol)
  • Direct API Writes: 124,475 ops/sec (no network overhead)
  • HTTP REST API: 979 ops/sec (JSON over HTTP)
  • Binary vs HTTP: 30x faster

Low Latency:

  • Write latency (binary): 0.039ms average @ 1M scale
  • Write latency (direct API): 0.008ms average
  • Query latency (1M docs): 4-5 seconds without indexes
  • Hot read latency: < 1ms (MemTable)

Key Features:

  • โœ… LSM-Tree Architecture: SortedDict MemTable with O(log n) inserts
  • โœ… Bloom Filters: 95% reduction in unnecessary disk reads
  • โœ… Dual MemTable: Non-blocking writes during flush (< 1ms swap)
  • โœ… WAL Batching: 500 operations batched for efficiency
  • โœ… LRU Cache: 10,000 entries with 70-95% hit rates
  • โœ… Vector Search: HNSW algorithm for semantic similarity
  • โœ… Secondary Indexes: B-Tree indexes for fast queries

TOON Format:

  • Token reduction: 40-50% vs JSON
  • Perfect for RAG systems and LLM cost optimization

๐Ÿ“Š Performance Guide โ€ข Detailed Benchmarks โ€ข All Features


๐Ÿ—๏ธ Architecture v3.0.0

Multi-Database Support with Single Source of Truth - All interfaces connect to one binary server:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         YOUR APPS                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Python/JS     โ”‚   HTTP/REST     โ”‚   Admin Web UI          โ”‚
โ”‚   NexaClient    โ”‚   curl/fetch    โ”‚   (localhost:9999)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                 โ”‚                 โ”‚
         โ”‚ Binary (6970)   โ”‚ REST (6969)     โ”‚ HTTP (9999)
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚    NexaDB Binary Server (6970)      โ”‚
         โ”‚    THE SINGLE SOURCE OF TRUTH       โ”‚
         โ”‚                                     โ”‚
         โ”‚  โ€ข MessagePack Protocol             โ”‚
         โ”‚  โ€ข Vector Search (HNSW)             โ”‚
         โ”‚  โ€ข TOON Format Support              โ”‚
         โ”‚  โ€ข Connection Pooling               โ”‚
         โ”‚  โ€ข ONE VeloxDB Instance             โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚      VeloxDB Storage Engine          โ”‚
         โ”‚                                      โ”‚
         โ”‚  โ€ข LSM-Tree (WAL + MemTable + SST)   โ”‚
         โ”‚  โ€ข Vector Index (HNSW Algorithm)     โ”‚
         โ”‚  โ€ข Automatic Compaction              โ”‚
         โ”‚  โ€ข Crash Recovery                    โ”‚
         โ”‚  โ€ข 66% Less Memory (vs v1.x)         โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
                 ./nexadb_data/

Key Benefits:

  • โœ… Immediate consistency - All clients see the same data instantly
  • โœ… 66% less memory - One VeloxDB instance instead of three
  • โœ… No race conditions - Single source of truth
  • โœ… Production-ready - Battle-tested architecture

๐Ÿ“ฆ Production Files

nexadb/
โ”œโ”€โ”€ nexadb_binary_server.py    # Binary protocol server (port 6970)
โ”œโ”€โ”€ admin_server.py             # HTTP server for admin panel (port 9999)
โ”œโ”€โ”€ nexadb_admin_modern.html    # Admin panel UI
โ”œโ”€โ”€ storage_engine.py           # LSM-Tree storage engine
โ”œโ”€โ”€ nexadb_cli.py               # Command-line interface
โ”œโ”€โ”€ toon_format.py              # TOON serialization/parsing
โ”œโ”€โ”€ toon_cli.py                 # TOON import/export CLI
โ”œโ”€โ”€ setup.py                    # Package setup
โ”œโ”€โ”€ logo-light.svg              # Admin panel logo (light)
โ”œโ”€โ”€ logo-dark.svg               # Admin panel logo (dark)
โ”œโ”€โ”€ README.md                   # This file
โ”œโ”€โ”€ BENCHMARK_RESULTS.md        # Performance benchmarks
โ””โ”€โ”€ nexaclient/                 # Client SDKs
    โ”œโ”€โ”€ python/                 # Python client
    โ””โ”€โ”€ src/                    # JavaScript client

๐Ÿ› ๏ธ Development

Run Tests

# Start all services (recommended)
python3 nexadb_server.py

# Or start individual services for testing:
# Binary server only:
python3 nexadb_binary_server.py --port 6970

# Admin UI only:
python3 admin_server.py --port 9999

# Test TOON export
python3 toon_cli.py export test_users output.toon

# Test TOON import
python3 toon_cli.py import output.toon test_collection

Configuration

All Services (recommended):

# Start all three servers with one command
python3 nexadb_server.py --data-dir ./nexadb_data

# Or use --rest-only to start just the REST API
python3 nexadb_server.py --rest-only

Individual Services:

# Binary Protocol Server
python3 nexadb_binary_server.py --host 0.0.0.0 --port 6970 --data-dir ./nexadb_data

# Admin UI Server
python3 admin_server.py --port 9999 --data-dir ./nexadb_data

๐Ÿ—บ๏ธ Roadmap

โœ… Completed

  • LSM-Tree storage engine
  • Binary protocol with MessagePack
  • Connection pooling (1000+ concurrent connections)
  • JSON document storage
  • MongoDB-style queries
  • Aggregation pipeline
  • Python SDK with context manager support
  • JavaScript/Node.js SDK
  • Native TOON format support ๐ŸŽ‰
  • Vector search with HNSW algorithm ๐ŸŽฏ
  • v2.0 unified architecture (single source of truth)
  • TOON CLI tools
  • Modern admin panel with TOON export
  • Query editor with JSON/TOON toggle
  • Homebrew distribution (macOS)
  • Linux install script (Ubuntu, Fedora, Arch)
  • Docker image (Windows, Mac, Linux) ๐Ÿณ
  • Interactive Python CLI (python3 nexadb_cli.py -u root -p) ๐Ÿ’ป
  • Rust CLI (nexa -u root -p) - Zero-dependency, cross-platform ๐Ÿฆ€
  • Cloud deployment (Railway, Render, Fly.io) โ˜๏ธ
  • Production-grade NexaClient with reconnection
  • ๐Ÿš€ v3.0.0 Multi-Database & Enterprise Features:
    • Multi-database architecture with complete data isolation
    • Database-level CRUD operations (create, drop, list, stats)
    • Enhanced Python client (nexaclient) with multi-database support
    • Admin panel with 25 working API endpoints
    • Session-based authentication
    • User management and database permissions
    • 98/98 tests passing (100% pass rate)
    • HNSW index building with configurable parameters
    • Multi-database vector search isolation
    • Comprehensive test suite and benchmarks

๐Ÿšง In Progress (v3.1.0 - Cloud Version)

  • HTTP REST API (16 endpoints for cloud deployments)
  • Enhanced authentication system
  • Rate limiting
  • Full-text search (inverted index)

๐Ÿ”ฎ Future (v3.2.0+)

  • Replication and clustering
  • Backup and restore functionality
  • GraphQL API
  • Time-series optimization
  • Kubernetes operator
  • Hosted NexaDB Cloud

๐Ÿ“„ License

MIT License - See LICENSE file


๐Ÿค Contributing

Contributions are welcome! Please feel free to submit pull requests.

Areas to contribute:

  • Performance optimizations
  • Additional query operators
  • Testing and benchmarks
  • Documentation improvements
  • Client SDKs for other languages

๐Ÿ“ž Support


๐Ÿš€ NexaDB

Built by Krish

โญ Star on GitHub โ€ข ๐Ÿ“– TOON Spec

About

NexaDB - A lightweight NoSQL database with vector search, TOON format, and enterprise security built-in

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •