How goldstygian/rag-from-scratch works
RAG from Scratch is an interactive, document-grounded question-answering program. It reads the knowledge base, chunks and embeds documents, caches per-document processing, builds a FAISS index, retrieves relevant chunks for each question, and sends the question with retrieved context to an LLM. The runtime is concentrated in main.py; README documents the intended end-to-end flow. Some internal call sites are in omitted excerpts, so those links rely on the README rather than implying additional implementation details.
Main entry points: main.py Interactive CLI · knowledgebase Knowledge Documents
Components 14
Ingestion and Cache
- Knowledge Documents
knowledgebase - Load and Chunk
main.py - Document Embeddings
main.py - Document Cache
main.py - Embedding Model
Retrieval
- FAISS Index
main.py - Query Embedding
main.py - Similarity Search
main.py - Retrieved Chunks
main.py
Answer Generation
- Interactive CLI
main.py - Context Prompt
main.py - Ollama LLM
- Grounded Answer
main.py
Other components
- Questioner
Connections 20
- Questioner → Interactive CLI: asks
main.py - Knowledge Documents → Load and Chunk: loads and chunks
README.md - Load and Chunk → Document Embeddings: embeds chunks
README.md - Embedding Model → Document Embeddings: creates vectors
main.py - Load and Chunk → Document Cache: caches chunks
README.md - Document Embeddings → Document Cache: caches vectors
README.md - Document Cache → Load and Chunk: reuses valid data
README.md - Document Embeddings → FAISS Index: stores vectors
README.md - Interactive CLI → Load and Chunk: builds knowledge base
main.py - Interactive CLI → FAISS Index: builds index
main.py - Interactive CLI → Query Embedding: submits question
README.md - Embedding Model → Query Embedding: embeds query
README.md - Query Embedding → Similarity Search: provides vector
README.md - FAISS Index → Similarity Search: searches vectors
main.py - Similarity Search → Retrieved Chunks: returns matches
README.md - Interactive CLI → Context Prompt: provides question
README.md - Retrieved Chunks → Context Prompt: adds context
README.md - Context Prompt → Ollama LLM: sends prompt
README.md - Ollama LLM → Grounded Answer: generates answer
README.md - Grounded Answer → Questioner: displays answer
README.md