Skip to main content

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?"))

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?"))

Limitations (Intentional)

  • Linear search (no ANN index)
  • Not optimized for millions of vectors
  • Retrieval only — no built-in LLM generation
  • Minimalistic by design

Contributing

Pull requests welcome.
If you use small-rag, share feedback via issues.


License

MIT License.

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

small_rag-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

small_rag-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file small_rag-0.1.2.tar.gz.

File metadata

  • Download URL: small_rag-0.1.2.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

Hashes for small_rag-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9b35215c1982655611b8177a53dbda57ae148df7378fd76d4ffc9301eee59225
MD5 81ff50984ec7fe2fc7809879a656a7ab
BLAKE2b-256 6dec0cd9ef18763985449a780b9662f51c4704ff9c5a79ed5811dc23dd5bdfd7

See more details on using hashes here.

File details

Details for the file small_rag-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: small_rag-0.1.2-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

Hashes for small_rag-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 18ec660bdfa9c402ad504a17e92d1aa50bb8f0470d564f595b3a670fb9829616
MD5 c80043f8dd5179eb769220af9a8a0ab2
BLAKE2b-256 421d41faf88e51ccad51613fd95d87fd36f7b77ce24ba5ee3a5d9a65b921f7aa

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