finds.dev← search

// the find

pguso/rag-from-scratch

★ 1,633 · JavaScript · MIT · updated Mar 2026

Demystify RAG by building it from scratch. Local LLMs, no black boxes - real understanding of embeddings, vector search, retrieval, and context-augmented generation.

A step-by-step, from-scratch RAG tutorial in Node.js that walks through chunking, embeddings, vector stores, retrieval strategies, and query rewriting using local LLMs via node-llama-cpp. It's aimed at JS developers who want to understand RAG internals rather than just wire up LangChain, and it pairs each example with an actual library (loaders, retrievers, chains) instead of throwaway scripts.

Each topic ships a working example.js plus CODE.md and CONCEPT.md, so you get the code and the reasoning behind it rather than just a demo. The retrieval strategies go further than most 'RAG 101' repos — hybrid BM25+vector search, multi-query with reciprocal rank fusion, and LLM-based query rewriting with a heuristic fallback are all implemented, not just described. Runs fully local (node-llama-cpp), so there's no API key needed to follow along. The src/ library is structured with real abstractions (BaseRetriever, BaseVectorStore) and multiple backends (in-memory, LanceDB, Qdrant), so it's more than glue code around one example.

A meaningful chunk of the advertised structure — reranking, evaluation metrics, production error handling/streaming, graph DB integration — is marked 'planned' in the README and not yet implemented, so the project is less complete than the directory tree suggests. No visible CI or test runner wired up despite an examples/tests folder existing in the structure. JS is a niche choice for RAG tooling; the ecosystem (embedding models, vector libraries) is far less mature here than in Python, so some of the 'from scratch' code exists only because good local JS options are limited, not because it's pedagogically necessary. No published npm package, so reusing src/ outside the tutorial means copying files rather than installing a dependency.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →