Skip to main content

RagSaaS Python SDK

Zero-config RAG for LangChain agents. One decorator, instant knowledge base.

Installation

pip install ragsaas

Quick Start

import os
os.environ["RAGSAAS_API_KEY"] = "sk_xxx"  # Your project API key

from ragsaas import with_rag
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

# Wrap your agent - tenant is your customer's ID
@with_rag(tenant_id="customer-123")
def create_agent():
    return create_react_agent(ChatOpenAI(), [])

agent = create_agent()
result = agent.invoke({"messages": [("user", "What does the docs say about pricing?")]})
# Agent automatically has access to customer-123's knowledge base

Dynamic Tenant (Multi-tenant Apps)

For web apps where tenant comes from request context:

from ragsaas import with_rag
from flask import g

# Tenant resolved at runtime
@with_rag(tenant_id=lambda: g.current_user.tenant_id)
def get_agent():
    return create_react_agent(llm, tools)

@app.route("/chat")
def chat():
    agent = get_agent()
    return agent.invoke({"messages": [("user", request.json["query"])]})

How It Works

The @with_rag decorator:

  1. Intercepts agent invocations
  2. Extracts the user's query
  3. Searches the tenant's knowledge base
  4. Injects relevant context as a system message
  5. Passes to the original agent

Your agent gets knowledge base context automatically - no tools, no pipelines, no config.

Manual Usage

If you need more control:

from ragsaas import RAGAgent

rag = RAGAgent(tenant_id="customer-123")

# Retrieve context manually
context = rag.retrieve("What is the refund policy?")
print(context.content)
print(context.sources)

# Or wrap an existing agent
agent = rag.wrap(my_agent)

Configuration

Env Variable Required Description
RAGSAAS_API_KEY Yes Your project API key
RAGSAAS_BASE_URL No API URL (default: https://api.ragsaas.com)

Decorator options:

@with_rag(
    tenant_id="customer-123",      # Required: customer identifier
    collection="support-docs",      # Optional: filter by collection
    top_k=10,                       # Optional: number of results (default: 5)
    use_hybrid=True,                # Optional: hybrid search (default: False)
    threshold=0.7,                  # Optional: minimum score threshold
)

With Different Frameworks

LangGraph

from langgraph.prebuilt import create_react_agent
from ragsaas import with_rag

@with_rag(tenant_id="customer-123")
def create_support_agent():
    return create_react_agent(
        ChatOpenAI(model="gpt-4o"),
        tools=[search_tool, calculator_tool],
    )

LangChain Chains

from langchain.chains import RetrievalQA
from ragsaas import RagSaaSRetriever

# For chains, use the retriever directly
retriever = RagSaaSRetriever(tenant_id="customer-123")
qa = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)

Raw Client

from ragsaas import RagSaaSClient

client = RagSaaSClient(
    api_key="sk_xxx",
    tenant_id="customer-123",
)

# Search
docs = client.search("machine learning", top_k=5)

# Hybrid search
docs = client.hybrid_search("ML basics", semantic_weight=0.7)

# Generate answer
answer = client.answer("What is ML?")
print(answer.answer)
print(answer.sources)

Metadata

Release files for ragsaas 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ragsaas 0.1.0
File Size Uploaded
ragsaas-0.1.0.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ragsaas 0.1.0
File Interpreter ABI Platform
ragsaas-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / ragsaas-0.1.0.tar.gz

Download URL ragsaas-0.1.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7f41298b06866a220fcf8cedfbfaee041ccaab029fa1eaa57d468d94d84aaaf6
BLAKE2b-256 checksum
How to use checksums
3a76be1e71937464b8413adc02c1805c4d4d354c8b90fa795a67cfb0bccb8ba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / ragsaas-0.1.0-py3-none-any.whl

Download URL ragsaas-0.1.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
520ecca502de847b8cac6b94784c059ff7eb46424911ae543e088a5ac3a5b186
BLAKE2b-256 checksum
How to use checksums
a82af4b53c91ca8027ca05b3817df5330a58da119358115633b37f3e92b6a7eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page