Skip to main content

SwarmV Python SDK

Edge vector memory for AI agents, with built-in relationship-based access control (ReBAC).

pip install "swarmv[fast]"   # [fast] adds orjson + numpy for max throughput

Quick Start

from swarmv import (
    SwarmV,
    OpenAIEmbeddings,
    embed_document_chunks,
)

# 1. Initialize client and embedding provider
client = SwarmV(api_key="evx_...")
embedder = OpenAIEmbeddings(model="text-embedding-3-small", dimensions=768)

# 2. Chunk & embed documents with standard schemas and 32-bit uint IDs
records = embed_document_chunks(
    embedder=embedder,
    container_id="container:handbook",
    document_id="handbook.md",
    chunks=[
        "Employees are entitled to 25 days paid annual leave.",
        "Remote work stipends cover home office equipment.",
    ],
    source="https://wiki.corp/handbook.md",
    category="hr",
)

client.insert_many(records)

# 3. Query with semantic similarity & access control
query_vector = embedder.embed_query("vacation allowance")
hits = client.search(query_vector, top_k=5, fresh=True)

for hit in hits:
    print(hit.id, hit.distance, hit.metadata.get("text"))

# 4. Mint scoped user tokens
token = client.generate_user_token("user:alice", scopes=["vector:read"])

Records are also searchable by the words in their metadata text (accents and case ignored). Keyword search needs no embedding, which suits exact terms: error codes, names, ids. Hybrid search fuses vector and keyword matches. Access control is the same in every mode.

# Keyword only
by_words = client.search_text("ERR_4021", top_k=5)

# Vector + keywords; keyword_weight: 0 = vector only, 1 = keyword only (default 0.5)
hybrid = client.hybrid_search(query_vector, "refund policy ERR_4021", top_k=5, keyword_weight=0.5)
for hit in hybrid:
    print(hit.id, hit.score, hit.match, (hit.metadata or {}).get("text"))  # match: vector | keyword | both

Embedding Providers

SwarmV provides zero-dependency, lightweight adapters built on httpx:

OpenAI (OpenAIEmbeddings)

from swarmv import OpenAIEmbeddings

embedder = OpenAIEmbeddings(
    api_key="sk-...",
    model="text-embedding-3-small",
    dimensions=512,
)

Cloudflare Workers AI (WorkersAIEmbeddings)

from swarmv import WorkersAIEmbeddings

embedder = WorkersAIEmbeddings(
    account_id="...",
    api_token="...",
    model="@cf/baai/bge-base-en-v1.5",
)

Voyage AI (VoyageEmbeddings)

from swarmv import VoyageEmbeddings

embedder = VoyageEmbeddings(
    api_key="pa-...",
    model="voyage-code-3",
    output_dimension=512,
)

Document Chunking & 32-Bit ID Allocation

SwarmV requires document IDs to be numeric strings representing 32-bit unsigned integers (0 to 4,294,967,295).

from swarmv import create_document_chunks

# Option A: Sequential ID Allocation (Recommended for multi-document pipelines)
# Callers must allocate non-overlapping ranges across documents to prevent collisions.
chunks_1 = create_document_chunks(
    document_id="doc1.txt",
    container_id="container:docs",
    chunks=["chunk A", "chunk B"],
    vectors=[[0.1, 0.2], [0.3, 0.4]],
    start_id=0,  # IDs: "0", "1"
)

chunks_2 = create_document_chunks(
    document_id="doc2.txt",
    container_id="container:docs",
    chunks=["chunk C", "chunk D"],
    vectors=[[0.5, 0.6], [0.7, 0.8]],
    start_id=2,  # IDs: "2", "3" (advancing start_id by prior chunk count)
)

# Option B: Deterministic FNV-1a Hashing (Small datasets / local development)
hashed_chunks = create_document_chunks(
    document_id="manual.pdf",
    container_id="container:manuals",
    chunks=["chunk text..."],
    vectors=[[0.1, 0.2]],
)

Note on 32-Bit Uniqueness: Stateless hashing functions (hash_doc_chunk_id) suffer from the birthday paradox (~50% collision risk at 77,000 items). For large datasets, always pass start_id backed by a sequence generator, database allocator, or custom id_generator.

Semantic Caching

Cache expensive LLM calls by semantic proximity:

from swarmv import SemanticCache, OpenAIEmbeddings

embedder = OpenAIEmbeddings()
cache = SemanticCache(client, embedder, threshold=0.95)

answer = cache.call("Explain Raft consensus", call_llm)

Full documentation: https://swarmv.dev/docs

Metadata

Release files for swarmv 1.6.0

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

Source distribution (sdist)

Source distribution for swarmv 1.6.0
File Size Uploaded Provenance Actions
swarmv-1.6.0.tar.gz 15.6 kB Without provenance Details for swarmv-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarmv 1.6.0
File Interpreter ABI Platform Actions
swarmv-1.6.0-py3-none-any.whl Python 3 none any Details for swarmv-1.6.0-py3-none-any.whl

Total release size: 35.2 kB

Release files / swarmv-1.6.0.tar.gz

Download URL swarmv-1.6.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
955ce3c7fba3162297d12e5c65ad74b02fa9a470069423bc2eac74c9f7ed76fa
BLAKE2b-256 checksum
How to use checksums
68bc798c2048d6ae84c6a07aed8de44e638ebfa99b14ef9a36588ad65008800c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.7

Release files / swarmv-1.6.0-py3-none-any.whl

Download URL swarmv-1.6.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f439fc38055df60590c007248bcbd7629df52be45e71f6ad1d49dcef1dddb4a
BLAKE2b-256 checksum
How to use checksums
89d296e2cd473d8ed84b9d11f4763684a48e43755f807def3666f1a6785b7c6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.7

Security for swarmv 1.6.0

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