Skip to main content

RAG in 3 lines of code — load documents, ask questions, get answers

Project description

easy-rag

RAG in 3 lines of code. Zero dependencies. Load documents, ask questions, get answers.

from easy_rag import EasyRAG

rag = EasyRAG("./my_docs/")
answer = rag.ask("What does the contract say about termination?")
print(answer)

That's it. No API keys, no vector databases, no configuration.

Why easy-rag?

easy-rag LangChain LlamaIndex
Lines to get started 3 50-100+ 30-80+
Dependencies 0 50+ 40+
Setup time Instant Minutes Minutes
Requires API key No Usually Usually
Install size < 50 KB 200+ MB 150+ MB

Installation

pip install easy-rag

Optional extras

pip install easy-rag[pdf]      # PDF support (pdfplumber)
pip install easy-rag[openai]   # OpenAI embeddings
pip install easy-rag[local]    # Local embeddings (sentence-transformers)
pip install easy-rag[all]      # Everything

Quick Start

Search your documents

from easy_rag import EasyRAG

# Load an entire folder of documents
rag = EasyRAG("./contracts/")

# Ask a question
result = rag.ask("What is the payment schedule?")
print(result)
# [contract_v2.pdf | Score: 0.87]
# Payment is due within 30 days of invoice date...

Add documents on the fly

rag = EasyRAG()

# Add individual files
rag.add_document("report.md")
rag.add_document("notes.txt")

# Add raw text directly
rag.add_text("The meeting is scheduled for Friday at 3pm.", source="email")

# Search
results = rag.search("meeting schedule", top_k=3)
for r in results:
    print(f"[{r.score:.2f}] {r.chunk.text[:100]}")

CLI usage

# Search documents from the command line
easy-rag ./docs/ "What are the key findings?"

# Show index statistics
easy-rag ./docs/ --stats

# Customize chunk size
easy-rag ./docs/ "query" --chunk-size 1000 --top-k 5

Check index stats

rag = EasyRAG("./docs/")
print(rag.stats())
# {
#   'num_chunks': 142,
#   'num_sources': 12,
#   'num_unique_terms': 3847,
#   'chunk_size': 500,
#   'overlap': 50
# }

Supported File Formats

Format Support Notes
.txt Built-in Plain text files
.md Built-in Markdown files
.json Built-in Extracts all string values
.pdf Optional Requires pip install easy-rag[pdf]

How It Works

  1. Load — Reads all supported files from a directory
  2. Chunk — Splits text into overlapping pieces at smart boundaries (paragraphs, sentences)
  3. Index — Builds a TF-IDF index using only Python's standard library
  4. Search — Finds the most relevant chunks using cosine similarity
  5. Return — Gives you the best matching text with source and score

No neural networks, no API calls, no GPU needed. Just fast, reliable text search.

API Reference

EasyRAG(path=None, chunk_size=500, overlap=50)

Create a new RAG index.

  • path — Directory or file to load (optional, can add later)
  • chunk_size — Max characters per chunk (default: 500)
  • overlap — Character overlap between chunks (default: 50)

.ask(question, top_k=3) -> RAGResult

Ask a question and get a formatted answer with sources.

.search(query, top_k=5) -> List[SearchResult]

Search for relevant chunks (raw results).

.add_document(filepath) -> int

Add a single file to the index. Returns number of chunks created.

.add_text(text, source="inline") -> int

Add raw text to the index. Returns number of chunks created.

.stats() -> dict

Get index statistics.

License

MIT

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

easyrag_kit-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

easyrag_kit-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easyrag_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for easyrag_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9fc78aba8989ae3f06d3d93d1ed288bc975092332622cab0ac73aec0330ea73a
MD5 aeaa32e64ab0cf83e1ee54840c5cf059
BLAKE2b-256 60f1bf657c953bd91fe57a53948a2305afe6e5fefb39cf5b5cb1d533e1904f96

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easyrag_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for easyrag_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfccd338deb8cebc01a4cd468e90e13ba329f863d229f2db855eb0295c68af4c
MD5 b8e1a86545fa15e2b33124f711570d6d
BLAKE2b-256 b7b560dea91b51478b6d5cbadcba272b0c0c92c2e3a99d6f9aa494ae6b574e3e

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