How tamustafa/local_chat_rag works
Project Type and Purpose
• This is a full-stack application for local, document-based question answering (RAG) using open-source LLMs.
• Purpose: upload files (PDF, DOCX), index them in ChromaDB, accept chat queries, retrieve and generate answers with source citations, all locally.
File Structure
• Top-level directories:
• frontend/ – React + Vite + TypeScript + Zustand + Chakra UI
• backend/ – FastAPI + SQLAlchemy + LangChain + ChromaDB + unstructured
• data/ – persistent ChromaDB index files + uploaded raw documents
• Backend subfolders:
• app/api/ – FastAPI routers & endpoints
• app/db/ – ORM models & session management
• app/rag/ – RAG pipeline (chunking, embedding, retrieval)
• app/services/ – business logic services (file upload, chat, admin)
• Notice configuration files: requirements.txt, package.json, vite.config.ts, .gitignore.
README for Additional Insights
• Key tech stack: Ollama (LLM + embeddings), ChromaDB, LangChain, unstructured libraries.
• Workflow outline: file upload → parsing → embeddings → storage → query → retrieval → LLM answer.
a. User & Browser
• Interacts via HTTP at http://localhost:5173.
b. Frontend
• Vite development server, React components, state stores (Zustand).
• API clients (chatApi.ts, filesApi.ts, healthApi.ts).
c. Backend API (FastAPI)
• /api/files for uploads, /api/chat for queries, /api/admin etc.
• Organized in app/main.py (entrypoint), app/api/ (routers), app/services/ (logic), app/db/ (ORM).
d. RAG Pipeline
• Chunker & parser (unstructured), embedding via Ollama embeddings model, vector store in ChromaDB.
e. ChromaDB
• Local vector database under data/chroma_db, holds vector index + metadata.
f. Document Storage
• Raw file storage under data/files.
g. Ollama Server (external service)
• Provides LLM for chat (mistral) and embedding (nomic-embed-text) via HTTP interface.
h. SQLite (optional)
• Under Chroma’s files or separate DB for metadata if used (chroma.sqlite3).
i. Local File System
• Persists uploaded documents & Chroma index.
Architectural Patterns and Design Principles
• Layered Architecture: UI → API Layer → Service Layer → Data Layer
• Modular Components: clear separation of file parsing, embedding, retrieval, chat.
• Single Monolith with External Service: backend is one codebase but relies on Ollama microservice.
• State Management: frontend uses Zustand for reactive local state.