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.
Installation
pip install ragora
Or with uv:
uv add ragora
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
httpxfor 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="gpt-4o-mini", # 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ragora_sdk-0.1.0.tar.gz.
File metadata
- Download URL: ragora_sdk-0.1.0.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcc6f6e804d2aa245e67e1710f74b2e5cf16b1fb0c621a2a87a950033ed9eaa2
|
|
| MD5 |
671b8dab08f57aab3821692b16b0e01c
|
|
| BLAKE2b-256 |
2342625a516725e17aeaa6ee64a2620ed6261da0888009d95a4f6dfcf43cf772
|
File details
Details for the file ragora_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ragora_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096af5cbf578e52db96cb786c8e4165b1bad01cf08f4a84de10e43649906b704
|
|
| MD5 |
d98744690938c00386962f36fb9a18d5
|
|
| BLAKE2b-256 |
8502bc17f709fe710a03eeff4893eb6c286d2d955053d2f6e53f776d2ef0f654
|