tiny-rag
Ask Your Texts, Images and Sounds
Ask a library of texts, images and sounds: every model is mine and trained from scratch, except the writer.
- Text, image or sound as the query
- Demo: 300 texts, 48 images, 32 clips
- Benchmarks pending family training
Built withPyTorch
Gradio
NumPy
Hugging Face Datasets
pytest
Code is in a private repository for now.

Overview
tiny-rag answers questions over your own files: texts, PDFs, images and sounds. You can ask with a text, an image or a sound, and each query searches its own index with its own model.
Every model in the loop comes from my tiny-* family: tiny-bert as the encoder, tiny-embedder for the embeddings, tiny-nn-search for the indexes, tiny-reranker for reranking. The writer is Qwen2.5-0.5B-Instruct, run inside tiny-llm. TinyRAG.from_checkpoints() loads the family checkpoints from a shared model store.
It is the from-scratch counterpart of Juridia, my legal RAG built on off-the-shelf tools.
The question
Can I build a full RAG system from my own small from-scratch models, and ask it with a text, an image or a sound?
Key features
- Queries by text, image or sound, each searched with its own model
- Three indexes: HNSW + BM25 for text, HNSW for images and audio
- Keyword, dense or hybrid search (RRF), with an optional reranker
- Answers with numbered citations, plus the sources, the prompt and timings per stage
- Gradio app, a Python API and CLI scripts to build an index and ask it
- Baseline fallbacks so it runs before the family models are trained
How it works
Ingest once
Files are chunked and embedded per modality by tiny-embedder, then stored in three tiny-nn-search indexes. Images and sounds take their caption from a sibling .txt file.
Search and rerank
The query is embedded with its own model, searched in its index by keyword, dense or hybrid (RRF), and the top-k is reranked by tiny-reranker.
Answer with sources
Qwen2.5-0.5B-Instruct, run by tiny-llm, writes the answer from the numbered sources and returns it with the cited sources.
Examples



Tech stack
The family models and Qwen2.5 inference through tiny-llm
Local app with Library, Ask and Search tabs
Embeddings, scores and saved indexes
SQuAD, Flickr30k and Clotho for the demo and the benchmarks
Tests for the chunker, RRF, citations, EM/F1 and ask() end to end
What I learned
- With a prompt that asked for citations, Qwen2.5-0.5B often answered only "[1]". Asking for a full answer in sentences fixed it.
- Baseline fallbacks (word hashing, colour features, log-mel statistics) let the whole system run before the family models finish training.
Limitations
- tiny-bert, tiny-embedder and tiny-reranker are still training, so the SQuAD, Flickr30k and Clotho benchmarks have no numbers yet.
- The 0.5B model rarely writes citations, and the family repos are private, so installing needs local clones or an SSH key.
Related projects

tiny-embedder — Text, Image and Audio Embeddings from Scratch
Code is in a private repository for now.
Three small embedding models built from scratch in PyTorch: text, images and sounds each become a 256-d vector, so similar things end up close. Every text tower starts from my tiny-bert.
Built with:
PyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript

tiny-reranker — Text, Image and Audio Rerankers from Scratch
Code is in a private repository for now.
Three small cross-encoders that reorder the top results of a first search stage. One reads a query with a passage, one a caption with a picture, one a caption with a sound. All three are built from scratch in PyTorch on top of tiny-bert.
Built with:
PyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript

Tiny NN Search — Vector and Keyword Search from Scratch
Code is in a private repository for now.
A small vector and keyword search engine I wrote from scratch in NumPy: exact search, IVF, PQ, IVF-PQ, HNSW, LSH, BM25 and hybrid fusion, with one engine each for text, images and audio. It is the retrieval engine of tiny-rag.
Built with:
NumPy
Gradio
PyTorchMatplotlib
pytest

Tiny BERT — A Small Encoder and Its BPE Tokenizer, From Scratch
Code is in a private repository for now.
A 9M-parameter BERT-style encoder and its byte-level BPE tokenizer, written and pre-trained from scratch in PyTorch, with no Hugging Face transformers. It is the encoder the rest of my tiny family starts from.
Built with:
PyTorch
Hugging Face Datasets
NumPy
scikit-learnMatplotlib
pytest

Tiny LLM — A Small LLM Built From Scratch
A small LLM written layer by layer in PyTorch. The same code trains from zero or loads GPT-2, Llama (SmolLM2), Qwen2.5 and Pythia with outputs identical to Hugging Face, fine-tunes them with LoRA, and chats in a Streamlit app.
Built with:
PyTorch
Hugging Face TransformersLoRA
Streamlit
Kaggle

Juridia — Multilingual Legal RAG
Code is private (company / client work)
A production retrieval and question-answering system for more than 100,000 Arabic and French legal documents, combining semantic, keyword, and metadata search.
Built with:
FastAPI
PostgreSQLQdrantLlamaIndex
React