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.7.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.7.0
File Size Uploaded Provenance Actions
swarmv-1.7.0.tar.gz 15.7 kB Without provenance Details for swarmv-1.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 35.5 kB

Release files / swarmv-1.7.0.tar.gz

Download URL swarmv-1.7.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c30611cbf330854c9ae35731a14ee14609ce2125cd69e09b2c15e9ccc63e2340
BLAKE2b-256 checksum
How to use checksums
3b2e48d21f910761dea41f89d820ae8371eb57cdf8874ffdb22fa7aa1daa55b1
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.7.0-py3-none-any.whl

Download URL swarmv-1.7.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aae2aac02c41dcae5c42d07564e1bc03e99d8312a9474fab55dd538a65d19ede
BLAKE2b-256 checksum
How to use checksums
0ff45bf85c18cbfb7d219b5c1491e58b20c3edf2768bf15d712f2b53d31776e0
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.7.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