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 root 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,
FullCoverageRegexPIIRedactor, # lowers the classification only for full pii_types coverage
FixedSizeChunker,
ExactHashDeduplicator,
MockEmbedder,
)
providers = {
DictDocumentSource,
RegexPIIRedactor,
FullCoverageRegexPIIRedactor,
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 |
Data classification
The mloda-registry OTel, OpenLineage and audit extenders track a data classification level
(public < internal < confidential < restricted < pii) through the pipeline. Stages declare theirs
(mloda.data.classification):
- Text PII redactors are masking steps: the redacted feature is
confidential, whatever came in. Masking asserts that the configuredpii_typescover the data: detection is best effort, a narrowedpii_typesleaves other PII in place, and empty or unknown types raise. Apublicinput is raised toconfidentialtoo. Subclass and setREDACTED_CLASSIFICATION, ormasking = False, to change it. - Chunkers, deduplicators, embedders, image preprocessors and image redactors declare
public, meaning "adds no sensitivity": their outputs keep their inputs' level. Image redactors therefore never lower it. - Sources, retrievers, vector stores, LLM responses, evaluators and connectors declare nothing and get
the extender's
undeclaredlevel.
The level belongs to the feature, not the row: rows still carry their source's other columns (such as
text). To see effective levels, pass classification_undeclared=... to the extender and read
mloda.data.classification, not the mloda.declared.* copy.
Run statistics
With an mloda extender (for example the registry's OtelExtender, which exports them as
mloda.result.<key> span attributes), these stages publish counts, flags and metrics, never text or ids.
| Key | Published by |
|---|---|
rag.dedup.duplicates_found |
Text and image deduplicators: rows flagged as duplicates |
rag.embedding.artifact_reused |
Artifact-enabled text embedders: embeddings loaded from a saved artifact |
rag.eval.<metric> |
RetrievalEvaluator, FaissRetrievalEvaluator: recall@1/5/10 (only when measured), num_queries, num_corpus |
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 (Python 3.11+), 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 .
Related
- Getting Started Guide for a detailed walkthrough
- GitHub Workflows for CI/CD setup and required secrets
- mloda core library
- mloda-registry for plugin guides and community plugins
Metadata
Release files for rag-integration 0.5.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 |
|---|---|---|---|---|
| rag_integration-0.5.0.tar.gz | 110.2 kB | Without provenance | Details for rag_integration-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rag_integration-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for rag_integration-0.5.0-py3-none-any.whl |
Total release size: 298.0 kB
Release files / rag_integration-0.5.0.tar.gz
| Download URL | rag_integration-0.5.0.tar.gz |
|---|---|
| Size | 110.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a12f39a7a5db503d2e1ed25b04331606f6522e0af27fe33586e2738bfcad7e2
|
|
BLAKE2b-256 checksum How to use checksums |
c5d4b3142c7649d0906d263544ac965386347f20e6b0dd956ba685e0146180c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / rag_integration-0.5.0-py3-none-any.whl
| Download URL | rag_integration-0.5.0-py3-none-any.whl |
|---|---|
| Size | 187.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0ff9e7f5744e37d3549db97ef039ef01a4b72680f9547809b3ca8e2c30f78b4
|
|
BLAKE2b-256 checksum How to use checksums |
4ab27ce3325bf2cbaa619b3a8ea470cc797b39fd159735d9a4c61e680ab88906
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for rag-integration 0.5.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.