Portable Retrieval-Augmented Generation Library
ragpackai is a Python library for creating, saving, loading, and querying portable RAG (Retrieval-Augmented Generation) packs. It allows you to bundle documents, embeddings, vectorstores, and configuration into a single .rag
file that can be easily shared and deployed across different environments.
- π Portable RAG Packs: Bundle everything into a single
.rag
file - π Provider Flexibility: Support for OpenAI, Google, Groq, Cerebras, and HuggingFace
- π Encryption Support: Optional AES-GCM encryption for sensitive data
- π― Runtime Overrides: Change embedding/LLM providers without rebuilding
- π Multiple Formats: Support for PDF, TXT, MD, and more
- π οΈ CLI Tools: Command-line interface for easy pack management
- π§ Lazy Loading: Efficient dependency management with lazy imports
# Basic installation (minimal dependencies)
pip install ragpackai
# Recommended for most users
pip install ragpackai[standard]
# Specific features
pip install ragpackai[core] # Core RAG functionality
pip install ragpackai[openai] # OpenAI integration
pip install ragpackai[documents] # PDF processing
pip install ragpackai[embeddings] # Sentence transformers
# Provider-specific
pip install ragpackai[google] # Google/Gemini
pip install ragpackai[groq] # Groq
pip install ragpackai[cerebras] # Cerebras
pip install ragpackai[nvidia] # NVIDIA
# Everything (may have installation issues on some systems)
pip install ragpackai[all]
If you encounter installation problems (especially with faiss-cpu
):
# Try the standard installation first
pip install ragpackai[standard]
# For FAISS issues, use conda instead
conda install -c conda-forge faiss-cpu
pip install ragpackai[core,openai,documents,embeddings]
# Get installation help
python -c "import ragpackai; ragpackai.install_guide()"
from ragpackai import ragpackai
# Create a pack from documents
pack = ragpackai.from_files([
"docs/manual.pdf",
"notes.txt",
"knowledge_base/"
])
# Save the pack
pack.save("my_knowledge.rag")
# Load and query
pack = ragpackai.load("my_knowledge.rag")
# Simple retrieval (no LLM)
results = pack.query("How do I install this?", top_k=3)
print(results)
# Question answering with LLM
answer = pack.ask("What are the main features?")
print(answer)
# Load with different providers
pack = ragpackai.load(
"my_knowledge.rag",
embedding_config={
"provider": "google",
"model_name": "textembedding-gecko"
},
llm_config={
"provider": "groq",
"model_name": "mixtral-8x7b-32768"
}
)
answer = pack.ask("Explain the architecture")
# From files and directories
ragpackai create docs/ notes.txt --output knowledge.rag
# With custom settings
ragpackai create docs/ \
--embedding-provider openai \
--embedding-model text-embedding-3-large \
--chunk-size 1024 \
--encrypt-key mypassword
# Simple retrieval
ragpackai query knowledge.rag "How to install?"
# Question answering
ragpackai ask knowledge.rag "What are the requirements?" \
--llm-provider openai \
--llm-model gpt-4o
# With provider overrides
ragpackai ask knowledge.rag "Explain the API" \
--embedding-provider google \
--embedding-model textembedding-gecko \
--llm-provider groq \
--llm-model mixtral-8x7b-32768
ragpackai info knowledge.rag
A .rag
file is a structured zip archive:
mypack.rag
βββ metadata.json # Pack metadata
βββ config.json # Default configurations
βββ documents/ # Original documents
β βββ doc1.txt
β βββ doc2.pdf
βββ vectorstore/ # Chroma vectorstore
βββ chroma.sqlite3
βββ ...
Embedding Providers:
openai
: text-embedding-3-small, text-embedding-3-largehuggingface
: all-MiniLM-L6-v2, all-mpnet-base-v2 (offline)google
: textembedding-gecko
LLM Providers:
openai
: gpt-4o, gpt-4o-mini, gpt-3.5-turbogoogle
: gemini-pro, gemini-1.5-flashgroq
: mixtral-8x7b-32768, llama2-70b-4096cerebras
: llama3.1-8b, llama3.1-70b
Create a RAG pack from files.
Parameters:
files
: List of file paths or directoriesembed_model
: Embedding model in format "provider:model"chunk_size
: Text chunk size (default: 512)chunk_overlap
: Chunk overlap (default: 50)name
: Pack name
Load a RAG pack from file.
Parameters:
path
: Path to .rag fileembedding_config
: Override embedding configurationllm_config
: Override LLM configurationreindex_on_mismatch
: Rebuild vectorstore if dimensions mismatchdecrypt_key
: Decryption password
Save pack to .rag file.
Retrieve relevant chunks (no LLM).
Ask question with LLM.
# Direct provider access
from ragpackai.embeddings import OpenAI, HuggingFace, Google
from ragpackai.llms import OpenAIChat, GoogleChat, GroqChat
# Create embedding provider
embeddings = OpenAI(model_name="text-embedding-3-large")
vectors = embeddings.embed_documents(["Hello world"])
# Create LLM provider
llm = OpenAIChat(model_name="gpt-4o", temperature=0.7)
response = llm.invoke("What is AI?")
# API Keys
export OPENAI_API_KEY="your-key"
export GOOGLE_CLOUD_PROJECT="your-project"
export GROQ_API_KEY="your-key"
export CEREBRAS_API_KEY="your-key"
# Optional
export GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account.json"
# Custom embedding config
embedding_config = {
"provider": "huggingface",
"model_name": "all-mpnet-base-v2",
"device": "cuda" # Use GPU
}
# Custom LLM config
llm_config = {
"provider": "openai",
"model_name": "gpt-4o",
"temperature": 0.7,
"max_tokens": 2000
}
ragpackai supports AES-GCM encryption for sensitive data:
# Save with encryption
pack.save("sensitive.rag", encrypt_key="strong-password")
# Load encrypted pack
pack = ragpackai.load("sensitive.rag", decrypt_key="strong-password")
- Use strong passwords for encryption
- Store API keys securely in environment variables
- Validate .rag files before loading in production
- Consider network security when sharing packs
See the examples/
directory for complete examples:
basic_usage.py
- Simple pack creation and queryingprovider_overrides.py
- Using different providersencryption_example.py
- Working with encrypted packscli_examples.sh
- Command-line usage examples
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- π Documentation
- π Issue Tracker
- π¬ Discussions
Built with:
- LangChain - LLM framework
- ChromaDB - Vector database
- Sentence Transformers - Embedding models