RAGIE Python Client SDK

1.15.1 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Ragie client, create a raw text document, wait for its processing to complete (indicated by the 'ready' status), and then perform a retrieval query to get relevant information based on the ingested document. Ensure you have `RAGIE_API_KEY` set as an environment variable.

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

view raw JSON →