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.
  • IVF-Flat Approximate Nearest Neighbor (ANN): Sublinear clustering index powered by k-means++ centroid initialization. Dramatically prunes search space for large-scale datasets while preserving high recall (collection.build_index(), use_ann=True).
  • Thread-Safe Readers-Writer Concurrency: Built-in ReadWriteLock with writer priority guarantees zero race conditions during parallel batch insertions, deletes, and query executions.
  • 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

Install via PyPI:

pip install sutradb-core

Or clone for local development & benchmarking:

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}")

# Optional: Build IVF-Flat ANN index for sublinear search on large datasets
collection.build_index(n_lists=4, n_probe=2)
ann_results = collection.query(
    vector=[1.0, 0.0, 0.0, 0.0],
    top_k=5,
    use_ann=True
)

🌐 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.

Metadata

Release files for sutradb-core 2.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sutradb-core 2.2.1
File Size Uploaded Provenance Actions
sutradb_core-2.2.1.tar.gz 42.9 kB Without provenance Details for sutradb_core-2.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sutradb-core 2.2.1
File Interpreter ABI Platform Actions
sutradb_core-2.2.1-py3-none-any.whl Python 3 none any Details for sutradb_core-2.2.1-py3-none-any.whl

Total release size: 75.4 kB

Release files / sutradb_core-2.2.1.tar.gz

Download URL sutradb_core-2.2.1.tar.gz
Size 42.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aec67409d9b9f5ba2d1ee1a2037e8c8eccb2a6153d3eab12b125186f4922b54a
BLAKE2b-256 checksum
How to use checksums
2a5580d428105a7b0b0de78023aefd61baa54d2e638fed6218fee4f8f0303fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / sutradb_core-2.2.1-py3-none-any.whl

Download URL sutradb_core-2.2.1-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67761e8ec99c80b08306840ece8688bc646e0629cf15d2ccb88c4d1754e2eac0
BLAKE2b-256 checksum
How to use checksums
d0ead89bde959881f252074e1372abb9567c79d18a14c36b6b90d213065f12c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for sutradb-core 2.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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