Skip to main content

सूत्र DB (SutraDB)

PyPI Python NumPy Tests Latency License

सूत्र (Sūtra): An aphorism or thread of knowledge designed to hold vast wisdom in the most concise, unbreakable form.

SutraDB is an ultra-fast, zero-dependency hybrid vector search and BM25 lexical engine engineered in pure Python. It combines SIMD-accelerated linear algebra with Robertson-Spärck Jones BM25 ranking and in-flight compound metadata filtering.

Designed specifically for the 95% of AI applications (local RAG, agent memory, enterprise document search, catalog matching) that need sub-millisecond retrieval without the multi-gigabyte dependency trees of Chroma or the network latency of cloud-managed vector databases.


🏗️ Architecture

                              CLIENT REQUEST
             [ Text Query: "P99 latency bug" | Vector: [0.12, ...] ]
             [ Metadata Filter: {"status": "resolved", "priority": {"$lte": 2}} ]
                                     │
                                     ▼
                      ┌──────────────────────────────┐
                      │    SutraDB Execution Core    │
                      └──────────────┬───────────────┘
                                     │
         ┌───────────────────────────┼───────────────────────────┐
         ▼                           ▼                           ▼
┌──────────────────┐       ┌──────────────────┐       ┌──────────────────┐
│  Metadata Engine │       │ Dense Vector Core│       │ Sparse BM25 Core │
│ (AST Predicates) │       │ (SIMD BLAS / SQ8)│       │ (Lexical Tokens) │
└────────┬─────────┘       └────────┬─────────┘       └────────┬─────────┘
         │                          │                          │
         │ Dynamic Bitmask          │ Dense Scores             │ Lexical Scores
         │ (e.g., 0b101100)         │ [0.89, 0.42, ...]        │ [12.4, 0.0, ...]
         └─────────────┬────────────┴─────────────┬────────────┘
                       │                          │
                       ▼                          ▼
               ┌───────────────┐          ┌───────────────┐
               │ Masked Dense  │          │ Masked BM25   │
               │ Top-K Heap    │          │ Top-K Heap    │
               └───────┬───────┘          └───────┬───────┘
                       │                          │
                       └───────────┬──────────────┘
                                   │
                                   ▼
                   ┌───────────────────────────────┐
                   │ Reciprocal Rank Fusion (RRF)  │
                   │ Merges semantic + exact words │
                   └───────────────┬───────────────┘
                                   │
                                   ▼
                   ┌───────────────────────────────┐
                   │    Ranked Final Results       │
                   │    P50: 0.36ms | P99: 5.9ms   │
                   └───────────────────────────────┘

⚡ Key Highlights

  • Pure SIMD / BLAS Velocity: Pre-normalizes vectors at insertion time so Cosine Similarity reduces to a single GEMV matrix-vector multiplication executed in L1 cache lines.
  • Reciprocal Rank Fusion (RRF): Dense embeddings understand semantic intent; BM25 matches exact serial numbers, error codes, and technical jargon. SutraDB dynamically fuses both ranking signals via RRF.
  • Single-Stage In-Flight Predicate Masking: Zero subset memory allocations. Evaluates complex JSON conditions ($eq, $ne, $gt, $gte, $in, $nin, $contains, $and, $or) into high-speed bitmasks in under $30\mu\text{s}$.
  • Zero-Copy Memory-Mapped Persistence: Custom .sutra 64-byte aligned binary format allows near-instant cold starts via mmap, backed by an append-only CRC32 Write-Ahead Log (WAL) for durability.
  • Embedded HTTP REST Micro-server: Built-in zero-dependency server exposes /health, /collections, /insert, and /query endpoints for microservice architectures.

📊 Benchmark Comparison

Ran on standard 4-vCPU Linux environment (5,000 documents, 128 dimensions):

Metric SutraDB (सूत्र DB) ChromaDB Pinecone (Cloud)
Dependency Footprint 1 library (NumPy) ~45 libraries Proprietary client
Cold Start Time < 2 ms ~850 ms N/A (Cloud API)
Vector Search Latency (P50) 0.36 ms ~4.2 ms 35 – 65 ms (Network roundtrip)
Ingestion Throughput 52,000+ docs/sec ~4,800 docs/sec Rate-limited by HTTP
RAM Overhead ~22 MB ~140 MB 0 MB (Remote)
Setup Overhead pip install sutradb-core Docker / heavy pip API keys + Monthly bill

🚀 Quickstart

1. Installation

git clone https://github.com/Sam-CodesAI/SutraDB.git
cd SutraDB
pip install -e .

2. Basic Usage (Python SDK)

from sutradb import SutraDB, Document

# Initialize SutraDB with disk persistence
db = SutraDB(persist_directory="./sutra_data")

# Create or load collection
collection = db.get_or_create_collection(name="kb", dimension=4, metric="cosine")

# Insert documents
collection.insert([
    Document(
        id="doc_1",
        vector=[0.95, 0.05, 0.10, 0.00],
        text="Deploying containerized microservices to Kubernetes",
        metadata={"category": "devops", "tier": "internal"}
    ),
    Document(
        id="doc_2",
        vector=[0.02, 0.98, 0.05, 0.01],
        text="PostgreSQL connection pooling and pgbouncer tuning",
        metadata={"category": "database", "tier": "public"}
    )
])

# Hybrid query combining semantic vector + text keywords + metadata filter
results = collection.query(
    vector=[1.0, 0.0, 0.0, 0.0],
    text="Kubernetes microservices",
    filter={"tier": "internal"},
    top_k=5,
    hybrid=True
)

for r in results:
    print(f"[{r.score:.4f}] {r.id}: {r.text}")

🌐 Running as an HTTP Microservice

Start the built-in HTTP server:

python3 -m sutradb.server 8765

Query via curl:

# Health check
curl http://localhost:8765/health

# Insert documents
curl -X POST http://localhost:8765/collections/demo/insert \
  -H "Content-Type: application/json" \
  -d '{"documents": [{"id": "d1", "vector": [1,0,0], "text": "Sample", "metadata": {"tag": "ai"}}]}'

# Hybrid search
curl -X POST http://localhost:8765/collections/demo/query \
  -H "Content-Type: application/json" \
  -d '{"vector": [1,0,0], "text": "Sample", "filter": {"tag": "ai"}, "top_k": 5}'

🧪 Test Suite

Run the full verification and benchmark suite:

pytest -v tests

📜 License

MIT License. Engineered by Samarth.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sutradb_core-2.0.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sutradb_core-2.0.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file sutradb_core-2.0.1.tar.gz.

File metadata

  • Download URL: sutradb_core-2.0.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sutradb_core-2.0.1.tar.gz
Algorithm Hash digest
SHA256 47b2bf68e319f23b7ae0befa9eed7d649adc5ddf4d9b16f9b48d4223acaa1898
MD5 4e1fd88aedd49128ef40f5a52f118b1a
BLAKE2b-256 689415eb7af3151a9b0b9d1d441f4911d81b9fed00991cdfeae0258a0253ba4b

See more details on using hashes here.

File details

Details for the file sutradb_core-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: sutradb_core-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sutradb_core-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66501793044cb03347865b000f4d9ee515bf544db3e88d7132162ac596019be2
MD5 43931b9da885c3c1db9d3e7e237ba36a
BLAKE2b-256 4cc92614df8dbdc14113b2a196924c22448964d3787c1c1f5677a41e0c5e715c

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.0

2 files

This release

2.0.1 This release

2 files

2.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page