MCPcopy Index your code
hub / github.com/TAMustafa/Local_Chat_RAG

github.com/TAMustafa/Local_Chat_RAG @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
73 symbols 302 edges 39 files 14 documented · 19% updated 13mo ago★ 179
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Local Chat RAG

A local, privacy-first Retrieval-Augmented Generation (RAG) chat app. Upload documents, ask questions, and get answers with sources—powered by open-source LLMs running on your own machine.


Features

  • Local RAG Pipeline: No cloud, no data leaks—everything runs on your machine.
  • File Upload & Parsing: Supports DOCX, PDF, and more (via unstructured, python-docx, pdfplumber).
  • Modern UI: Gemini-style, minimal, and accessible. Built with Vite, React, TypeScript, Zustand, Chakra UI.
  • Chat with Sources: Ask questions and see which documents/sections the answer comes from.
  • FastAPI Backend: Robust API, clean separation from frontend, /api route organization.
  • Ollama LLM Integration: Use open-source models (Mistral, Llama2, etc.) locally via Ollama.
  • Extensible & Documented: Modular, testable code with strict documentation and change management policies.

Quick Start

1. Requirements

  • Python 3.9+
  • Node.js 18+
  • Ollama (for local LLMs and embeddings)

🚀 Quick Setup Checklist

  1. Install Ollama (for local LLM and embeddings)
  2. Pull required models: mistral (chat) and nomic-embed-text (embeddings)
  3. Start the Ollama server: ollama serve (must be running for backend to work)
  4. Set up backend (Python, FastAPI)
  5. Set up frontend (Node.js, Vite)
  6. Open the app in your browser: http://localhost:5173

2. Install Ollama and Required Models

  • Download Ollama: ollama.com/download (macOS, Windows, Linux)
  • Or via Homebrew (macOS): bash brew install ollama
  • Start the Ollama server: (must be running for backend to work) bash ollama serve
  • Pull required models: bash ollama pull mistral ollama pull nomic-embed-text
  • mistral: Used for chat and answering questions
  • nomic-embed-text: Used for document embeddings

    You can substitute mistral with any compatible model (e.g. llama3, llama2), but the backend defaults to mistral.

3. Backend Setup (FastAPI)

  • Create and activate a virtual environment: bash cd backend python -m venv .venv source .venv/bin/activate
  • Install Python dependencies: bash pip install --upgrade pip pip install -r requirements.txt
  • Start the backend server: bash uvicorn app.main:app --reload
  • The backend API will be available at: http://localhost:8000/api

4. Frontend Setup (Vite)

  • Install Node.js dependencies: bash cd frontend npm install
  • Start the frontend dev server: bash npm run dev
  • The frontend app will be available at: http://localhost:5173

✅ Quick Setup Checklist


How to Use the App

  • Open http://localhost:5173 in your browser.
  • Upload your files using the sidebar.
  • Ask questions in the chat box; answers will cite document sources.
  • All processing is local—your data never leaves your device.

Troubleshooting & Tips

  • Ollama not running or model errors:
  • Make sure ollama serve is running in a terminal window before starting the backend.
  • Ensure you have pulled both llama3 and nomic-embed-text models.
  • You can check running models with ollama list.
  • Python dependency errors:
  • Make sure your virtual environment is activated and pip is up to date.
  • Node/npm errors:
  • Use Node.js 18+ and delete/reinstall node_modules if issues persist.
  • PDF/DOCX parsing errors:
  • Install libmagic and poppler-utils (see backend gotchas).
  • For more help:
  • See backend/gotchas.md and backend/implementation_details.md.

Usage

  • Upload files in the sidebar.
  • Ask questions in the chat—answers are generated using your documents as context.
  • Sources are shown for every answer (deduplicated by file).
  • All processing is local—your data never leaves your device.

Architecture

  • Frontend: Vite + React + TypeScript + Zustand + Chakra UI
  • Backend: FastAPI + SQLAlchemy + LangChain + ChromaDB + Unstructured
  • LLM: Ollama (Mistral, Llama2, etc.) via langchain-ollama
  • RAG Pipeline: Chunking, embedding, retrieval, and chat with sources

Folder Structure

ChatRAG/
  backend/
    app/
      main.py           # FastAPI app & API endpoints
      db/               # Database models & session
      rag/              # RAG pipeline logic
    requirements.txt
    ...
  frontend/
    src/
      components/       # UI components (Chat, Files, Layout)
      state/            # Zustand stores
      ...
    vite.config.ts
    ...

Customization

  • Change LLM Model: Edit the model name in backend/app/main.py (OllamaLLM(model="mistral")).
  • Add File Types: Extend file parsing in the backend pipeline.
  • UI/UX: Tweak Chakra UI theme or component structure in frontend/src/components.

Documentation & Policies

  • All operational quirks, architecture decisions, and gotchas are logged in backend/implementation_details.md, gotchas.md, and quick_reference.md.
  • Strict documentation and code quality policies are followed—see project docs for details.

Credits


License

MIT

Extension points exported contracts — how you extend this code

ImportMetaEnv (Interface)
(no doc)
frontend/src/vite-env.d.ts
ImportMeta (Interface)
(no doc)
frontend/src/vite-env.d.ts
FileErrorAlertProps (Interface)
(no doc)
frontend/src/components/Files/components/FileErrorAlert.tsx
FilesListProps (Interface)
(no doc)
frontend/src/components/Files/components/FilesList.tsx
SourceMeta (Interface)
(no doc)
frontend/src/components/Chat/components/ChatBubble.tsx

Core symbols most depended-on inside this repo

safe_log_gotcha
called by 10
backend/app/log_utils.py
Header
called by 1
frontend/src/components/Layout/Header.tsx
getFileExt
called by 1
frontend/src/components/Files/components/FilePill.tsx
loadFiles
called by 1
frontend/src/components/Files/components/FilesSidebar.tsx
useFileUpload
called by 1
frontend/src/components/Files/hooks/useFileUpload.ts
handleSend
called by 1
frontend/src/components/Chat/components/ChatInput.tsx
fetchHealth
called by 1
frontend/src/api/healthApi.ts
uploadFile
called by 1
frontend/src/api/filesApi.ts

Shape

Function 41
Interface 11
Class 10
Route 6
Method 5

Languages

Python52%
TypeScript48%

Modules by API surface

backend/app/main.py12 symbols
backend/app/schemas.py6 symbols
backend/app/rag/pipeline.py6 symbols
frontend/src/components/Files/components/FilesSidebar.tsx3 symbols
frontend/src/components/Chat/components/ChatBubble.tsx3 symbols
frontend/src/api/filesApi.ts3 symbols
backend/app/services/file_service.py3 symbols
backend/app/error_handlers.py3 symbols
backend/app/db/models.py3 symbols
frontend/src/vite-env.d.ts2 symbols
frontend/src/state/filesStore.ts2 symbols
frontend/src/state/chatStore.ts2 symbols

For agents

$ claude mcp add Local_Chat_RAG \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact