Skip to main content

Observability SDK for ML/LLM pipelines - debug candidate drop-off and track decision context

Project description

ZenRay

PyPI version Python 3.9+ License: MIT

Observability for ML/LLM pipelines. Debug candidate drop-off and track decision context with minimal code changes.


Installation

pip install zenray

Quick Start

import zenray

# Initialize with your API key
zenray.init(api_key="zenray_xxxxx")  # or set ZENRAY_API_KEY env var

@zenray.pipeline("my-rag-pipeline")
def answer(question: str):
    docs = retrieve(question)
    filtered = filter_docs(docs)
    return generate(question, filtered)

@zenray.step("RETRIEVE")
def retrieve(question: str):
    return vector_db.search(question, k=100)

@zenray.step("FILTER")
def filter_docs(docs):
    kept = []
    for doc in docs:
        if doc.score < 0.3:
            zenray.drop(doc, "low_relevance")  # Track why items are dropped
        else:
            kept.append(doc)
    return kept

@zenray.step("RANK")
def rank_docs(docs):
    for doc in docs:
        zenray.score(doc, doc.relevance)  # Track scores
    return sorted(docs, key=lambda d: d.relevance, reverse=True)[:10]

View traces at zenray.live or self-host.


Features

Feature Description
@zenray.pipeline Mark pipeline entry points
@zenray.step Track processing stages
zenray.drop() Record why candidates were filtered
zenray.score() Capture ranking scores
zenray.tag() Add custom metadata
zenray.artifact() Attach prompts, responses, etc.

All data is sent asynchronously with <1ms overhead.


API Reference

Initialization

zenray.init(
    api_key="zenray_xxxxx",     # Required (or ZENRAY_API_KEY env var)
    endpoint="http://localhost:8000",  # Server URL
    disabled=False,              # Disable tracing
    sample_rate=1.0,            # 0-1 sampling rate
)

Decorators

@zenray.pipeline("pipeline-name", version="v1.0")
def my_pipeline(input):
    ...

@zenray.step("RETRIEVE")  # or FILTER, RANK, LLM_CALL, etc.
def my_step(data):
    ...

Tracking Functions

# Record dropped candidates
zenray.drop(item, "reason")

# Record scores
zenray.score(item, 0.95)

# Custom metrics
zenray.metric("latency_ms", 150)

# Attach artifacts (prompts, responses)
zenray.artifact("prompt", "What is the capital of France?")
zenray.artifact("response", "Paris")

# Add tags to runs
zenray.tag("user_id", "u123")
zenray.tag("model", "gpt-4")

Error Handling

# Check for errors
if zenray.get_last_error():
    print(f"Error: {zenray.get_last_error()}")

# Get stats
stats = zenray.get_stats()
print(f"Success: {stats['success_count']}, Errors: {stats['error_count']}")

Configuration

Environment Variable Default Description
ZENRAY_API_KEY - API key (required)
ZENRAY_ENDPOINT http://localhost:8000 Server URL
ZENRAY_DISABLED false Disable tracing
ZENRAY_SAMPLE_RATE 1.0 Sampling rate (0-1)
ZENRAY_TOP_K 10 Max candidates per step

Step Kinds

Kind Use Case
RETRIEVE Database/vector search
FILTER Candidate filtering
RANK Scoring/reranking
LLM_CALL LLM inference
JUDGE LLM-as-judge evaluation
SELECT Final selection
TRANSFORM Data transformation
TOOL_CALL External tool calls

Async Support

@zenray.async_pipeline("async-pipeline")
async def my_async_pipeline(input):
    ...

@zenray.async_step("LLM_CALL")
async def call_llm(prompt):
    ...

Self-Hosting

# Clone the repo
git clone https://github.com/DeepakSilaych/ZenRay
cd ZenRay

# Start services
docker compose up -d

# Access dashboard at http://localhost:5174

Links


License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zenray-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zenray-0.1.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file zenray-0.1.0.tar.gz.

File metadata

  • Download URL: zenray-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for zenray-0.1.0.tar.gz
Algorithm Hash digest
SHA256 99058473f3c2a84a29430550297d514b57040c6b8e263f507a5a939a8a2665cf
MD5 b0b2b7348bb11919d9c51e0195392057
BLAKE2b-256 12df4c85f370bba659e574def81255605a29355021e0858a67cb14c10fa8efdc

See more details on using hashes here.

File details

Details for the file zenray-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zenray-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for zenray-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a50774627f5000c775ad92942347fc218ae03cce3286b7d101ba30d5e03c7ed4
MD5 639ee8f04d47f5e1c78bacd880946930
BLAKE2b-256 bc2d6ac7c7a4fa0d9e0e815db5d1b8500fc1d5f777d0cdda8c3139ebbf414d12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page