Skip to main content

A RAG (Retrieval-Augmented Generation) toolkit with Milvus integration

Project description

RagXO

Export, version and reuse your RAG pipeline everywhere 🚀

PyPI version License: MIT Python 3.8+

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

from ragxo import Ragxo, Document

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

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

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

ragxo_client = Ragxo(dimension=768)

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")

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?")

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")

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.

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

ragxo-0.1.9.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

ragxo-0.1.9-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ragxo-0.1.9.tar.gz.

File metadata

  • Download URL: ragxo-0.1.9.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for ragxo-0.1.9.tar.gz
Algorithm Hash digest
SHA256 3ede0114dc86c9d6b0dbe846702ee96974b8d1b5004d226579fa9c6455ec9f58
MD5 0e941185a12791fbfb506625c8ba54cb
BLAKE2b-256 7d2b1f65e6d1d2db22d27a7dddd18c598948091f3d3de0d5d7694ab5b19d3a43

See more details on using hashes here.

File details

Details for the file ragxo-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: ragxo-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for ragxo-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 10c370d3c6859e1d5ab249e0c6c42b6d35f646f55e05b54c3f72ae95ae0afa1b
MD5 cfa22e7e1e50e124f3db13011d673fa1
BLAKE2b-256 29fda1d742ce2756225cd97423a66921d06f17e91e27475e0c7c7b13c29b0b9d

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