Prerequisites
pip install moorcheh-client
moorcheh up
from moorcheh import MoorchehClient
with MoorchehClient("http://localhost:8080") as client:
health = client.health()
assert health["status"] == "ok"
Full example — text namespace
import time
from moorcheh import MoorchehClient, MoorchehApiError
with MoorchehClient("http://localhost:8080") as client:
# 1. Check quota
health = client.health()
print(f"Items: {health['items']} / {health['max_items']}")
# 2. Create a text namespace
try:
client.namespaces.create("docs", type="text")
except MoorchehApiError as e:
if e.status_code != 409: # 409 = namespace already exists
raise
# 3. Upload documents (async job)
resp = client.documents.upload("docs", documents=[
{"id": "doc-1", "text": "Hello Moorcheh", "team": "ai"},
])
# 4. Poll until upload completes
job_id = resp["job_id"]
while True:
job = client.documents.upload_job_status("docs", job_id)
if job["status"] == "completed":
if job["failed"]:
print("Upload errors:", job.get("last_error"))
break
time.sleep(0.5)
# 5. Search (use #team:ai in query for metadata filter)
hits = client.similarity_search.query(
namespaces=["docs"],
query="hello moorcheh #team:ai",
top_k=5,
)
for r in hits["results"]:
print(r["id"], r["score"], r["label"], r.get("text"))
Vector namespace (optional)
with MoorchehClient("http://localhost:8080") as client:
client.namespaces.create("embeddings", type="vector", vector_dimension=768)
resp = client.vectors.upload("embeddings", vectors=[
{"id": "vec-1", "vector": [0.1] * 768, "source": "demo"},
])
# Poll upload job, then search with a vector query
hits = client.similarity_search.query(
namespaces=["embeddings"],
query=[0.1] * 768,
top_k=5,
)
CLI equivalent
moorcheh status
moorcheh namespace-create --name docs --type text
moorcheh upload-documents --namespace-name docs --documents-file docs.json
moorcheh upload-job-status --namespace-name docs --job-id <job_id>
moorcheh search --query "hello moorcheh" --namespaces docs --top-k 5
Method reference
| Step | Python (resource style) | Docs |
|---|---|---|
| Health / quota | client.health() | health |
| Create namespace | client.namespaces.create(...) | create |
| Upload documents | client.documents.upload(...) | upload |
| Poll upload | client.documents.upload_job_status(...) | upload job status |
| Upload file | client.files.upload(...) | upload files |
| Poll file job | client.files.job_status(...) | file job status |
| Search | client.similarity_search.query(...) | search |
Tips
- Text upload and text search require a configured embedding provider (
moorcheh configure) - Global item cap is 100,000 across all namespaces — check
health()or handle 409 on upload - Document upload, file upload, and namespace delete are async — poll the job until
statusis"completed" - Item ids are unique per namespace, not globally
Next steps
- Python client overview — all resources and error handling
- Quickstart — CLI walkthrough
- API reference — full HTTP API docs