This is the single source of truth to set up KnowledgeAI on a fresh machine, prepare the RAG data, run the backend API, and launch the frontend chat UI. It captures all the practical gotchas we hit while bringing the stack up on macOS.
- What You Get
 - Architecture at a Glance
 - Directory Structure
 - Prerequisites
 - Python Backend Setup
 - RAG Data Prep & Pipeline
 - Start the Backend API
 - Frontend (Vite + React + Tailwind)
 - Run the Chat End‑to‑End
 - Scripts Reference
 - Troubleshooting
 - Cheatsheet
 
- A document pipeline (extract → caption images → chunk → embed to Chroma).
 - Four agents (RCA, SOP, Ticket, Super) you can run locally via FastAPI.
 - A simple chat UI (Vite + React + Tailwind) that talks to the backend 
POST /chatendpoint. 
- Pipeline (Python): 
scripts/pipeline.pyorchestrates:scripts/extract_and_caption.py→ uses unstructured + BLIP to parse docs & caption images.scripts/embed.py→ builds Chroma vector DB with SBERT (BAAI/bge-base-en).
 - Agents (Python/FastAPI): live under 
scripts/agents/; helper inscripts/agents/shared.py. - Backend API (Python/FastAPI): 
backend/main.py, route mounted inbackend/routes/chat.pyexposesPOST /chat. - Frontend (Vite/React/Tailwind): under 
frontend/. The UI posts to/chat(Vite proxy → backend). 
KnowledgeAI/
├── backend/
│   ├── logs/
│   │   └── chat.log                 # created/used by backend chat route
│   ├── routes/
│   │   ├── __init__.py
│   │   └── chat.py                  # POST /chat
│   └── main.py                      # FastAPI app (imports routes, CORS, etc.)
├── clean/                           # optional exports
├── frontend/
│   ├── public/
│   ├── src/
│   │   ├── components/
│   │   │   ├── Chat.tsx
│   │   │   ├── ChatBubble.tsx
│   │   │   └── ChatInput.tsx
│   │   ├── pages/App.tsx
│   │   ├── styles/index.css
│   │   ├── utils/api.ts
│   │   └── main.tsx
│   ├── .env                         # (optional) front-end overrides
│   ├── index.html
│   ├── package.json
│   ├── postcss.config.cjs
│   ├── tailwind.config.js
│   └── vite.config.ts               # includes proxy for /chat → http://127.0.0.1:8000
├── logs/
├── raw/                             # put your source documents here
├── raw_imgs/                        # extracted images
├── scripts/
│   ├── agents/
│   │   ├── rca_agent.py
│   │   ├── sop_agent.py
│   │   ├── ticket_agent.py
│   │   ├── super_agent.py
│   │   └── shared.py
│   ├── assistants/                  # helper utilities
│   ├── extract_and_caption.py
│   ├── embed.py
│   ├── verify_embeddings.py
│   ├── check_embedding_progress.py
│   ├── tools_rag.py
│   └── pipeline.py
├── vector_store/                    # Chroma DB
├── agents_start.sh / agents_stop.sh / agents_test.sh
├── requirements.txt
└── .env                             # backend/agents environment
- macOS (Apple Silicon OK) or Linux/WSL
 - Python 3.11 recommended
 - Node.js 18+ (Node 20+ recommended) and 
npm - Git
 - OpenAI API key (only if you intend to call OpenAI; the chat route can also use local answers, depending on your code path)
 
- 
Create & activate venv
cd KnowledgeAI python3 -m venv .venv source .venv/bin/activate python -m pip install --upgrade pip wheel setuptools
 - 
Install Python deps
pip install -r requirements.txt # Extras used by unstructured for Office docs pip install "unstructured[docx]" "unstructured[xlsx]" "unstructured[pptx]"
 - 
System packages (macOS)
brew install imagemagick ghostscript poppler tesseract ffmpeg cmake brew install --cask libreoffice
 - 
Backend env (.env at repo root)
# === Backend / RAG === VECTOR_STORE_PATH=./vector_store # === Logging === LOG_LEVEL=INFO TOKENIZERS_PARALLELISM=false HF_HUB_DISABLE_TELEMETRY=1 # === LLM (optional) === OPENAI_API_KEY=
 
- Place documents in 
raw/(.pptx,.docx,.xlsx,.pdf,.txt, images). - Build vectors:
python -m scripts.pipeline all
- First run will download HF models (BLIP + SBERT). If you use Cloudflare WARP/corp VPN and hit SSL issues, temporarily disable it.
 
 
- Ensure the backend log directory exists once:
mkdir -p backend/logs
 - Launch API:
uvicorn backend.main:app --reload --port 8000
- FastAPI will serve on 
http://127.0.0.1:8000. backend/routes/chat.pyappends tobackend/logs/chat.log(created automatically if the directory exists).
 - FastAPI will serve on 
 
The UI posts to
/chat. Vite’s dev server proxies/chat→http://127.0.0.1:8000(seevite.config.ts).
Therefore, start the backend first to avoidECONNREFUSEDat the proxy.
- 
Install Node deps
cd frontend npm ci # or: npm install
 - 
(Optional) Frontend .env
If you want to override the default proxy/URLs, createfrontend/.env:# example — only if you changed backend port/host VITE_BACKEND_URL=http://127.0.0.1:8000
Ensure
utils/api.tsreads this if present; otherwise the proxy handles/chat. - 
Run the dev server
npm run dev
- Vite opens 
http://localhost:5173. - When you send a message, the UI sends 
POST /chatwhich the dev proxy forwards tohttp://127.0.0.1:8000/chat. 
 - Vite opens 
 - 
Build for production
npm run build npm run preview # optional local preview 
- Terminal A (repo root):
source .venv/bin/activate uvicorn backend.main:app --reload --port 8000 - Terminal B:
cd frontend npm run dev - Open the browser at 
http://localhost:5173, type in the chat box, and hit Enter.
Checkbackend/logs/chat.logfor request/response traces. 
Pipeline
python -m scripts.pipeline all— end‑to‑end doc processingscripts/extract_and_caption.py— unstructured + BLIP captionsscripts/embed.py— Chroma embeddingsscripts/verify_embeddings.py,scripts/check_embedding_progress.py— diagnostics
Agents (optional)
./agents_start.sh— start RCA/SOP/Ticket/Super on ports 9131/9132/9133/9191./agents_stop.sh,./agents_test.sh
Backend
backend/main.py— FastAPI appbackend/routes/chat.py—POST /chathandler + logging
Frontend
frontend/src/components/Chat.tsx,ChatBubble.tsx,ChatInput.tsxfrontend/src/utils/api.ts— HTTP clientfrontend/vite.config.ts— dev proxy for/chat
1) Vite “http proxy error: /chat ECONNREFUSED”
Cause: Backend isn’t running or wrong port.
Fix:
uvicorn backend.main:app --reload --port 8000
# verify: curl -i http://127.0.0.1:8000/docs2) 500 from /chat – FileNotFoundError for backend/logs/chat.log
Cause: Directory missing on first run.
Fix:
mkdir -p backend/logs
# restart uvicorn3) Unstructured errors (PPTX/DOCX/XLSX)
PackageNotFoundError→ file missing/misnamed inraw/.- “not a ZIP archive” → re-save the DOCX in Word/LibreOffice.
 - Install extras:
pip install "unstructured[docx]" "unstructured[xlsx]" "unstructured[pptx]" 
4) SSL errors when downloading models
Disable Cloudflare WARP / corp VPN temporarily or configure your CA bundle.
5) CORS errors (in production without Vite proxy)
Expose the backend with proper CORS in backend/main.py or use a reverse proxy (Nginx/Caddy) to forward /chat.
# One-time
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel setuptools
pip install -r requirements.txt
pip install "unstructured[docx]" "unstructured[xlsx]" "unstructured[pptx]"
brew install imagemagick ghostscript poppler tesseract ffmpeg cmake
brew install --cask libreoffice
# Data → vectors
mkdir -p raw backend/logs
python -m scripts.pipeline all
# Backend
uvicorn backend.main:app --reload --port 8000
# Frontend
cd frontend
npm ci
npm run devIf you hit a new edge case, open an issue with the failing command, full stack trace, and OS/Node/Python versions. Happy shipping! 🚀