How juancvalencias/chat-rag works
Project type and purpose
• This is a full-stack Retrieval-Augmented Generation (RAG) prototype built with Python and Streamlit.
• It ingests a PDF (“23_migracion.pdf”), splits it into chunks, computes embeddings via a local Ollama “nomic-embed-text” model, stores them in an in-memory vector store, and then answers user questions by retrieving relevant chunks and forwarding them (with context) to a local Llama2 LLM via Ollama.
File structure
• Top level
• README.md – project description and setup steps
• pyproject.toml – Python dependencies and project metadata
• data/23_migracion.pdf – source document for RAG
• temp.pdf – probably a scratch/test file
• src/
• app.py – Streamlit UI and entry point
• rag.py – core RAG pipeline (PDF loader, chunker, embedding, retrieval, LLM call)
• test_pdf_loader.py – unit test for PDF ingestion/chunking
• test_embeddings.py – unit test for embedding integration
• Configuration
• .python-version – pinned Python version
• .gitignore – excludes environment, temp files
Insights from README
• Requires Ollama local server with two models pulled:
• “llama2:7b” for generation
• “nomic-embed-text:latest” for embeddings
• Run via uv run streamlit run app.py in the src/ directory.
a. Main Components
1. User Interface (Streamlit app.py)
2. RAG Pipeline (rag.py), comprising:
– PDF Loader & Chunker
– Embedding Engine (nomic-embed-text via Ollama)
– Vector Store (in-memory or lightweight DB)
– Retriever (nearest-neighbor search)
– LLM Service (Llama2 via Ollama)
3. Data Store
– Local file system storing the source PDF
4. External Services
– Ollama server hosting the two models
b. Relationships & Interactions
• User submits a question in the Streamlit UI
• UI calls RAG pipeline
• PDF Loader reads chunks (or reuses cached chunks)
• Chunks passed to embedding service → embedding vectors
• Vectors indexed/stored in vector store
• Query embedding compared to stored vectors → top-k contexts
• Context + user question sent to LLM service → answer
• UI renders the generated response
c. Architectural Patterns
• Layered separation: Presentation (UI), Application (RAG pipeline), Data (vector store + PDF), Infrastructure (Ollama models)
• Single-process Python app, but clear module boundaries (app.py vs rag.py)
d. Key Technologies
• Python 3.x, Streamlit, Ollama CLI/daemon
• nomic-embed-text model, llama2:7b model
• pyproject.toml / pip for dependency management