Skip to main content

A lightweight RAG pipeline toolkit powered by HuggingFace

Project description

ragkitpy ๐Ÿค—

PyPI version Python 3.8+ License: MIT

A lightweight, beginner-friendly RAG (Retrieval-Augmented Generation) pipeline toolkit powered by HuggingFace ๐Ÿค— โ€” no OpenAI key required.


๐Ÿš€ Why ragkitpy?

Setting up a RAG pipeline from scratch is painful. LangChain and LlamaIndex are powerful but heavy and complex for beginners. ragkitpy gives you a working RAG pipeline in 5 lines of code using only open-source models.

  • โœ… No OpenAI API key needed โ€” runs fully local with HuggingFace
  • โœ… Supports PDF and TXT files
  • โœ… Built on FAISS for fast vector search
  • โœ… Beginner-friendly API
  • โœ… Lightweight โ€” minimal dependencies

๐Ÿ“ฆ Installation

pip install ragkitpy

โšก Quick Start

from ragkitpy import RAGPipeline

# Initialize
rag = RAGPipeline()

# Load your document (PDF or TXT)
rag.load_document("my_document.pdf")

# Query it
results = rag.query("What is this document about?")

for i, chunk in enumerate(results, 1):
    print(f"Result {i}: {chunk}")

That's it. 5 lines to a working RAG pipeline. ๐ŸŽฏ


๐Ÿง  How It Works

Your Document (PDF/TXT)
        โ†“
   [loader.py]  โ†’  Extract raw text
        โ†“
  [chunker.py]  โ†’  Split into overlapping chunks
        โ†“
  [embedder.py] โ†’  HuggingFace embeddings (all-MiniLM-L6-v2)
        โ†“
[vectorstore.py]โ†’  Store in FAISS index
        โ†“
   Your Query   โ†’  Embed query โ†’ Search FAISS โ†’ Return top-k chunks

๐Ÿ“– Full API Reference

RAGPipeline

from ragkitpy import RAGPipeline

rag = RAGPipeline(
    model_name="all-MiniLM-L6-v2",  # Any SentenceTransformer model
    chunk_size=500,                   # Characters per chunk
    overlap=50                        # Overlap between chunks
)
Method Description
rag.load_document(path) Load a PDF or TXT file
rag.query(question, top_k=3) Get top-k relevant chunks
rag.query_with_scores(question, top_k=3) Get chunks with similarity scores
rag.is_ready Check if document is loaded
rag.source Path of loaded document

Use a different HuggingFace model

# Larger model, better quality
rag = RAGPipeline(model_name="all-mpnet-base-v2")

Get similarity scores

results = rag.query_with_scores("What is machine learning?", top_k=3)
for chunk, score in results:
    print(f"Score: {score:.4f} | {chunk[:100]}")

Use individual modules

from ragkitpy import load_file, chunk_text, HFEmbedder, VectorStore

# Use just the loader
text = load_file("document.pdf")

# Use just the chunker
chunks = chunk_text(text, chunk_size=300, overlap=30)

# Use sentence chunker instead
from ragkitpy.chunker import chunk_by_sentences
chunks = chunk_by_sentences(text, sentences_per_chunk=3)

๐Ÿ—‚๏ธ Project Structure

ragkitpy/
โ”œโ”€โ”€ ragkitpy/
โ”‚   โ”œโ”€โ”€ __init__.py       # Public API
โ”‚   โ”œโ”€โ”€ loader.py         # PDF & TXT file loading
โ”‚   โ”œโ”€โ”€ chunker.py        # Text chunking strategies
โ”‚   โ”œโ”€โ”€ embedder.py       # HuggingFace embeddings wrapper
โ”‚   โ”œโ”€โ”€ vectorstore.py    # FAISS vector store
โ”‚   โ””โ”€โ”€ pipeline.py       # End-to-end RAG pipeline
โ”œโ”€โ”€ tests/                # 24 unit tests
โ”œโ”€โ”€ examples/             # Working examples
โ””โ”€โ”€ pyproject.toml

๐Ÿ”ง Dependencies

Package Purpose
sentence-transformers HuggingFace text embeddings
faiss-cpu Vector similarity search
pypdf PDF text extraction
numpy Array operations

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md first.

git clone https://github.com/SRINATH-GITHU/ragkitpy.git
cd ragkitpy
pip install -e ".[dev]"
pytest tests/ -v

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


๐Ÿ‘จโ€๐Ÿ’ป Author

Built by Srinath Dhumnor as an open-source contribution to the GenAI community.

โญ Star this repo if it helped you!


---

Built by Srinath Dhumnoor as an open-source contribution to the GenAI community.

If this project helped you build something cool, โญ star the repo โ€” it really helps others discover it!

Questions, ideas or feedback? Feel free to open an issue. ๐Ÿš€

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

ragkitpy-0.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

ragkitpy-0.1.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file ragkitpy-0.1.1.tar.gz.

File metadata

  • Download URL: ragkitpy-0.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for ragkitpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 743ca2ce06781f1dde1f1b2aeab4cfcfe40184884d3632c55623a2a6d6a47a3d
MD5 bbca30dbcc63838be8d239a7168afbf8
BLAKE2b-256 9f325c7b8b4796b64a817103fa9b23a5e318ae110586c0c001f0871fb683dffa

See more details on using hashes here.

File details

Details for the file ragkitpy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ragkitpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for ragkitpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 706f74d6f6560736420da9fd9b5b9ebf065ea75eb39571d43ba20740da3cff1e
MD5 0b2b7ec3600e1920b90bd2ba43ca1751
BLAKE2b-256 afc3046826395979c50649da839c1305d7d0175234c215fcc01914e1dfa0ec2a

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