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/YOURUSERNAME/ragkitpy.git
cd ragkitpy
pip install -e ".[dev]"
pytest tests/ -v

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


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

Built by Your Name as an open-source contribution to the GenAI community.

โญ Star this repo if it helped you!


---

Also write your `LICENSE` file (MIT):

MIT License

Copyright (c) 2025 Your Name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.0.tar.gz (13.1 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.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragkitpy-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 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.0.tar.gz
Algorithm Hash digest
SHA256 af08bfdb98132fbc210a058b705f2fc759c40e24770f936a0b9094a8f8c37b38
MD5 33da74363205adcebf9836521d280b3e
BLAKE2b-256 6f64bbf8d85c24fddd7565b729b026951dfd2bebaf50d5028548c99921a3395b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragkitpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02ae4a2d0397b71a4f9faf5e74e3d2ee76be7e72f0be647cfeb185e387f9fddf
MD5 5b2e88396ba62639d04aa2d0d3b6c624
BLAKE2b-256 925c06c556ffb5f8139ad146cf7bd7abba4691773bd1ff15c7712a77e18f2f0c

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