RAGIE Python Client SDK
The `ragie` Python Client SDK, currently at version 1.15.1, provides an idiomatic interface to access the Ragie API for Retrieval-Augmented Generation (RAG) applications. It enables developers to integrate Ragie's RAG capabilities, including document ingestion, chunk retrieval, and interaction with LLMs. The library appears to have a regular release cadence with frequent updates and new features.
Warnings
- breaking The SDK is currently in beta. Breaking changes may occur between versions without a major version update. Users are strongly advised to pin their usage to a specific package version to prevent unexpected breaks.
- gotcha Improper resource management can lead to open HTTP connections and memory leaks in long-lived applications. The `Ragie` client manages underlying `httpx` clients.
- gotcha Documents ingested into Ragie are not immediately ready for retrieval. They go through a lifecycle (e.g., `pending`, `partitioning`, `indexed`, `ready`). Attempting to retrieve from a document that is not yet 'ready' will yield incomplete or no results.
- gotcha Invalid or missing API keys are a common source of authentication failures (401 errors). Additionally, exceeding plan-based rate limits or quotas (e.g., page processing, retrieval limits) can result in 402 or 429 errors.
Install
-
pip install ragie -
poetry add ragie
Imports
- Ragie
from ragie import Ragie
Quickstart
import os
from ragie import Ragie
from dotenv import load_dotenv
load_dotenv() # Load environment variables from .env file
RAGIE_API_KEY = os.environ.get("RAGIE_API_KEY", "")
if not RAGIE_API_KEY:
raise ValueError("RAGIE_API_KEY environment variable not set. Get one at https://secure.ragie.ai/api-keys")
try:
# Initialize the Ragie client using a context manager for resource cleanup
with Ragie(auth=RAGIE_API_KEY) as ragie_client:
# Create a raw document
print("Creating a raw document...")
document = ragie_client.documents.create_raw(request={
"data": "The quick brown fox jumps over the lazy dog. A common phrase used to test typewriters."
})
print(f"Document created with ID: {document.id}")
# Wait for the document to be ready (simplified polling for demonstration)
print("Waiting for document to be ready...")
while True:
doc_status = ragie_client.documents.get(document_id=document.id)
if doc_status.status == "ready":
print(f"Document {document.id} is ready.")
break
# In a real application, you'd add a delay (e.g., time.sleep(1)) and/or timeout
# Retrieve chunks based on a query
print("Retrieving chunks...")
retrieval = ragie_client.retrievals.retrieve(request={"query": "What is a common phrase?"})
if retrieval.chunks:
for chunk in retrieval.chunks:
print(f"Retrieved chunk: {chunk.text}")
else:
print("No chunks retrieved for the query.")
except Exception as e:
print(f"An error occurred: {e}")
# Consider handling specific ragie.models.RagieError for API-related issues