Skip to main content

Official Python SDK for the Ragora RAG API - Build AI-powered knowledge bases

Project description

Ragora Python SDK

Official Python SDK for the Ragora RAG API. Build AI-powered knowledge bases with semantic search and chat completions.

PyPI version Python 3.10+ License: MIT

Installation

pip install ragora-sdk

Or with uv:

uv add ragora-sdk

Release Smoke Check

Run a quick pre-release smoke check that:

  • builds the package (if build is installed),
  • validates dist metadata (if twine is installed),
  • executes a curated set of examples against a mocked client (no network/API key required).
python -m ragora.smoke

Or via CLI entrypoint:

ragora-smoke

Useful options:

# skip build/twine phase
python -m ragora.smoke --skip-prepare

# run a subset of examples
python -m ragora.smoke --examples search.py,credits.py,listings.py

Quick Start

import asyncio
from ragora import RagoraClient

async def main():
    client = RagoraClient(api_key="your-api-key")

    # Create a collection
    collection = await client.create_collection(
        name="My Knowledge Base",
        description="Documentation and guides"
    )
    print(f"Created collection: {collection.id}")

    # Upload a document
    upload = await client.upload_file(
        file_path="./document.pdf",
        collection_id=collection.id
    )
    print(f"Uploaded: {upload.filename} (ID: {upload.id})")

    # Wait for processing to complete
    status = await client.wait_for_document(upload.id)
    print(f"Processing complete: {status.vector_count} vectors created")

    # Search the collection
    results = await client.search(
        collection_id=collection.id,
        query="How do I get started?",
        top_k=5
    )
    for result in results.results:
        print(f"Score: {result.score:.3f} - {result.content[:100]}...")

    # Chat with your knowledge base
    response = await client.chat(
        collection_id=collection.id,
        messages=[{"role": "user", "content": "Summarize the main concepts"}]
    )
    print(response.choices[0].message.content)

if __name__ == "__main__":
    asyncio.run(main())

Features

  • Async-first - Built on httpx for high-performance async operations
  • Full type hints - Pydantic models with complete type coverage
  • Streaming support - Real-time chat completions with async iterators
  • Document management - Upload, track progress, and manage documents
  • Collection CRUD - Create, update, delete, and list collections
  • Cost tracking - Monitor API costs per request
  • Rate limit handling - Access rate limit info from response metadata

API Reference

Client Initialization

from ragora import RagoraClient

# Basic usage
client = RagoraClient(api_key="your-api-key")

# With custom settings
client = RagoraClient(
    api_key="your-api-key",
    base_url="https://api.ragora.app",  # default
    timeout=30.0  # seconds
)

# Using as async context manager
async with RagoraClient(api_key="your-api-key") as client:
    results = await client.search(...)

Collections

# Create a collection
collection = await client.create_collection(
    name="My Collection",
    description="Optional description",
    slug="my-collection"  # optional, auto-generated if not provided
)

# List collections
collections = await client.list_collections(limit=20, offset=0)
for coll in collections.data:
    print(f"{coll.name}: {coll.total_documents} documents")

# Get a collection by ID or slug
collection = await client.get_collection("collection-id-or-slug")

# Update a collection
collection = await client.update_collection(
    "collection-id",
    name="New Name",
    description="Updated description"
)

# Delete a collection
result = await client.delete_collection("collection-id")
print(result.message)

Documents

# Upload from bytes
upload = await client.upload_document(
    file_content=b"Hello world",
    filename="hello.txt",
    collection_id="collection-id"  # optional, uses default if not provided
)

# Upload from file path
upload = await client.upload_file(
    file_path="./document.pdf",
    collection_id="collection-id"
)

# Check document status
status = await client.get_document_status(upload.id)
print(f"Status: {status.status}")
print(f"Progress: {status.progress_percent}%")
print(f"Stage: {status.progress_stage}")

# Wait for processing to complete
status = await client.wait_for_document(
    upload.id,
    timeout=300.0,      # max wait time in seconds
    poll_interval=2.0   # time between status checks
)

# List documents in a collection
documents = await client.list_documents(
    collection_id="collection-id",
    limit=50,
    offset=0
)

# Delete a document
result = await client.delete_document("document-id")

Search

results = await client.search(
    collection_id="collection-id",
    query="What is machine learning?",
    top_k=5,              # number of results
    threshold=0.7,        # minimum relevance score (0-1)
    filter={"type": "doc"}  # optional metadata filter
)

for result in results.results:
    print(f"Score: {result.score:.3f}")
    print(f"Content: {result.content}")
    print(f"Document ID: {result.document_id}")
    print("---")

Chat Completions

# Non-streaming
response = await client.chat(
    collection_id="collection-id",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain RAG"}
    ],
    model="google/gemini-2.5-flash",    # optional
    temperature=0.7,         # optional
    max_tokens=1000,         # optional
    system_prompt="Custom system prompt"  # optional
)

print(response.choices[0].message.content)
print(f"Sources used: {len(response.sources)}")

# Streaming
async for chunk in client.chat_stream(
    collection_id="collection-id",
    messages=[{"role": "user", "content": "Explain RAG"}]
):
    print(chunk.content, end="", flush=True)

    # Sources are included in the final chunk
    if chunk.sources:
        print(f"\n\nSources: {len(chunk.sources)}")

Marketplace

# Browse marketplace products
products = await client.list_marketplace(limit=10, search="AI")
for product in products.data:
    print(f"{product.title} - {product.average_rating:.1f} stars")

# Get product details (by ID or slug)
product = await client.get_marketplace_product("product-slug")
print(f"{product.title}: {product.total_vectors} vectors")
if product.listings:
    for listing in product.listings:
        print(f"  {listing.get('type')}: ${listing.get('price_amount_usd', 0):.2f}")

Credits

balance = await client.get_balance()
print(f"Balance: ${balance.balance_usd:.2f} {balance.currency}")

Response Metadata

Every response includes metadata from API headers:

response = await client.search(...)

print(f"Request ID: {response.request_id}")
print(f"API Version: {response.api_version}")
print(f"Cost: ${response.cost_usd:.4f}")
print(f"Remaining balance: ${response.balance_remaining_usd:.2f}")
print(f"Rate limit: {response.rate_limit_remaining}/{response.rate_limit_limit}")
print(f"Rate limit resets in: {response.rate_limit_reset}s")

Error Handling

from ragora import RagoraClient, RagoraException

client = RagoraClient(api_key="your-api-key")

try:
    results = await client.search(...)
except RagoraException as e:
    print(f"Error: {e.message}")
    print(f"Status code: {e.status_code}")
    print(f"Request ID: {e.request_id}")

    if e.is_rate_limited:
        print("Rate limited - wait and retry")
    elif e.is_auth_error:
        print("Check your API key")
    elif e.is_retryable:
        print("Temporary error - safe to retry")

Examples

See the examples/ directory for complete, runnable examples:

Example Description
Search Search documents and access response metadata
Chat Chat completions with RAG context
Streaming Streaming chat responses
Collections CRUD Create, list, get, update, delete collections
Documents Upload, process, list, delete documents
Marketplace Browse marketplace products and listings
Credits Check balance and track costs

Set your API key before running:

export RAGORA_API_KEY="your-api-key"
python examples/search.py

License

MIT License - see LICENSE for details.

Links

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

ragora_sdk-0.1.2.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

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

ragora_sdk-0.1.2-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file ragora_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: ragora_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for ragora_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 33180bf906396ee786e576779437346b7625e9eea93859d3cb1ec40b33f66237
MD5 801e0e15645ba47a3888ee531e35ac97
BLAKE2b-256 2aafc977781c8dc1bfd2cd519b95437942cc1a0f1f974b136845933857292f79

See more details on using hashes here.

File details

Details for the file ragora_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ragora_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for ragora_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 01e5a08838500d7b2057a67f846ef3310c84b47ae34e612c48893fb1fd110195
MD5 0bbd3111d49c84f969c93749b00574c3
BLAKE2b-256 cb3d6d06fc1b054010c783f6ccb54eb7d67475a22c6ef27c38595438c642745f

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