Skip to main content

Zero-Configuration RAG Framework and Embeddable SDK for Python

Project description

mzero: Zero-Configuration RAG Framework

License: MIT Python 3.11+ FastAPI Streamlit

mzero is a zero-configuration Retrieval-Augmented Generation (RAG) framework and embeddable Python SDK. It abstracts document ingestion, domain-aware chunking, dynamic vector store routing, hybrid dense/sparse search, cross-encoder reranking, conversation state management, and hallucination verification behind a minimal single-line interface.

from mzero import RAG

rag = RAG("./docs")
print(rag.ask("Explain the refund policy"))

Architecture Flow

graph TD
    A[Document Corpus] --> B[Router Parser]
    B -->|PDF / DOCX / MD / Code / Web| C[Adaptive Chunker]
    C --> D[Embedding Selector]
    D --> E[Vector DB Store Router]
    E -->|FAISS / Chroma / Qdrant / Milvus| F[Hybrid Retriever]
    
    UserQuery[User Query] --> G[Semantic Cache]
    G -->|Cache Hit| ReturnCache[Return Cached Response]
    G -->|Cache Miss| F
    
    F -->|Reciprocal Rank Fusion| H[Cross-Encoder Reranker]
    H --> I[LLM Query Engine]
    I --> J[Hallucination Verifier]
    J -->|Verified| Output[Response & Citations]
    J -->|Unverified Grounding| WebFallback[Web Search Fallback]

Core Specifications & Features

  • Zero Configuration Setup: Automatic runtime initialization of storage, indexes, and model pipelines based on directory inspection.
  • Smart Multi-Format Parsing: Built-in support for PDF, DOCX, TXT, MD, HTML, CSV, JSON, XML, PPTX, Source Code ASTs, Web Pages, OCR Images, and YouTube transcripts.
  • Adaptive Chunking: Domain-aware context splitting for structured manuals, AST-based source code parsing, legal contracts, research papers, and FAQ structures.
  • Content-Aware Embedding Selector: Automatic model selection (BGE, BGE-M3, Code-specialized, Bio-medical, or Cloud API models) matching input context language and domain.
  • Dynamic Vector DB Routing: Automatic tier assignment:
    • FAISS CPU for lightweight local datasets (<50MB)
    • ChromaDB for medium local stores (<1GB)
    • Qdrant or Milvus for large-scale distributed deployments (>1GB)
  • Hybrid Dense & Sparse Search: Reciprocal Rank Fusion (RRF) combining dense vector search and BM25 sparse keyword matching, followed by Cross-Encoder reranking.
  • Incremental Indexing Engine: Incremental document delta tracking using SHA-256 signatures to update modified files without full re-indexing.
  • Hallucination Verification & Web Fallback: Grounding verification scoring model calculating source token overlap, triggering optional web search fallback when verification drops below threshold.
  • Embeddable Framework Adapters: Native integration adapters for FastAPI, Streamlit, LangChain, LlamaIndex, and Flask applications.

Installation & Setup

pip install mzero-rag

To include framework optional dependencies (e.g. Streamlit, vector storage backends):

# Install with Streamlit support
pip install mzero-rag[streamlit]

# Install full enterprise bundle
pip install mzero-rag[full]

Google Colab Guide

For step-by-step instructions on running mzero inside Google Colab (including Google Drive mounting, token streaming, and exposing Streamlit via localtunnel), see COLAB_README.md.


API Reference & SDK Usage

Synchronous SDK Usage

from mzero import RAG

# Initialize pipeline pointing to knowledge base directory
rag = RAG(docs_path="./docs")

# Single question retrieval and generation
response = rag.ask("What is the warranty coverage period?")

print("Answer:", response.answer)
print("Confidence Score:", response.confidence)
print("Citations:", response.citations)

# Streaming token response
for token in rag.stream("Summarize section 4 of the documentation"):
    print(token, end="", flush=True)

Custom Provider & API Key Configuration

You can easily instantiate RAG with any document folder and API key from any LLM provider (OpenAI, Gemini, NVIDIA, Anthropic, Groq, OpenRouter, etc.), passed directly or resolved automatically from environment variables:

from mzero import RAG

# 1. Direct Initialization with explicit API Key
rag = RAG(
    docs_path="./my_documents",
    llm_provider="openai",        # "openai", "nvidia", "gemini", "anthropic", "groq", "openrouter"
    llm_model="gpt-4o-mini",
    api_key="sk-..."
)

# 2. NVIDIA NIM Example
rag_nvidia = RAG(
    docs_path="./my_documents",
    llm_provider="nvidia",
    llm_model="meta/llama-3.1-70b-instruct",
    api_key="nvapi-..."
)

# 3. Provider specified, API key automatically pulled from environment variable (e.g. GEMINI_API_KEY)
rag_gemini = RAG(
    docs_path="./my_documents",
    llm_provider="gemini"
)

# 4. Zero-config auto-detection (Detects provider & key automatically from environment)
# Scans environment for OPENAI_API_KEY, GEMINI_API_KEY, NVIDIA_API_KEY, ANTHROPIC_API_KEY, GROQ_API_KEY, etc.
rag_auto = RAG(docs_path="./my_documents")

Asynchronous SDK Usage

import asyncio
from mzero import AsyncRAG

async def run_query():
    rag = AsyncRAG(docs_path="./docs")
    response = await rag.aask("How do I initiate a return?")
    print("Answer:", response.answer)

asyncio.run(run_query())

Framework Integration Adapters

Streamlit Integration

Embed an interactive chat UI into any existing Streamlit application.

import streamlit as st
from mzero.adapters.streamlit import render_mzero_chat

st.set_page_config(page_title="mzero Knowledge Base", layout="wide")

# Mount interactive chat component bound to local documents
render_mzero_chat(docs_path="./docs")

Run the Streamlit application:

streamlit run app.py

FastAPI Integration

Mount mzero endpoints directly onto a FastAPI app instance:

from fastapi import FastAPI
from mzero.adapters.fastapi import mount_mzero

app = FastAPI(title="Knowledge Base Service")

# Mount /ask, /stream, and /stats endpoints
mount_mzero(app, docs_path="./docs")

CLI & Telemetry Dashboard

Start API Server & Telemetry Dashboard

mzero serve --port 8000

Access the built-in live telemetry dashboard at: http://localhost:8000/dashboard

CLI Direct Query

mzero ask "What are the API rate limits?" --docs ./docs

Documentation & AI Context

  • Module Architecture Reference: For a technical breakdown of every package module, parser, chunker, vector DB router, and retriever, see MODULES.md.
  • AI Agent Context & SDK Reference Guide: For feeding AI assistants (ChatGPT, Claude, Gemini, Cursor, Antigravity) with precise SDK specs, schemas, and rules, see AI_README.md and AGENTS.md.

License

MIT License.

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

mzero_rag-0.1.0.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

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

mzero_rag-0.1.0-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

Details for the file mzero_rag-0.1.0.tar.gz.

File metadata

  • Download URL: mzero_rag-0.1.0.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mzero_rag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ced5e6b0a816fef0e025b381a42e3ef30ae8d902cc41bdf78a41b9cfc42a93c2
MD5 62cd251d2b31250af2a15cdfbd7b60e6
BLAKE2b-256 580279cdc27eaa66c4f5c93ff06d5c3c6f805853cf7aa70d97ab1b287e8d1d3a

See more details on using hashes here.

File details

Details for the file mzero_rag-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mzero_rag-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mzero_rag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1668e941a95e40f6b4a523cec7b11d72c4330e1bda8afe522b94d89043e3f6f
MD5 4dcf72eb708f99d2adf366c5e83411f8
BLAKE2b-256 1d1b76ffbd497e41e2589d18ca9445939bfec0a1a0aa582e48e7068ccea6bad5

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