rag-from-scratch  by pguso

Building Retrieval-Augmented Generation (RAG) from scratch

Created 2 months ago
1,184 stars

Top 32.8% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a hands-on, educational approach to understanding Retrieval-Augmented Generation (RAG) by building it from scratch using local components. It targets developers seeking a deep, code-level comprehension of RAG pipelines, embeddings, vector search, and context-augmented generation without relying on black-box cloud APIs. The primary benefit is demystifying advanced AI concepts through clear explanations and minimal, well-commented local code.

How It Works

The project meticulously breaks down the RAG pipeline into fundamental steps: data loading, text splitting, embedding generation, vector store creation, retrieval, re-ranking, query preprocessing, prompt augmentation, and final generation. It emphasizes a conceptual clarity and mathematical intuition, starting with simplified examples before introducing vector databases and advanced retrieval strategies. This incremental, code-first methodology ensures users grasp each component's function and interaction within the broader RAG system.

Quick Start & Requirements

  • Install: Run npm install in the project root.
  • Run: Execute examples using node <path_to_example>/example.js, e.g., node 00_how_rag_works/example.js.
  • Prerequisites: Node.js 18+, a local LLM setup (e.g., node-llama-cpp), and necessary npm packages for embeddings and vector math.

Highlighted Details

  • Educational Focus: Builds RAG concepts step-by-step with minimal code and clear explanations, avoiding cloud APIs and black boxes.
  • Local-First: Designed to run entirely locally, fostering a deeper understanding of underlying mechanisms.
  • Modular Design: Features reusable library code for embeddings, vector stores (in-memory, LanceDB, Qdrant), loaders, text splitters, retrievers, and chains.
  • Structured Learning Path: Offers a progressive series of examples covering core RAG components from basic similarity search to advanced retrieval strategies and prompt engineering.

Maintenance & Community

Contributions are welcomed for clear, educational RAG examples via pull requests. The project references related concepts and tools like LangChain and AI Agents from Scratch.

Licensing & Compatibility

The provided README does not specify a software license. Potential adopters should verify licensing terms before use, especially concerning commercial applications or integration with closed-source systems.

Limitations & Caveats

This project is primarily educational and under active development, with many advanced features (e.g., hybrid search, multi-modal RAG, production-ready components, evaluation frameworks) still planned. Its focus on foundational understanding means it may not yet offer the robustness or breadth of features found in mature RAG frameworks.

Health Check
Last Commit

1 month ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
55 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.