A lightweight RAG pipeline toolkit powered by HuggingFace
Project description
ragkitpy ๐ค
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af08bfdb98132fbc210a058b705f2fc759c40e24770f936a0b9094a8f8c37b38
|
|
| MD5 |
33da74363205adcebf9836521d280b3e
|
|
| BLAKE2b-256 |
6f64bbf8d85c24fddd7565b729b026951dfd2bebaf50d5028548c99921a3395b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02ae4a2d0397b71a4f9faf5e74e3d2ee76be7e72f0be647cfeb185e387f9fddf
|
|
| MD5 |
5b2e88396ba62639d04aa2d0d3b6c624
|
|
| BLAKE2b-256 |
925c06c556ffb5f8139ad146cf7bd7abba4691773bd1ff15c7712a77e18f2f0c
|