pyplasmod
中文
pyplasmod is a Python HTTP client library for Plasmod: it talks to a deployed Plasmod gateway over standard HTTP (and some binary RPC) for vector ingest, search, Memory listing, dataset operations, and health checks.
Plasmod targets multi-agent workloads by combining cognitive object storage, event-driven materialization, and structured evidence retrieval in a runnable system.
Request paths, fields, and semantics follow the official Plasmod HTTP API documentation; this README only describes what this repository wraps and typical usage.
In-package topic index: from pyplasmod import plasmod_help; plasmod_help(). CLI: python -m pyplasmod [topic].
SDK architecture and implementation details: docs/SDK.md; gateway embedding (CPU/GPU): docs/EMBEDDING.md.
Quick start (~5 minutes)
Install and use PlasmodClient (same idea as pymilvus.MilvusClient):
pip install -U pyplasmod
from pyplasmod import PlasmodClient
# Local profile file (JSON) — stores default gateway URI + collection metadata
client = PlasmodClient("plasmod_demo.db")
# Or connect to a running server (Docker: adamwerw/plasmod:v1.0 on port 19530)
# client = PlasmodClient(uri="http://127.0.0.1:19530")
client.create_collection(collection_name="demo_collection", dimension=768)
client.insert("demo_collection", data=[{"id": "1", "vector": [0.0] * 768}])
res = client.search(collection_name="demo_collection", data="hello", limit=10)
The default Docker image runs on linux/arm64 (including Apple Silicon). To use an image built for another architecture, set PLASMOD_DOCKER_IMAGE. You can start the default image manually with the following command.
docker run -d --name plasmod -p 9091:9091 -p 19530:19530 -p 19531:19531 adamwerw/plasmod:v1.0
Full HTTP/RPC surface: client.http (PlasmodHttpClient). Day-to-day helpers: EasyPlasmod.
The steps below assume Plasmod is running. For docker compose up -d (split), the SDK default is http://127.0.0.1:19530 and health is on port 9091; unified / go run uses 8080. See Start the Plasmod gateway.
| Step |
What to do |
Command / code |
| 0 |
Confirm the gateway is up |
split: curl -sS http://127.0.0.1:9091/healthz; unified: curl -sS http://127.0.0.1:8080/healthz |
| 1 |
Install this client |
pip install -U pyplasmod |
| 2 |
Configure gateway URL (optional) |
split: export PLASMOD_BASE_URL=http://127.0.0.1:19530; unified: http://127.0.0.1:8080 (see .env.example) |
| 3 |
Health check |
See Python snippet below |
| 4 |
(Optional) Upload data |
Text/docs §2.1; .fbin §2.3; JSON matrix + ANN index §2.4; skip if no data yet |
| 5 |
Search |
p.search("your question", "w_demo", top_k=10) |
| 6 |
API details |
plasmod_help("easy") or read docs/SDK.md |
Steps 3 + 5 minimal example (verifies connectivity without your own data; search returns hits only when data exists):
from pyplasmod import EasyPlasmod
with EasyPlasmod() as p:
print("health:", p.health()) # gateway JSON
print("search:", p.search("hello", "w_demo")) # empty store may yield no objects/hits
Example script in the repository (clone the repo or copy the script; it is not installed via pip):
export PLASMOD_BASE_URL=http://127.0.0.1:19530
python examples/http_quickstart.py
Start the Plasmod gateway
pyplasmod only calls a running Plasmod HTTP service; it does not ship the server binary. Default entry points:
| Deployment |
Health |
PLASMOD_BASE_URL (SDK) |
docker compose up -d (split) |
http://127.0.0.1:9091/healthz |
http://127.0.0.1:19530 (client default) |
docker compose -f docker-compose.unified.yml or make dev / go run |
http://127.0.0.1:8080/healthz |
http://127.0.0.1:8080 |
Option A: Local dev from Plasmod source (recommended for debugging)
In the Plasmod repo root:
# Requires Go, Python 3, etc.; see Plasmod README
make dev
Verify after startup:
curl -sS http://127.0.0.1:8080/healthz
curl -sS http://127.0.0.1:8080/v1/system/mode
More (HNSW build, make build, seed data, scripts/run_demo.py) is in the Plasmod README Quick start / Run section.
Option B: Docker Compose full stack (split, default)
In the Plasmod repo:
docker compose up -d
export PLASMOD_BASE_URL=http://127.0.0.1:19530
curl -sS http://127.0.0.1:9091/healthz
Single-port unified:
docker compose -f docker-compose.unified.yml up -d
export PLASMOD_BASE_URL=http://127.0.0.1:8080
Switch prod/test with APP_MODE=prod / APP_MODE=test, etc.; see Plasmod docs.
Option C: Client-only validation
If you do not have Plasmod yet, pip install pyplasmod and run python -c "from pyplasmod import plasmod_help; plasmod_help()" for help; any HTTP call (health, search, upload, …) needs a reachable gateway.
Checklist aligned with the client
| Check |
Notes |
| URL match |
PLASMOD_BASE_URL (or base_url= in code) matches the gateway |
| Port reachable |
curl $PLASMOD_BASE_URL/healthz returns 2xx |
| Admin APIs |
Set PLASMOD_ADMIN_API_KEY for /v1/admin/*; dev may skip validation if unset (enable in production) |
| Vector dimension |
.fbin or ingest_vectors dimension must match gateway embedder config |
Choose a client entry and built-in help
Which class?
| Entry |
When to use |
EasyPlasmod |
Day-to-day: health, search/query, .fbin upload, ingest_document, memories |
PlasmodEmbedding |
Gateway-side embedding (CPU/GPU presets, ingest/search, runtime probe); also via p.embedding |
PlasmodClient |
MilvusClient-style API: create_collection, insert, search; profile file or uri=; .http for full gateway |
PlasmodHttpClient |
Full HTTP/RPC: admin ops, ingest_vectors, binary rpc_*, internal task/MAS, WAL SSE, etc. |
pyplasmod.data.upload / build_query_body |
Helpers decoupled from HTTP; pass client= to reuse connections |
PlasmodVectorStore |
LangChain (pip install pyplasmod[langchain]); embedding runs on the client |
Relationship: EasyPlasmod holds a PlasmodHttpClient; use p.http for the full API. Most examples use with EasyPlasmod() as p: to close connections.
from pyplasmod import EasyPlasmod, PlasmodClient
# Convenience entry
with EasyPlasmod() as p:
p.health()
p.http.dataset_delete({...}) # admin via .http
# Or the full client directly
with PlasmodClient(base_url="http://127.0.0.1:8080", admin_key="...") as c:
c.ingest_vectors([[0.1, 0.2, ...]])
Core concepts (primer)
| Concept |
Meaning |
workspace_id |
Workspace/tenant boundary; ingest and query usually require it (e.g. w_demo) |
dataset_name |
Logical dataset for bulk imports; matches upload(..., dataset=...) |
session_id / agent_id |
Session and agent IDs; query values must match ingest or recent writes may not appear |
| Memory |
Materialized memory objects on the gateway; list with p.memories(workspace_id) |
.fbin |
Bulk vector file format supported by the SDK (see §2) |
| Gateway embedding |
No /v1/embed; text vectors are produced at ingest/query on the server (ONNX/GGUF/TF-IDF, etc.); CPU/GPU via PLASMOD_EMBEDDER_DEVICE |
upload defaults session_id to ingest_{dataset}_{filename}; build_query_body aligns that session when you pass the same dataset_name and ingest_fbin_path.
plasmod_help() topics
from pyplasmod import plasmod_help, plasmod_topics
plasmod_help() # print topic index
print(plasmod_topics()) # [..., 'embedding', 'env', ...]
plasmod_help("embedding") # PlasmodEmbedding / CPU·GPU
plasmod_help("easy") # EasyPlasmod + full built-in help()
plasmod_help("env") # environment variables only
CLI equivalents: python -m pyplasmod, python -m pyplasmod upload, python -m pyplasmod client.
Single topics embed full signatures such as help(EasyPlasmod); for client, prefer help(PlasmodHttpClient) in a REPL.
Prerequisites
- Plasmod gateway deployed and running (see Start the Plasmod gateway).
- Python 3.8+.
- For
.fbin vector files: format per SDK (see §2.3); dimensions must match gateway configuration.
Install
pip install pyplasmod
Optional (LangChain PlasmodVectorStore, etc.):
pip install pyplasmod[langchain]
Editable install and tests from this repo:
pip install -e ".[dev]"
make unittest
Environment variables and client configuration
Read at construct time by PlasmodHttpClient / EasyPlasmod (constructor args override env).
| Variable |
Purpose |
PLASMOD_BASE_URL or ANDB_BASE_URL |
Gateway root URL; default http://127.0.0.1:19530 (split compose). Use http://127.0.0.1:8080 for unified. |
PLASMOD_HTTP_TIMEOUT or ANDB_HTTP_TIMEOUT |
HTTP timeout (seconds); default 30. |
PLASMOD_ADMIN_API_KEY or ANDB_ADMIN_API_KEY |
X-Admin-Key header for /v1/admin/*. |
Gateway embedding (Plasmod process, not the pyplasmod client) — set via PlasmodEmbedding.use_cpu / use_gpu or EmbedderConfig:
| Variable |
Purpose |
PLASMOD_EMBEDDER |
tfidf | onnx | gguf | tensorrt | openai | … |
PLASMOD_EMBEDDER_DEVICE |
cpu | cuda | metal (local ONNX/GGUF dual path) |
PLASMOD_EMBEDDER_DIM |
Vector dimension |
PLASMOD_EMBEDDER_MODEL_PATH |
Local model path |
See docs/EMBEDDING.md and .env.example.
Equivalent to PLASMOD_ADMIN_API_KEY: EasyPlasmod(..., admin_key="...") or PlasmodHttpClient(..., admin_key="..."). Whether Admin Key is enforced depends on gateway deployment.
export PLASMOD_BASE_URL=http://127.0.0.1:19530
# export PLASMOD_ADMIN_API_KEY=... # only when calling admin APIs
Common API vs HTTP path
p means an EasyPlasmod instance. upload and build_query_body live in pyplasmod.data (import separately; see §§2–3).
| Method |
HTTP |
Notes |
p.health() |
GET /healthz |
Liveness |
p.system_mode() |
GET /v1/system/mode |
System mode, etc. |