Catalog PyPI
Back to packageRELEASE DETAILS

0.2.2

PyPI

advanced-rag-framework

Advanced Retrieval Framework — dependency-free retrieval pipeline toolkit

Published6 Apr 2026
Direct dependencies13
Transitive dependenciesNot calculated

README

Version 0.2.2 documentation

ARF — Advanced Retrieval Framework

CI PyPI Python 3.10+ License: MIT

A zero-dependency retrieval pipeline toolkit. Plug in your own vector search, embedding model, LLM, ML model, and database — ARF provides the routing algorithms, feature engineering, rephrase-graph caching, and score blending.

pip install advanced-rag-framework

What ARF Does

Most RAG pipelines send every candidate to an expensive LLM for reranking. ARF eliminates this waste with a multi-stage filtering pipeline called R-Flow:

Query
  → Cache graph walk (free — returns instantly if seen before)
  → Vector search (your provider)
  → Threshold + gap filter (free — drops obvious junk)
  → MLP triage (free, <5ms — accept/reject/uncertain)
  → LLM verification ($$$ — only for the ~20% uncertain candidates)
  → Answer with summaries

Each stage filters candidates so the next stage does less work. Only the uncertain ~20% ever reach the LLM.

Quick Start

from arf import Pipeline, DocumentConfig, Triage

pipeline = Pipeline(
    doc_config=DocumentConfig(title_field="title", text_fields=["text"]),
    triage=Triage(min_score=0.65, accept_threshold=0.85, verify_threshold=0.70),
    search_fn=my_search,       # (embedding, top_k) → [(dict, float)]
    embed_fn=my_embed,         # (text) → [float]
)

results = pipeline.run("how does caching work?")

That's it. Two required functions. Everything else is optional.

Full Pipeline

from arf import Pipeline, DocumentConfig, Triage
from arf.trainer import load_reranker

pipeline = Pipeline(
    doc_config=DocumentConfig(
        title_field="title",
        text_fields=["text", "summary"],
        children_fields=["sections", "clauses"],
        hierarchy=["title", "chapter", "section"],
    ),
    triage=Triage(
        min_score=0.65,
        accept_threshold=0.85,
        verify_threshold=0.70,
        gap=0.20,
    ),

    # Required
    search_fn=my_search,           # any vector DB
    embed_fn=my_embed,             # any embedding model

    # Scoring (optional)
    predict_fn=load_reranker("model.joblib"),  # trained MLP
    llm_fn=my_llm_verify,         # any LLM

    # Cache (optional)
    cache_lookup=my_cache_get,     # any cache backend
    cache_store=my_cache_set,

    # Preprocessing (optional)
    preprocess_fn=my_clean,        # translate, normalize, etc.
    moderate_fn=my_moderate,       # content safety
    rephrase_fn=my_rephrase,       # retry with rephrased query

    # Hierarchy (optional)
    resolve_fn=my_get_parent,      # walk up document tree
    summarize_fn=my_summarize,     # generate answer
)

results = pipeline.run("what is due process?", top_k=5)
# [{"document": Document, "score": 0.94, "context": [...], "summary": "..."}, ...]

Components

ARF is 6 independent modules. Use them together or individually.

Document — DB-agnostic data model

from arf import Document, DocumentConfig

config = DocumentConfig(
    title_field="name",
    text_fields=["body", "content"],
    children_fields=["subsections"],
    hierarchy=["category", "name"],
)

doc = Document.from_dict({"name": "Guide", "body": "...", "category": "Medical"}, config)
# doc.depth = 2, doc.path = "Medical / Guide"

Works with any database. MongoDB, PostgreSQL, DynamoDB, Pinecone, FAISS — just map your fields.

Features — 15-feature extraction

from arf import FeatureExtractor

extractor = FeatureExtractor(config)
features = extractor.extract_features(query="...", document={...}, semantic_score=0.85)
vector = extractor.to_vector(features)  # [0.85, 4.2, 0, 0, ...]
FeatureDescription
semantic_scoreRaw cosine similarity from vector search
bm25_scoreTerm-frequency relevance approximation
alias_matchWhether query matches a document alias
keyword_matchWhether query matches via keyword pattern
domain_typeEncoded domain identifier
document_lengthLog-scaled character count
query_lengthQuery character count
section_depthDepth in document hierarchy
embedding_cosine_similarityDirect embedding cosine similarity
match_type0=none, 1=partial, 2=exact
score_gap_from_topGap from highest-scored document
query_term_coverageFraction of query terms in document
title_similarityJaccard similarity between query and title
has_nested_contentWhether document has children
bias_adjustmentConfigurable per-document bias

Triage — threshold + gap + zone routing

from arf import Triage

triage = Triage(min_score=0.65, accept_threshold=0.85, verify_threshold=0.70, gap=0.20)
result = triage.classify(candidates)
# result.accepted, result.needs_review, result.rejected

QueryGraph — rephrase chain walk

from arf import follow_rephrase_chain

result = follow_rephrase_chain("due process clause", lookup_fn=my_db_lookup, max_hops=3)
# result.hit, result.cached_results, result.path, result.loop_detected

Walks a directed graph of query→rephrase edges with loop detection and early exit on cache hit. Storage-agnostic — you provide the lookup_fn.

ScoreParser — LLM output parsing + multiplier blending

from arf import extract_score, multiplier, adjust_score

extract_score('{"score": 7}')           # → 7
extract_score("Score: 8")               # → 8
multiplier(8)                           # → 1.39
adjust_score(0.72, "Score: 8")          # → min(0.72 * 1.39, 1.0)

Parses messy LLM output (JSON, bare numbers, "Score: N" lines) into a 0-9 score, converts to a multiplier, and blends with the retrieval score.

Trainer — MLP training

from arf.trainer import train_reranker, load_reranker

# Train
metrics = train_reranker(X, y, architecture=(64, 32, 16), save_path="model.joblib")

# Load as a predict_fn for Pipeline
predict_fn = load_reranker("model.joblib")

Requires pip install advanced-rag-framework[ml] (numpy + scikit-learn).

Ingest — document ingestion helper

from arf import ingest_documents, DocumentConfig

result = ingest_documents(
    documents,
    config=DocumentConfig(title_field="title", text_fields=["text"]),
    embed_fn=my_embed,     # your embedding function
    store_fn=my_store,     # your DB write function
)
# result.processed, result.skipped, result.errors

Validates documents, computes hierarchy metadata (depth, path), generates embeddings for parent and children, and stores via your function.

Bring Your Own Everything

SlotWhat you provideExamples
search_fnVector searchFAISS, Pinecone, Weaviate, Qdrant, MongoDB Atlas, pgvector
embed_fnEmbeddingsOpenAI, Voyage AI, Cohere, sentence-transformers, Ollama
predict_fnML modelscikit-learn, XGBoost, PyTorch, any callable
llm_fnLLM verificationOpenAI, Anthropic, Ollama, Llama.cpp, any API
cache_lookup/storeCacheRedis, MongoDB, SQLite, in-memory dict
resolve_fnParent lookupAny database query
summarize_fnAnswer generationAny LLM
store_fn (ingest)Document storageAny database write

Installation

# Core (zero dependencies)
pip install advanced-rag-framework

# With MLP training support (numpy + scikit-learn)
pip install advanced-rag-framework[ml]

Sample Project

See sample-project/ for a complete working example using:

  • FAISS for vector search
  • Voyage AI for embeddings
  • OpenAI for LLM verification
  • A cooking recipe dataset (non-legal, 46 recipes from 15 cuisines)
python sample-project/ingest.py                          # Embed recipes into FAISS
python sample-project/train.py                           # Train MLP reranker
python sample-project/query.py "spicy noodle soup"       # Full pipeline query

R-Flow Pipeline

The core innovation — each stage filters candidates so the next stage does less work:

                    ┌──────────────────────┐
                    │   Vector Search      │
                    │  (your provider)     │
                    └──────────┬───────────┘
                               │ candidates with scores
                    ┌──────────▼───────────┐
                    │  Threshold + Gap     │
                    │  Filter (~60% cut)   │
                    └──────────┬───────────┘
                               │ survivors
                    ┌──────────▼───────────┐
                    │  Feature Extraction  │
                    │  (15 features)       │
                    └──────────┬───────────┘
                               │ feature vectors
                    ┌──────────▼───────────┐
                    │   MLP Reranker       │
                    │  (<5ms, $0.00)       │
                    └──────────┬───────────┘
                        ┌──────┼──────┐
                   p≥0.6│  0.4<p<0.6  │p≤0.4
                        │      │      │
                   Accept   ┌──▼──┐  Reject
                   (free)   │ LLM │  (free)
                            │(20%)│
                            └──┬──┘
                          Accept/Reject

Development

git clone https://github.com/jager47X/ARF.git
cd ARF
pip install -e ".[dev]"

# Run library tests
pytest tests/test_arf/ -v

# Lint
ruff check arf/ tests/test_arf/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

License

MIT License — see LICENSE for details.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 15

Native requirements
13 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
numpy
Environment
{
  "extras": "",
  "marker": "extra == \"ml\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
numpy>=1.24; extra == "ml"runtime
scikit-learn
Environment
{
  "extras": "",
  "marker": "extra == \"ml\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
scikit-learn>=1.3; extra == "ml"runtime
joblib
Environment
{
  "extras": "",
  "marker": "extra == \"ml\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
joblib>=1.3; extra == "ml"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.0; extra == "dev"runtime
pytest-cov
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest-cov>=4.0; extra == "dev"runtime
ruff
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
ruff>=0.4; extra == "dev"runtime
numpy
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
numpy>=1.24; extra == "dev"runtime
numpy
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
numpy>=1.24; extra == "full"runtime
openai
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
openai>=1.0; extra == "full"runtime
pymongo
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pymongo>=4.0; extra == "full"runtime
python-dotenv
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
python-dotenv>=1.0; extra == "full"runtime
tiktoken
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
tiktoken>=0.5; extra == "full"runtime
nltk
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
nltk>=3.8; extra == "full"runtime
pydantic
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pydantic>=2.0; extra == "full"runtime
voyageai
Environment
{
  "extras": "",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
voyageai>=0.3; extra == "full"runtime

Distribution files

2 collected
advanced_rag_framework-0.2.2-py3-none-any.whl

bdist_wheel · 135.17 KB · Python py3

Source file
advanced_rag_framework-0.2.2.tar.gz

sdist · 141.23 KB · Python source

Source file

Repository

PENDING
jager47x/arf

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:58 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:d01ef57ef8af1e87cfc82c6e074c95fca9fdc2de78b806b4e826257e9e688e62

Other collected versions

View all collected versions →