How linkedinlearning/rag-models-from-scratch-with-open-source-3980304 works
Project type and purpose
• This is a hands-on instructional repository for a Retrieval-Augmented Generation (RAG) pipeline built from scratch using open-source tools.
• Its purpose is to guide learners through:
• Installing a local LLM (LLama/ollama)
• Creating a content corpus and extracting text
• Generating embeddings and storing them in a vector database (Postgres + pgvector)
• Building a RAG service that retrieves context and calls the LLM to answer queries
File structure
• Top-level scripts prefixed with b_, c_, d_ correspond to successive course stages:
• b_01…b_05: model install, model file prep, helper functions, corpus generation, text extraction
• c_02…c_05: Postgres install, DB connection, populating vector DB, querying embeddings
• d_02…d_05: content preparation and running the final RAG pipeline
• init-db/init.sql: schema for Postgres vector store
• .devcontainer: Dockerfile and config for reproducible dev environment
• GitHub workflows and templates for CI/CD and contribution guidelines
Architectural insights from README
• Emphasis on modular pipeline steps (install → prepare data → embed → store → retrieve → generate)
• Use of open-source LLMs and vector DB for efficient local experimentation
a. Developer Environment
• Dev Container (Docker)
• Shell & Python Scripts
b. Data Ingestion & Processing
• Corpus files (raw data sources)
• generate_corpus.py & extract_text.py
c. Embedding & Vector Store
• ollama_functions.py (LLM wrapper for embeddings)
• Postgres + pgvector (initialized via init.sql & c_02…c_05 scripts)
d. Retrieval & Generation Service
• run_rag.py
• Querying the vector DB for similar contexts
• Passing context + prompt to local LLM for answer
e. Supporting Infrastructure
• GitHub Actions (CI/CD)
• Configuration files (.devcontainer, Dockerfile, workflows)
Architectural patterns & design principles
• Pipeline/ETL pattern: clearly separated stages for data preparation, embedding, storage, retrieval, and generation
• Modular scripting: each script handles one responsibility, enabling incremental learning and debugging
• Infrastructure as code: using Docker and SQL schema for reproducibility