Skip to main content

RagXO

Export, version and reuse your E2E RAG pipeline everywhere 🚀

PyPI version License: MIT Python 3.8+

Table of Contents

RagXO extends the capabilities of traditional RAG (Retrieval-Augmented Generation) systems by providing a unified way to package, version, and deploy your entire RAG pipeline with LLM integration. Export your complete system—including embedding functions, preprocessing steps, vector store, and LLM configurations—into a single, portable artifact.

Features ✨

  • Complete RAG Pipeline: Package your entire RAG system into a versioned artifact
  • LLM Integration: Built-in support for OpenAI models
  • Flexible Embedding: Compatible with any embedding function (Sentence Transformers, OpenAI, etc.)
  • Custom Preprocessing: Chain multiple preprocessing steps
  • Vector Store Integration: Built-in Milvus support
  • System Prompts: Include and version your system prompts

Installation 🛠️

pip install ragxo

Quickstart 🚀

Build a RAG pipeline

export OPENAI_API_KEY=<openai_key> 
from ragxo import Ragxo, Document



ragxo_client = Ragxo(dimension=1536)

def preprocess_text_remove_special_chars(text: str) -> str:
    return re.sub(r'[^a-zA-Z0-9\s]', '', text)

def preprocess_text_lower(text: str) -> str:
    return text.lower()

def get_embeddings(text: str) -> list[float]:
    return openai.embeddings.create(input=text, model="text-embedding-ada-002").data[0].embedding

ragxo_client.add_preprocess(preprocess_text_lower)
ragxo_client.add_preprocess(preprocess_text_remove_special_chars)
ragxo_client.add_embedding_fn(get_embeddings)

ragxo_client.add_system_prompt("You are a helpful assistant that can answer questions about the data provided.")
ragxo_client.add_model(
    "gpt-4o-mini",
    limit=10,
    temperature=0.5,
    max_tokens=1000,
    top_p=1.0,
    frequency_penalty=0.0,
    presence_penalty=0.0
)

ragxo_client.index([
    Document(text="Capital of France is Paris", metadata={"source": "example"}, id=1),
    Document(text="Capital of Germany is Berlin", metadata={"source": "example"}, id=2),
    Document(text="Capital of Italy is Rome", metadata={"source": "example"}, id=3),
])

ragxo_client.export("my_rag_v1.0.0")

# or export to s3
ragxo_client.export("my_rag_v1.0.0", s3_bucket="my_bucket")

Load a RAG pipeline

loaded_ragxo_client = Ragxo.load("my_rag_v1.0.0")

vector_search_results = loaded_ragxo_client.query("What is the capital of France?")

llm_response = loaded_ragxo_client.generate_llm_response(
    "What is the capital of France?")

print(llm_response.choices[0].message.content)

Usage Guide 📚

Import

from ragxo import Ragxo, Document

ragxo_client = Ragxo(dimension=768)

Adding Preprocessing Steps

import re

def remove_special_chars(text: str) -> str:
    return re.sub(r'[^a-zA-Z0-9\s]', '', text)

def lowercase(text: str) -> str:
    return text.lower()

ragxo_client.add_preprocess(remove_special_chars)
ragxo_client.add_preprocess(lowercase)

Custom Embedding Functions

# Using SentenceTransformers
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')

def get_embeddings(text: str) -> list[float]:
    return model.encode(text).tolist()

ragxo.add_embedding_fn(get_embeddings)

# Or using OpenAI
from openai import OpenAI
client = OpenAI()

def get_openai_embeddings(text: str) -> list[float]:
    response = client.embeddings.create(
        input=text,
        model="text-embedding-ada-002"
    )
    return response.data[0].embedding

ragxo.add_embedding_fn(get_openai_embeddings)

Creating Documents

from ragxo import Document

doc = Document(
    text="Your document content here",
    metadata={"source": "wiki", "category": "science"},
    id=1
)

ragxo_client.index([doc])

LLM Configuration

# Set system prompt
ragxo_client.add_system_prompt("""
You are a helpful assistant. Use the provided context to answer questions accurately.
If you're unsure about something, please say so.
""")

# Set LLM model
ragxo_client.add_model("gpt-4")

Export and Load

# Export your RAG pipeline
ragxo_client.export("rag_pipeline_v1")

# Load it elsewhere
loaded_ragxo_client = Ragxo.load("rag_pipeline_v1")

Evaluation

from ragxo import EvaluationExample

# Create test examples
test_data = [
    EvaluationExample(
        query="What is the capital of France?",
        expected="The capital of France is Paris."
    ),
    EvaluationExample(
        query="What is the capital of Germany?",
        expected="The capital of Germany is Berlin."
    ),
]

# Evaluate the RAG system
accuracy = ragxo_client.evaluate(
    test_data=test_data,
    batch_size=10,  # Process 10 examples at a time
    judge_model="gpt-4o-mini"  # Optional: specify a different model for evaluation
)

print(f"Evaluation accuracy: {accuracy * 100:.2f}%")

The evaluation process:

  1. Processes test examples in batches
  2. Generates RAG responses for each query
  3. Uses an LLM to compare generated answers with expected answers
  4. Returns accuracy score (0.0 to 1.0)

Best practices for evaluation:

  • Use diverse test examples
  • Include edge cases
  • Keep expected answers consistent in format
  • Use a more capable model for evaluation (e.g., GPT-4)
  • Adjust batch size based on your rate limits and needs

Best Practices 💡

  1. Version Your Exports: Use semantic versioning for your exports:
ragxo.export("my_rag_v1.0.0")
  1. S3: Use S3 to store your exports
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
ragxo_client.export("my_rag_v1.0.0", s3_bucket="my_bucket")

License 📝

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for ragxo 0.1.13

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

Source distribution (sdist)

Source distribution for ragxo 0.1.13
File Size Uploaded Provenance Actions
ragxo-0.1.13.tar.gz 10.4 kB Without provenance Details for ragxo-0.1.13.tar.gz

Built distribution (wheel)

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

Total release size: 19.2 kB

Release files / ragxo-0.1.13.tar.gz

Download URL ragxo-0.1.13.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
142d045f255a3695abd58be8727f2ccd00ab34eca1f883019691f0e7797d4273
BLAKE2b-256 checksum
How to use checksums
6d0b0dafc8ac561f045198bb689362cca6eca384cddfcadb7ecc24e8df91088d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

Release files / ragxo-0.1.13-py3-none-any.whl

Download URL ragxo-0.1.13-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65383655e9ef9d0743b64292836155bda5f009867a65fbf6a298207c9c610b15
BLAKE2b-256 checksum
How to use checksums
71521f2dee8fee9689a44b4ad7cea47958f744677d108159f9db7cb4021cf98b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

Security for ragxo 0.1.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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