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"])
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 passstart_idbacked by a sequence generator, database allocator, or customid_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.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmv-1.4.0.tar.gz | 13.9 kB | Without provenance | Details for swarmv-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmv-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for swarmv-1.4.0-py3-none-any.whl |
Total release size: 32.0 kB
Release files / swarmv-1.4.0.tar.gz
| Download URL | swarmv-1.4.0.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0abe37f163ec0533b5cf9ebc5758602bf70b7b7da0df77d4d5c4300987edfa7
|
|
BLAKE2b-256 checksum How to use checksums |
0ac18fc2fd84f29c2e587c87e856a2824d5b055000283c50ffa1c20506dee32c
|
| 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.4.0-py3-none-any.whl
| Download URL | swarmv-1.4.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbbbeebea47ab5a495a239f2e259e44cf04ff0b39e1bbeefc4a4988d82ddffcf
|
|
BLAKE2b-256 checksum How to use checksums |
70fcb445828cbfd2c0b23f4b8f1097c80f3d1b9c9512b6f22b10c98c4f87ef6c
|
| 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.4.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.