PolyRAG 🧬
PolyRAG is a modular, multi-paradigm Retrieval-Augmented Generation (RAG) framework designed to unify multiple RAG architectures—from standard Naive 1-Shot RAG and Advanced Multi-Query RAG, to autonomous Agentic RAG and future expansions like GraphRAG.
🏛️ The RAG Class Hierarchy
PolyRAG is architected around an object-oriented class hierarchy rooted in BaseRAG:
┌─────────────────────────┐
│ BaseRAG │
│ (Abstract Base Class) │
└────────────┬────────────┘
│
┌──────────────────────────┼──────────────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ NaiveRAG │ │ AdvancedRAG │ │ AgenticRAG │
│ (1-Shot RAG) │ │ (Expand/RRF) │ │ (Reflection) │
└──────────────┘ └──────────────┘ └──────┬───────┘
│
▼
┌──────────────┐
│ ReActAgent │
│ (ReActRAG) │
└──────────────┘
All derived pipelines inherit shared document ingestion (ingest_text, ingest_file, ingest_directory), vector search (retrieve), and context assembly (format_context) from BaseRAG.
🌟 Key Features
-
Multi-Paradigm Pipelines:
NaiveRAG: Standard retrieve-then-read pipeline with minimal latency.AdvancedRAG: Multi-query expansion, parallel search, and Reciprocal Rank Fusion (RRF) re-ranking.AgenticRAG: Planning, keyword rewriting, iterative multi-round search, deduplication, and fused self-reflection with source citations.ReActAgent: Structured Thought-Action-Observation reasoning loop with dynamic tool execution.- Coming Soon:
GraphRAG(knowledge graph entity extraction, community detection, and summarization).
-
Native LangChain Foundation:
- Built directly on top of
langchain-coreandlangchain-text-splittersprimitives. - Zero-wrapper pluggability: pass ANY LangChain
VectorStore(Chroma, Milvus, Pinecone, FAISS, PGVector),Embeddings(OpenAI, HuggingFace, Ollama, Cohere),BaseChatModel(ChatOpenAI,ChatAnthropic,ChatGoogleGenerativeAI,ChatOllama), orTextSplitterdirectly into PolyRAG pipelines. - Full bidirectional compatibility: PolyRAG components can be used anywhere a LangChain runnable or component is expected.
- Built directly on top of
-
Dependency Injection:
- Built-in
Containeracting as the Composition Root for all services, adapters, and pipelines. - Seamless DI resolution and alias mapping for both PolyRAG and LangChain types (
VectorStore,Embeddings,BaseChatModel,TextSplitter). - Full support for Singleton and Transient scopes, lifecycle management, and 1-line test mocking.
- Built-in
-
Clean & Swappable Components:
- Vector Stores: Built-in
InMemoryVectorStore(zero-dependency cosine/L2/dot similarity) or any LangChainVectorStore(Chroma,Milvus,FAISS,Pinecone,PGVector,Qdrant). - Chunkers:
FixedSizeChunker,RecursiveCharacterChunker(subclassing LangChain'sTextSplitter). - Embeddings: Built-in
FakeEmbeddingsfor zero-setup local dev or any LangChainEmbeddings(OpenAIEmbeddings,HuggingFaceEmbeddings,OllamaEmbeddings,CohereEmbeddings). - Chat Models: Standard LangChain
BaseChatModelandChatOpenAI(supporting OpenAI, Anthropic, Gemini, Ollama, Azure, and vLLM).
- Vector Stores: Built-in
📚 Documentation
Comprehensive documentation is available in the docs/ directory:
- Getting Started: Installation & Quickstart
- Configuration: Environment Variables, Custom Pipelines, & Dependency Injection Guide
- Guides: Class Hierarchy, Naive RAG, Advanced RAG, Agentic RAG, & ReAct Agent
- Modules: Vector Stores, Embeddings, LLMs, Chunkers, App & Factory
- API Reference: Core Entities, Pipelines, & Services / Container
- Roadmap: GraphRAG & Hybrid Search
- Deep Analysis: Deep Agents Cost & Architecture
📦 Installation
# Minimal installation (core pipelines, DI container, in-memory vector store)
pip install polyrag
# With OpenAI support (langchain-openai)
pip install "polyrag[openai]"
# With ChromaDB vector store (langchain-chroma)
pip install "polyrag[chroma]"
# With Milvus vector store (langchain-milvus)
pip install "polyrag[milvus]"
# With HuggingFace embeddings (langchain-huggingface)
pip install "polyrag[huggingface]"
# Complete installation with all official partner packages
pip install "polyrag[all]"
🚀 Quick Start
1. Instant Setup from Environment (PolyRAG)
from polyrag import PolyRAG
# Automatically loads configuration from environment variables (.env)
app = PolyRAG.from_env()
# Ingest raw text, a file, or an entire folder into the shared store
app.ingest("RFC 1035 specifies DNS domain name syntax.", source="rfc1035.txt")
app.ingest_file("data/rfc9000.txt")
app.ingest_directory("docs/", glob_pattern="*.txt")
# End-to-end question answering (convenience shortcut)
response = app.query("How does DNS translate domain names?")
print("Answer:", response.answer)
print("Sources:", response.sources)
2. Manufacturing Across the Pipeline Hierarchy
Manufacture the exact pipeline strategy you need from the configured setup:
# Level 1: Standard 1-Shot RAG
naive = app.create_naive_rag()
naive_res = naive.query("What is DNS?")
# Level 2: Advanced RAG (Multi-Query Expansion & RRF Re-ranking)
advanced = app.create_advanced_rag(num_expanded_queries=3, top_k=5)
advanced_res = advanced.query("How does DNS handle packet truncation?")
# Level 3: Agentic RAG (Autonomous Multi-Round Loop & Fused Reflection)
agentic = app.create_agentic_rag(max_rounds=2, top_k=3, verbose=True)
agentic_res = agentic.query(
"What transport protocol does HTTP/3 rely on, and how does connection migration work?"
)
print("Agentic Grounded Answer:\n", agentic_res.answer)
print("Confidence:", agentic_res.confidence)
print("Trajectory:", agentic_res.reasoning_summary)
3. Advanced: Dependency Injection (For Custom Backends & Testing)
from polyrag import (
Container,
PolyRAG,
BaseVectorStore,
BaseLLMClient,
InMemoryVectorStore,
)
# 1. Initialize DI Container (Composition Root)
container = Container()
# 2. Register custom implementations or test mocks
container.register_instance(BaseVectorStore, InMemoryVectorStore())
# container.register_instance(BaseLLMClient, MyCustomOllamaLLM())
# 3. Option A: Build pipelines directly with injected dependencies
pipeline = container.build_agentic_rag(top_k=3, max_rounds=2)
response = pipeline.query("Explain TLS 1.3 0-RTT handshakes.")
print(response.answer)
# 3. Option B: Pass to PolyRAG for familiar ingestion & pipeline manufacturing
app = PolyRAG.from_container(container)
app.ingest("RFC 8446 defines the TLS 1.3 protocol.")
advanced = app.create_advanced_rag()
🧪 Testing
PolyRAG includes a complete suite of unit tests verifying all chunkers, stores, pipelines, and the DI container:
pytest tests
🛠️ Building & Publishing
To package PolyRAG for distribution:
# Build wheel and sdist
python -m build
# Upload to PyPI using twine
twine upload dist/*
📄 License
This project is licensed under the MIT License.
Metadata
Release files for polyrag 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polyrag-0.2.0.tar.gz | 57.4 kB | Without provenance | Details for polyrag-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polyrag-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for polyrag-0.2.0-py3-none-any.whl |
Total release size: 105.8 kB
Release files / polyrag-0.2.0.tar.gz
| Download URL | polyrag-0.2.0.tar.gz |
|---|---|
| Size | 57.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ceacb67517e84d35961ca6c825f6cfca1b58843389997ea8062644a4fd7254a8
|
|
BLAKE2b-256 checksum How to use checksums |
45a44b2360c02eff8ef0ddc62a0d2c980716f8a02667ac9fc5f286002d0c79cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / polyrag-0.2.0-py3-none-any.whl
| Download URL | polyrag-0.2.0-py3-none-any.whl |
|---|---|
| Size | 48.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8a60874816bd69e19c890c1121babfad4a4f8e4a7e070937b41b9d1919d5a17
|
|
BLAKE2b-256 checksum How to use checksums |
bdc08a24f86cfa50e26a42685f7fa28b87adae4304694585be0ef2a42bf1709d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for polyrag 0.2.0
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.