Skip to main content

Official Python SDK for SwarnDB, the vector database that thinks in graphs. Combines HNSW + IVF-PQ indexing with virtual graph traversal and 15+ vector math operations.

Project description

SwarnDB Python SDK

Official Python SDK for SwarnDB, a high-performance vector database that combines HNSW and IVF + product quantization indexing with a virtual graph layer and 15+ built-in vector math operations.

Installation

pip install swarndb

Requires Python 3.9 or higher.

Quick Start

from swarndb import SwarnDBClient

with SwarnDBClient(host="localhost", port=50051) as client:
    # Create a collection
    client.collections.create(
        "articles",
        dimension=384,
        distance_metric="cosine",
    )

    # Insert a vector
    vec_id = client.vectors.insert(
        "articles",
        vector=[0.1, 0.2, 0.3, ...],   # length 384
        metadata={"topic": "physics", "year": 2024},
    )

    # Search
    results = client.search.query("articles", vector=[0.1, 0.2, 0.3, ...], k=10)
    for r in results.results:
        print(r.id, r.score)

Bulk Insert From a File

For large loads, stage your vectors as a .npy (or flat .f32) file on a path the server can read, then point the server at the file. The server reads the file via memory mapping, so the working memory for the load is bounded by the index being built rather than by the input file size.

import numpy as np
from swarndb import SwarnDBClient

vectors = np.random.rand(1_000_000, 1536).astype(np.float32)
np.save("/data/ingest/embeddings.npy", vectors)

with SwarnDBClient(host="localhost", port=50051) as client:
    client.collections.create("docs", dimension=1536, distance_metric="cosine")

    result = client.vectors.bulk_insert_from_path(
        collection="docs",
        path="/data/ingest/embeddings.npy",
        dim=1536,
        expected_count=1_000_000,
        total_count_hint=1_000_000,
        index_mode="immediate",
    )

    print(result.inserted_count, len(result.assigned_ids))

For tight-memory hosts where the single-pass load would not fit, set chunk_size to a positive value (for example 100_000). The server then processes the load in chunks and releases scratch memory between chunks, trading wall-clock for a lower peak resident memory footprint.

Async Client

The async client mirrors the full API surface using asyncio, including bulk_insert_from_path.

import asyncio
from swarndb import AsyncSwarnDBClient

async def main():
    async with AsyncSwarnDBClient(host="localhost", port=50051) as client:
        await client.collections.create("articles", dimension=384)
        await client.vectors.insert(
            "articles",
            vector=[0.1, 0.2, 0.3, ...],
            metadata={"topic": "physics"},
        )
        results = await client.search.query("articles", vector=[0.1, 0.2, 0.3, ...], k=10)
        for r in results.results:
            print(r.id, r.score)

asyncio.run(main())

Features

  • Sync (SwarnDBClient) and async (AsyncSwarnDBClient) clients with identical method names and return types
  • Single insert, streaming bulk insert, and file-based bulk insert (bulk_insert_from_path)
  • HNSW tuning knobs (ef_construction, ef_search, M) settable per collection and per query
  • Vector similarity search with metadata filtering (Filter.eq, Filter.in_, Filter.between, boolean combinators with &, |, ~)
  • Batch search across multiple queries in one round trip
  • Virtual graph traversal with per-collection and per-vector similarity thresholds
  • 15+ vector math operations (centroid, cone search, SLERP, drift detection, k-means, PCA, MMR, analogies)
  • Bulk insert checkpoints and resume via resume_token for long-running loads
  • NumPy arrays accepted anywhere a list[float] is expected

Documentation

For the complete reference, see the SwarnDB documentation:

License

Elastic License 2.0 (ELv2).

Project details


Download files

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

Source Distribution

swarndb-1.1.0.tar.gz (115.1 kB view details)

Uploaded Source

Built Distribution

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

swarndb-1.1.0-py3-none-any.whl (132.8 kB view details)

Uploaded Python 3

File details

Details for the file swarndb-1.1.0.tar.gz.

File metadata

  • Download URL: swarndb-1.1.0.tar.gz
  • Upload date:
  • Size: 115.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarndb-1.1.0.tar.gz
Algorithm Hash digest
SHA256 dbe75f9fee6962c6f01482842e64fb9ee0f5707fe46a05778cac44689d969033
MD5 df32458b6cb2241cfc144776af742c44
BLAKE2b-256 2a47d276ef520b2c8f6e77ddf4bf1b25ecc5871a79a8e2d68efe316fbd9b8abb

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarndb-1.1.0.tar.gz:

Publisher: python-sdk.yml on SarthiAI/SwarnDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarndb-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: swarndb-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 132.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarndb-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 666a01696e86963d00b9c5b24e1571d0e4d7c5488a589203a3185ff576f1905b
MD5 4b83add8adadb1fc477e5a9c14b94cc3
BLAKE2b-256 b33b6c0b0bd90cdc1c8d5074466fd99a8b13c6a15ab87ecf6f2ef990bf8db80a

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarndb-1.1.0-py3-none-any.whl:

Publisher: python-sdk.yml on SarthiAI/SwarnDB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page