← all repositories
pguso/rag-from-scratch

Stop importing RAG, start writing it

A hands-on Node.js tutorial series that makes you implement embeddings, vector stores, and retrieval yourself so RAG stops feeling like magic.

1.6k stars JavaScript RAG · SearchLearningLanguage Models
rag-from-scratch
Velocity · 7d
+22
★ / day
Trend
accelerating
star history

What it does This repository is a progressive, example-driven course for building Retrieval-Augmented Generation in plain Node.js. It walks through every unglamorous stage of the pipeline—text chunking, local embedding generation, vector storage, query preprocessing, and context augmentation—using node-llama-cpp and no cloud APIs. By the end you have a working RAG system and, more importantly, a precise understanding of why each stage exists.

The interesting bit Instead of treating RAG as a framework configuration problem, the project treats it as a series of discrete programming exercises. You build a naive keyword-search version in under 70 lines, then swap in real vector stores, hybrid search, and query rewriting only after you understand the mechanics. The src/ directory contains a surprisingly modular little library—swappable vector stores, retrievers, and chains—but the README makes clear the code is there to be read, not just imported.

Key highlights

  • Runs fully offline using local LLMs via node-llama-cpp
  • Progressive learning path from a 70-line naive simulation up to multi-query retrieval with reciprocal rank fusion
  • Reusable src/ components including in-memory, LanceDB, and Qdrant vector stores, plus hybrid and reranker retrievers
  • Explicit coverage of the tedious but critical bits: embedding normalization, stopword removal, query rewriting, and chunk boundary strategies
  • Every example ships with paired concept explanations and line-by-line code walkthroughs

Caveats

  • The README is largely a table of contents with minimal detail on testing, performance, or production readiness; the library code is explicitly educational scaffolding.
  • Several sections appear truncated in the source (e.g., the query rewriting description cuts off mid-sentence), so the documentation may still be a work in progress.

Verdict Grab this if you are tired of treating LangChain like a black box and want to know exactly how retrieval scoring and prompt augmentation work. Look elsewhere if you need a hardened, production-grade framework with SLAs.

Frequently asked

What is pguso/rag-from-scratch?
A hands-on Node.js tutorial series that makes you implement embeddings, vector stores, and retrieval yourself so RAG stops feeling like magic.
Is rag-from-scratch open source?
Yes — pguso/rag-from-scratch is open source, released under the MIT license.
What language is rag-from-scratch written in?
pguso/rag-from-scratch is primarily written in JavaScript.
How popular is rag-from-scratch?
pguso/rag-from-scratch has 1.6k stars on GitHub and is currently accelerating.
Where can I find rag-from-scratch?
pguso/rag-from-scratch is on GitHub at https://github.com/pguso/rag-from-scratch.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.