Skip to main content

ragplus

PyPI version Python 3.9+ License: MIT Downloads

Lightweight, production-ready RAG (Retrieval-Augmented Generation) toolkit with 100% offline capabilities.

Build powerful RAG applications with document loading, hybrid search, reranking, and semantic chunking - all without API keys or internet connectivity.


🎯 Why ragplus?

  • 🔒 100% Offline - No API keys, no internet required, perfect for air-gapped environments
  • ⚡ Production-Ready - Proper error handling, type hints, comprehensive testing
  • 🎨 Flexible - Plug in any LLM (OpenAI, Anthropic, local models, Ollama)
  • 📦 Lightweight - Minimal dependencies, easy to integrate
  • 🚀 High Performance - Hybrid search + reranking for 20-40% accuracy boost

✨ Features

Core RAG Capabilities

  • 🔹 Smart Document Loading - Auto-detects and loads PDF, DOCX, TXT files
  • 🔹 Multiple Embedding Models - MiniLM, BGE (default), E5 (all offline)
  • 🔹 Advanced Chunking - Fixed, sentence-based (with overlap), markdown-aware, heading-based, semantic
  • 🔹 Vector Storage - In-memory with persistence and metadata filtering
  • 🔹 Semantic Search - Cosine similarity with optional hybrid BM25

v0.2.2 Accuracy Improvements ⚡ NEW!

  • 🎯 Enhanced BM25 Tokenization - Regex-based with stemming (+20-30% accuracy)
  • 🚀 BGE-Base Default - Upgraded from MiniLM (+10-15% accuracy)
  • 📊 Query/Passage Prefixes - Optimized for BGE/E5 models (+5-10% accuracy)
  • 🔄 Chunking with Overlap - Better context preservation (+5-10% accuracy)
  • 🧠 Semantic Chunking - Groups similar sentences together (+10-15% accuracy)
  • Total Improvement: 50-70% better accuracy! 🎉

v0.2.1 Advanced Features

  • 🔍 Hybrid Search - Combines BM25 keyword + embedding semantic search
  • 🎯 Cross-Encoder Reranking - 20-40% accuracy improvement
  • 💾 Persistent Storage - Cache embeddings for instant reloads
  • 🏷️ Metadata Filtering - Filter by source, page, section, custom fields
  • 📝 Token-Based Truncation - Accurate context limits with tiktoken
  • 🤖 Auto-Loader - Handles file paths, bytes, and text automatically

📦 Installation

pip install ragplus

Requirements: Python 3.9+


🚀 Quick Start

Basic RAG Pipeline

from ragplus import rag_answer, Embedder

def my_llm(prompt: str) -> str:
    # Use any LLM: OpenAI, Anthropic, Ollama, local models
    return "Your LLM response here"

# Works with text, file paths, or PDF bytes
documents = "RAG combines retrieval with generation for better AI responses."
query = "What is RAG?"

answer = rag_answer(query, documents, llm_fn=my_llm)
print(answer)

Advanced Usage with All Features

from ragplus import rag_answer, Embedder

# Maximum accuracy configuration
answer = rag_answer(
    query="What are the key findings?",
    documents="report.pdf",  # or PDF bytes from upload
    llm_fn=my_llm,
    
    # Advanced features
    use_hybrid_search=True,      # BM25 + embeddings
    use_reranking=True,           # Cross-encoder reranking
    chunk_strategy="sentence",    # Better chunking
    max_tokens=4096,              # Token-based truncation
    persist_dir="./rag_cache",    # Cache for fast reloads
    
    # Fine-tuning
    k=10,                         # Retrieve top 10 chunks
    embedder=Embedder("bge-base") # High-accuracy embeddings
)

📚 Documentation

Load Documents

from ragplus import load_document, load_pdf, load_docx

# Auto-detect format
text = load_document("report.pdf")

# Specific loaders
pdf_text = load_pdf("document.pdf")
docx_text = load_docx("report.docx")

Choose Embedding Models

from ragplus import Embedder

# High accuracy (recommended)
embedder = Embedder(model_name="bge-base")

# Fastest
embedder = Embedder(model_name="minilm")

# Best accuracy
embedder = Embedder(model_name="e5-large")

Hybrid Search (BM25 + Embeddings)

from ragplus import HybridRetriever, VectorStore, Embedder

embedder = Embedder()
store = VectorStore()
# ... add documents ...

hybrid = HybridRetriever(
    vectorstore=store,
    embedder=embedder,
    bm25_weight=0.3,        # 30% keyword matching
    embedding_weight=0.7     # 70% semantic similarity
)

results = hybrid.search("your query", k=5)

Semantic Chunking Strategies

from ragplus import chunk_text

# Markdown-aware (preserves structure)
chunks = chunk_text(text, strategy="markdown")

# Sentence-based (natural boundaries)
chunks = chunk_text(text, strategy="sentence")

# Heading-based (section-aware)
chunks = chunk_text(text, strategy="heading")

# Fixed-size (default)
chunks = chunk_text(text, size=500, overlap=50)

Persistent Vector Store

from ragplus import VectorStore

# Auto-save and auto-load
store = VectorStore(persist_dir="./my_index")
store.add_documents(texts, embeddings, doc_id="file1.pdf")

# Reload instantly on next run
store = VectorStore(persist_dir="./my_index")  # Auto-loads existing data

🎓 Examples

See the examples/ directory:


🔑 Keywords

RAG, Retrieval Augmented Generation, LLM, embeddings, vector search, semantic search, document QA, offline RAG, Python RAG, BM25, hybrid search, cross-encoder, reranking, PDF extraction, DOCX parsing, sentence transformers, BGE embeddings, E5 embeddings, local RAG, air-gapped AI, private AI, document intelligence


🤝 Contributing

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


📄 License

MIT License - see LICENSE file for details.


🌟 Star History

If you find ragplus useful, please consider giving it a star on GitHub!


📞 Support


Made with ❤️ for the AI community

Metadata

Release files for ragplus 0.2.2

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

Source distribution (sdist)

Source distribution for ragplus 0.2.2
File Size Uploaded Provenance Actions
ragplus-0.2.2.tar.gz 22.5 kB Without provenance Details for ragplus-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 44.8 kB

Release files / ragplus-0.2.2.tar.gz

Download URL ragplus-0.2.2.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
41dc6a48e2c71504d7cf8ef67ec3cf2fca3ca0a93f58c8266b9d921f9951c24f
BLAKE2b-256 checksum
How to use checksums
f91805122cff59b6cb83e0164bad085fb46dfa9770d7941145ec6bebe7dd3520
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.0

Release files / ragplus-0.2.2-py3-none-any.whl

Download URL ragplus-0.2.2-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfdf04f2a9799ddc6f93e5bbc5839d683d3afffc8cb5ab0c62bf8c2946ef21fa
BLAKE2b-256 checksum
How to use checksums
e3ae1167e3d2a119e0aa51ecb5ee99e39409d0bd25643568116eb9e78ed0a5c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.0

Security for ragplus 0.2.2

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