Skip to main content

Zero-config RAG integration for LangChain, LlamaIndex, and AI agents

Project description

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)

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

ragsaas-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

ragsaas-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file ragsaas-0.1.0.tar.gz.

File metadata

  • Download URL: ragsaas-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ragsaas-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f41298b06866a220fcf8cedfbfaee041ccaab029fa1eaa57d468d94d84aaaf6
MD5 8a20306b6283323a754c2341f1c73ebe
BLAKE2b-256 3a76be1e71937464b8413adc02c1805c4d4d354c8b90fa795a67cfb0bccb8ba7

See more details on using hashes here.

File details

Details for the file ragsaas-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ragsaas-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ragsaas-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 520ecca502de847b8cac6b94784c059ff7eb46424911ae543e088a5ac3a5b186
MD5 1eae694305e1507720f5608305864603
BLAKE2b-256 a82af4b53c91ca8027ca05b3817df5330a58da119358115633b37f3e92b6a7eb

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