Skip to main content

Python SDK for ragger.ai RAG API

Project description

Ragger Python SDK

Python SDK for the Ragger RAG (Retrieval Augmented Generation) API. Build powerful AI applications that can search and answer questions using your own documents.

Features

  • Easy Integration: Simple Python client. With a few lines of code, you can build a complete RAG application.
  • Document Upload: Support for PDF, Word, text, markdown, and other formats
  • Vector Indexing: Create searchable embeddings from your documents
  • Natural Language Queries: Ask questions and get AI-powered answers with advanced reasoning
  • Conversation Memory: Maintain context across multiple queries
  • Multi-tenant: Organization and project-based document isolation
  • Async Processing: Handle large documents with background processing

Installation

pip install ragger-python-sdk

Quick Start

  1. Initialize the client
from ragger_sdk import RaggerClient
client = RaggerClient(
    base_url="https://your-ragger-server.com/rag/api/v1",
    token="your-api-token"
)
  1. Upload a document
upload_result = client.documents.upload(
    organization="my-company",
    project="knowledge-base",
    name="user-manual",
    file_path="/path/to/manual.pdf"
)
  1. Create searchable index
index_result = client.index.index(
    organization="my-company",
    project="knowledge-base"
)
task_id = index_result['task_id']

# Wait for indexing to complete
status = client.index.status(task_id, organization="my-company")
  1. Ask questions
answer = client.query.ask(
    query="How do I reset my password?",
    organization="my-company",
    project="knowledge-base",
    user="support@company.com"
)

print(f"Answer: {answer['answer']}")
# Assistant: "To reset your password, go to the login page and click 'Forgot Password'..."

print(f"Source: {answer['metadata']['sources']}")
# "Source: {'https://intranet.company.com/policy', 'https://help.company.com/reset-password'}"

print(f"Session ID: {answer['session_id']}")
# 123456789abcdef
  1. Maintain conversation context
followup_answer = client.query.ask(
    query="Sorry, I meant username recovery",
    organization="my-company",
    project="knowledge-base",
    user="support@company.com",
    session_id="123456789abcdef"
)
# Answer: "Unlike password resets, username recovery usually requires contacting support..."

Core Concepts

  • Organization: Top-level container for your projects
  • Project: Collection of related documents and their index
  • Document: Individual files (PDF, Word, text, etc.) containing your data
  • Index: Searchable vector representation of your documents
  • Query: Natural language questions answered using your documents

API Reference

Client Initialization

client = RaggerClient(
    base_url="https://api.ragger.ai/v1",  # Your Ragger server URL
    token="your-api-token",               # API authentication token
    timeout=30,                           # Request timeout in seconds
    verify_ssl=True                       # SSL certificate verification
)

Document Management

# Upload from file
response = client.documents.upload(
    organization="org-name",
    project="project-name",
    name="document-name",
    file_path="/path/to/file.pdf",
    metadata={"author": "John Doe", "department": "Engineering"},
    system_prompt="You are a helpful assistant for company policies",
    text_search_config="english"
)

# Upload from text content
response = client.documents.upload(
    organization="org-name",
    project="project-name",
    name="document-name",
    content="Your text content here...",
    content_type="text/markdown",
    metadata={"source": "manual_entry"}
)

# Check processing status
status = client.documents.status(
    task_id=response['task_id'],
    organization="org-name"
)

Index Management

# Create/update index
response = client.index.index(
    organization="org-name",
    project="project-name",
    force_overwrite=False
)

# Check indexing status
task_id = response['task_id']
status = client.index.status(
    task_id=task_id,
    organization="org-name"
)

Querying

# Basic query
answer = client.query.ask(
    query="What is the return policy?",
    organization="org-name",
    project="project-name",
    user="user@example.com"
)

# Query with session (maintains conversation context)
answer = client.query.ask(
    query="Tell me more about that",
    organization="org-name",
    project="project-name",
    user="user@example.com",
    session_id="conversation-123"
)

Deleting Documents

# Delete a single document by name
response = client.documents.delete(
    organization="org-name",
    project="project-name",
    name="document-name"
)

# Delete all documents in a project (use with caution!)
response = client.documents.delete(
    organization="org-name",
    project="project-name",
    delete_all=True
)

Chat History

# Get all sessions for a user
sessions = client.chat_history.sessions(
    organization="org-name",
    project="project-name",
    user="user@example.com"
)

# Get specific session details
session = client.chat_history.session(
    organization="org-name",
    project="project-name",
    user="user@example.com",
    session_id="session-123"
)

Error Handling

The SDK raises RaggerAPIError for API-related issues. You can inspect the error type:

try:
    result = client.some_operation()
except RaggerAPIError as e:
    if e.is_validation_error():
        # Handle parameter validation
    elif e.is_not_found():
        # Handle missing resources
    elif e.is_conflict():
        # Handle resource conflicts

Examples

See the examples/ directory for complete usage examples:

  • documents_from_file_example.py - File upload and processing
  • index_example.py - Vector index creation
  • query_example.py - Natural language querying
  • chat_history_example.py - Conversation management

Requirements

  • Python 3.8+
  • requests >= 2.25.0

License

MIT License - see LICENSE file for details.

Support

Development

To contribute or modify the SDK, clone the repository and install dependencies:

git clone <repository-url>
cd ragger-sdk
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt

Create a tagged release:

git tag -a vX.Y.Z -m "Release version X.Y.Z"
git push origin vX.Y.Z

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

ragger_python_sdk-0.1.3.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

ragger_python_sdk-0.1.3-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file ragger_python_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: ragger_python_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.3 Linux/6.8.0-57-generic

File hashes

Hashes for ragger_python_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f524fa600d7659fa5af92bcf377c416bbcc5fa63c6c914b98d6bd842c304097f
MD5 065bd761cc1fbc5c8594cf21a34b6198
BLAKE2b-256 0d0496af27b3768bbcdc1c9c98e0e9d9a0c639d8d16cb31eea97f2a9a503e08c

See more details on using hashes here.

File details

Details for the file ragger_python_sdk-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ragger_python_sdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.3 Linux/6.8.0-57-generic

File hashes

Hashes for ragger_python_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fa2d41562140a20e2711f7c165dcc31155f63f8fa4239b1247a643e9e021fd7d
MD5 6c2583052c4dfcb74a8bf13dc3c2af2e
BLAKE2b-256 216e5b8a06a568e83692d78cfb811422a7404d4034bfabffb5f04907924bf8f4

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