A lightweight Python framework for building retrieval-augmented generation applications with clean architecture, strong typing, and minimal dependencies.
The project is intentionally focused. It does not try to be another LangChain clone; it provides a small set of composable primitives that are easy to read, test, and extend.
- TXT and Markdown loading in the core package
- optional PDF, DOCX, and OCR image loading
- deterministic chunking
- local hashing and n-gram hashing embeddings
- in-memory and SQLite vector stores
- exact and operator-based metadata filtering
- optional lexical reranking
- prompt construction
- pluggable LLM interface
- callable, OpenAI, and Anthropic LLM adapters
- streaming responses
- source citations
- conversation history
- small CLI for local inspection, chunking, and retrieval
Core install:
uv add python-rag-frameworkDevelopment install:
uv sync --extra devOptional integrations:
uv add "python-rag-framework[pdf]"
uv add "python-rag-framework[docx]"
uv add "python-rag-framework[ocr]"
uv add "python-rag-framework[openai]"
uv add "python-rag-framework[anthropic]"from rag import RAG
rag = RAG()
rag.add_text(
"In Korean, 은/는 are topic particles and often introduce contrast.",
source="note",
)
results = rag.retrieve("What do topic particles mark?", limit=2)
for result in results:
print(result.score)
print(result.chunk.text)Use a callable for answer generation:
from collections.abc import Sequence
from rag import CallableLLM, Message, RAG
def generate(prompt: str, history: Sequence[Message]) -> str:
return call_your_model(prompt, history)
rag = RAG(llm=CallableLLM(generate))
rag.add_markdown("notes.md")
answer = rag.ask("Explain the difference between 은/는 and 이/가.")
print(answer.text)rag inspect examples/sample_notes.md
rag chunk examples/sample_notes.md --json
rag search examples/sample_notes.md "topic particles"The CLI is intentionally local-only. It is useful for inspecting loaders, chunking behavior, and retrieval results without configuring an LLM provider.
Runnable examples live in examples/:
local_search.pycallable_llm.pypersistent_sqlite_index.pyopenai_adapter.py
uv run ruff check .
uv run mypy
uv run pytest
uv buildThe repository also includes GitHub Actions for linting, type checking, tests, package builds, docs builds, and optional PyPI publishing.
The framework is feature-complete for its current scope and suitable as a portfolio-quality open-source Python library. Future work should focus on release hardening, examples, benchmarks, and real-world feedback rather than feature sprawl.