Skip to main content

License mloda Python

rag-integration

RAG integration plugin for mloda. Composes modular FeatureGroups into text and image processing pipelines with PII redaction, chunking, deduplication, embedding, FAISS vector search, retrieval, evaluation, and LLM response generation.

See the demo notebook for an interactive walkthrough or the CLI for command-line usage.

Project Structure

rag_integration/
  feature_groups/
    rag_pipeline/       # Text: source, PII, chunk, dedup, embed, index, retrieve, LLM
    image_pipeline/     # Image: source, PII, preprocess, dedup, embed
    datasets/           # BEIR (SciFact) and image (Flickr30k) loaders
    evaluation/         # Retrieval metrics (precision, recall, NDCG, MAP)
cli/                    # Command-line demo tools (see cli/README.md)
tests/                  # Unit and integration tests
docs/                   # Detailed guides

Quick Start

1. Define your documents

Documents are loaded through a DataCreator-based FeatureGroup. The simplest option is DictDocumentSource, which loads from a Python list:

documents = [
    {"doc_id": "1", "text": "Contact support@example.com for help."},
    {"doc_id": "2", "text": "Our office is at 123 Main St."},
]

2. Build the pipeline

Each pipeline stage is expressed as a feature name. Stages chain with __:

docs                                    # raw documents
docs__pii_redacted                      # PII removed
docs__pii_redacted__chunked             # text split into chunks
docs__pii_redacted__chunked__deduped    # duplicates removed
docs__pii_redacted__chunked__deduped__embedded  # vector embeddings

3. Run with mlodaAPI

from mloda.user import mlodaAPI, PluginCollector, Feature, Options
from mloda_plugins.compute_framework.base_implementations.python_dict.python_dict_framework import (
    PythonDictFramework,
)

from rag_integration.feature_groups.rag_pipeline import (
    DictDocumentSource,
    RegexPIIRedactor,
    FixedSizeChunker,
    ExactHashDeduplicator,
    MockEmbedder,
)

providers = {
    DictDocumentSource,
    RegexPIIRedactor,
    FixedSizeChunker,
    ExactHashDeduplicator,
    MockEmbedder,
}

# Group options forward to every upstream stage, down to `docs`; context options do not.
feature = Feature(
    "docs__pii_redacted__chunked__deduped__embedded",
    options=Options(
        group={
            "documents": [
                {"doc_id": "1", "text": "Contact support@example.com for help."},
                {"doc_id": "2", "text": "Our office is at 123 Main St."},
            ]
        }
    ),
)

results = mlodaAPI.run_all(
    features=[feature],
    compute_frameworks=[PythonDictFramework],
    plugin_collector=PluginCollector.enabled_feature_groups(providers),
)

4. Configure pipeline stages

With several implementations per stage enabled, group options select one each and tune parameters. To pick another value, add its class to providers:

from rag_integration.feature_groups.rag_pipeline import (
    HashEmbedder,
    NormalizedDeduplicator,
    SentenceChunker,
    SimplePIIRedactor,
)

providers |= {SimplePIIRedactor, SentenceChunker, NormalizedDeduplicator, HashEmbedder}

feature = Feature(
    "docs__pii_redacted__chunked__deduped__embedded",
    options=Options(
        group={
            "documents": documents,
            "redaction_method": "regex",  # or "simple", "pattern", "presidio"
            "chunking_method": "sentence",  # or "fixed_size", "paragraph", "semantic"
            "deduplication_method": "exact_hash",  # or "normalized", "ngram"
            "embedding_method": "hash",  # or "mock", "tfidf", "sentence_transformer"
            "chunk_size": 512,
            "chunk_overlap": 128,
        }
    ),
)

results = mlodaAPI.run_all(
    features=[feature],
    compute_frameworks=[PythonDictFramework],
    plugin_collector=PluginCollector.enabled_feature_groups(providers),
)

Available Components

Text Pipeline

Stage Implementations
Document Source DictDocumentSource, FileDocumentSource
PII Redaction RegexPIIRedactor, SimplePIIRedactor, PatternPIIRedactor, PresidioPIIRedactor
Chunking FixedSizeChunker, SentenceChunker, ParagraphChunker, SemanticChunker
Deduplication ExactHashDeduplicator, NormalizedDeduplicator, NGramDeduplicator
Embedding MockEmbedder, HashEmbedder, TfidfEmbedder, SentenceTransformerEmbedder
Vector Store FaissFlatIndexer, FaissIVFIndexer, FaissHNSWIndexer
Retrieval FaissRetriever
LLM Response ClaudeCliResponse

Image Pipeline

Stage Implementations
Image Source DictImageSource, FileImageSource
PII Redaction BlurPIIRedactor, PixelPIIRedactor, SolidFillPIIRedactor
Preprocessing ResizePreprocessor, NormalizePreprocessor, ThumbnailPreprocessor
Deduplication ExactHashImageDeduplicator, PerceptualHashImageDeduplicator, DifferenceHashImageDeduplicator
Embedding MockImageEmbedder, HashImageEmbedder, CLIPImageEmbedder

Connector families

Alongside the build-your-own stage pipeline, the connectors/ package wraps whole external open-source RAG tools under one mloda surface, organized into six families by query-contract shape (retrieve, rerank, generate, graph_rag, structured, orchestrator). You swap backends by changing options, not by rewriting a pipeline.

The two layers share one seam: the FAISS retrieval stage is the native dense path of the retrieve family (retrieve_backend="faiss"), and a stage and its connector counterpart emit the same passage / answer row shape under the same canonical feature name, so migrating between them is an option swap. See "Relationship to the stage pipeline" in docs/rag-connector-base-classes.md.

See feature_groups/connectors/README.md for the family map (per-family contract, backends, no-Docker concrete, and pedigree), runnable examples, and links to the contract suites. The design rationale is in docs/rag-connector-base-classes.md.

from mloda.user import mlodaAPI, Feature, Options, PluginCollector
from mloda_plugins.compute_framework.base_implementations.python_dict.python_dict_framework import (
    PythonDictFramework,
)
from rag_integration.feature_groups.connectors.retrieve import Bm25sRetriever

feature = Feature(
    "retrieved_passages",
    options=Options(
        context={
            "retrieve_backend": "bm25s",
            "query_text": "cat pet",
            "corpus": [
                {"doc_id": "d1", "text": "A cat is an independent and curious pet."},
                {"doc_id": "d2", "text": "Cars need regular engine oil and maintenance."},
            ],
            "top_k": 3,
        }
    ),
)
results = mlodaAPI.run_all(
    [feature],
    compute_frameworks=[PythonDictFramework],
    plugin_collector=PluginCollector.enabled_feature_groups({Bm25sRetriever}),
)

Install a family's backend with uv sync --extra connectors (or rerank / graph / structured / orchestrator).

Swapping one backend for another is an option change, not a pipeline rewrite. python -m cli.swap_demo runs that swap within a family (retrieve_backend="bm25s" -> "tfidf") and across families (retrieve vs orchestrator over the same inputs); the contract is written up under "Swapping backends" in docs/rag-connector-base-classes.md.

Installation

Clone the repository and install with uv:

git clone https://github.com/mloda-ai/rag_integration.git
cd rag_integration
uv venv
source .venv/bin/activate
uv sync --all-extras

To install only specific extras, use uv sync --extra <name>:

Extra What it adds
faiss FAISS vector indexing (faiss-cpu)
advanced Presidio, sentence-transformers, joblib, Pillow, FAISS
eval BEIR benchmark datasets, pandas, numpy
graph networkx graph-RAG backend (NetworkxGraphRag)
dev tox, pytest, ruff, mypy, bandit, mloda-testing

CLI

A command-line interface is available for running pipelines interactively. See cli/README.md for full usage.

python3 -m cli.rag_demo run --input cli/docs/ --pii regex --chunking sentence --embedding tfidf -v

Development Setup

uv venv
source .venv/bin/activate
uv sync --all-extras

Run all checks (pytest, ruff, mypy, bandit):

tox

Run individual checks

pytest
ruff format --check --line-length 120 .
ruff check .
mypy --strict --ignore-missing-imports .
bandit -c pyproject.toml -r -q .

Metadata

Release files for rag-integration 0.4.4

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

Source distribution (sdist)

Source distribution for rag-integration 0.4.4
File Size Uploaded Provenance Actions
rag_integration-0.4.4.tar.gz 105.4 kB Without provenance Details for rag_integration-0.4.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rag-integration 0.4.4
File Interpreter ABI Platform Actions
rag_integration-0.4.4-py3-none-any.whl Python 3 none any Details for rag_integration-0.4.4-py3-none-any.whl

Total release size: 287.4 kB

Release files / rag_integration-0.4.4.tar.gz

Download URL rag_integration-0.4.4.tar.gz
Size 105.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f9153154501778cfdf1f053afdea3820510911145fcf6911518336f2356e9322
BLAKE2b-256 checksum
How to use checksums
41eceeb3d0e6327c3636ec877acbf6b63d316a667835fbe67ed55d6419de46f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / rag_integration-0.4.4-py3-none-any.whl

Download URL rag_integration-0.4.4-py3-none-any.whl
Size 182.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
909fbdb2fc50a1683bc5d6c1ce75f6fc4ce7dcfef38e66fc8bbd790e7476cd33
BLAKE2b-256 checksum
How to use checksums
5998a75bf67dee489da2cd13a9ab422a25ff991614b82dc1ae7ea4db8a4349f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for rag-integration 0.4.4

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