A minimal, dependency-free Retrieval-Augmented Generation (RAG) engine using SQLite as a local vector store.
Project description
small-rag
A lightweight, dependency-free Retrieval-Augmented Generation (RAG) engine for Python.
small-rag is a minimal, easy-to-understand vector store + RAG toolkit.
It is designed for developers who want a simple, transparent, hackable RAG library that can be fully understood in minutes.
No FAISS, no Qdrant, no heavy dependencies — just pure Python + SQLite.
Features
- Pure Python implementation (no external dependencies)
- SQLite-backed vector store
- Pluggable embedding function (OpenAI, HF models, local LLMs, custom functions)
- Text preprocessing + chunking
- Metadata filtering
- Import/export database to JSON
- Command-line interface (
smallrag-cli) - Easy to read, extend, and embed inside other projects
Installation
pip install small-rag
Verify:
python -m smallrag --help
Quick Start (Python)
1. Create a RAG instance
from smallrag import SmallRAG
rag = SmallRAG("my.db")
2. Set an embedder (required)
rag.set_embedder(lambda t: [float(ord(c) % 255) for c in t[:64]])
3. Add documents
rag.add_document("Python is a programming language created by Guido van Rossum.")
rag.add_document("Retrieval augmented generation improves LLM accuracy.")
4. Query
res = rag.query("What is RAG?")
print(res)
Example output:
[
{
"id": 2,
"text": "retrieval augmented generation improves llm accuracy.",
"metadata": {},
"score": 0.87
}
]
Realistic Example (HuggingFace Embeddings)
from smallrag import SmallRAG
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")
rag = SmallRAG("docs.db")
rag.set_embedder(lambda t: model.encode(t).tolist())
rag.add_document("Paris is the capital of France.", metadata={"topic": "geography"})
rag.add_document("The Eiffel Tower is in Paris.", metadata={"topic": "landmark"})
print(rag.query("Where is the Eiffel Tower?"))
OR
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
def st_embed(text: str):
return model.encode(text).tolist()
rag = SmallRAG('data/rag.db')
rag.set_embedder(st_embed)
rag.add_document('Example doc about kafka and streaming')
print(rag.query('kafka streaming'))
# Export/Import
rag.export_db('backup.json')
rag.import_db('backup.json')
CLI Usage
Add a document
smallrag-cli --db my.db add "Python is easy to learn"
With metadata:
smallrag-cli --db my.db add "Paris is beautiful" --meta '{"country": "France"}'
Query
smallrag-cli --db my.db query "What is Python?"
Export DB
smallrag-cli --db my.db export dump.json
Import DB
smallrag-cli --db my.db import dump.json
Filtering by Metadata
rag.query("Paris", filter={"country": "France"})
Chunking Behavior
Default:
- chunk size: 512
- overlap: 64
rag.add_document(big_text, chunk=True, chunk_size=256)
Using OpenAI Embeddings
from smallrag import SmallRAG
from openai import OpenAI
client = OpenAI()
rag = SmallRAG("openai.db")
def openai_embed(t: str):
emb = client.embeddings.create(
model="text-embedding-3-small",
input=t
)
return emb.data[0].embedding
rag.set_embedder(openai_embed)
rag.add_document("The Amazon rainforest is the largest rainforest on Earth.")
print(rag.query("What is the largest rainforest?"))
Contributing
Pull requests welcome.
If you use small-rag, share feedback via issues.
License
MIT License.
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 small_rag-0.1.3.tar.gz.
File metadata
- Download URL: small_rag-0.1.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0b5662faf28a3285d62b018cdcf9af531286ef72eb12518dfc75bf907f964f3
|
|
| MD5 |
867fca7f56dd24479f2f8fad09ae6392
|
|
| BLAKE2b-256 |
6428852634d984027fc38d8d69eabd537fee5834e48cf1a486c85c039b416458
|
File details
Details for the file small_rag-0.1.3-py3-none-any.whl.
File metadata
- Download URL: small_rag-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9ddd2c3f01ed859ab48c279d0241822959e4df6a4c92382c330c8b643258f42
|
|
| MD5 |
c428ee2ab0762acad1d41184d5db7142
|
|
| BLAKE2b-256 |
979a6479bfc7eb7e8dca53a313f25f0282700fa05c0bd5c7464dab7ad017b9e1
|