A commercial-grade, local-first AI desktop app for macOS.
PyQt UI • MLX inference • Persistent RAG • Optional LoRA fine-tuning
LokumAI is a desktop-first AI chat studio that runs fully on your machine:
- A polished chat UI with streaming responses
- RAG (Retrieval-Augmented Generation) over your local files with persistent storage
- Optional MLX LoRA fine-tuning with a safe dataset pipeline (including ChatML-aware presplitting)
Designed for developers who want a fast local workflow without sacrificing reliability, persistence, or UX.
- Streaming tokens + Stop button
- Chat history persisted in SQLite
- Dev Mode tools embedded as a right sidebar (no separate window)
- Index local folders (code + docs) and retrieve relevant context at chat time
- Vector search with FAISS + sentence-transformers
- Store survives restarts and is designed to be commit-safe
Supported inputs:
- Text/code:
.py .js .ts .md .txt .json .yaml ... - Documents:
.pdf(PyMuPDF),.docx(python-docx) - Archives:
.zim(libzim / python-zim) - Images (optional): OCR via
pillow + pytesseract + tesseract
- One-click training runner via
python -m mlx_lm lora ... - Live logs + graceful stop
- Dataset helpers: JSONL (ChatML) + SQLite
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtOptional OCR dependency (images):
brew install tesseractpython3 -u main.pyWait until the UI shows: Service: ready.
prompts.json controls:
- system prompt / user prompt
- theme
model_path(MLX model directory)use_rag(enable/disable RAG)
LOKUMAI_HOME— base app data folder (default:~/.lokumai)LOKUMAI_RAG_DIR— RAG store directory (default:~/.lokumai/rag)LOKUMAI_LORA_DIR— LoRA artifacts directory (default:~/.lokumai/lora_data)LOKUMAI_CHAT_DB— chat history DB path (default:~/.lokumai/app.db)
LOKUMAI_DEV_PASSWORD— set your own password- otherwise the app stores/uses
~/.lokumai/dev_password.txt
LOKUMAI_FT_PRESPLIT=1— enable presplitting (recommended)LOKUMAI_FT_PRESPLIT_CHARS_PER_TOKEN(default4.0) — lower = more aggressive splitLOKUMAI_FT_CLEAR_CACHE_THRESHOLD— lower = more frequent cache clears
RAG stores a cumulative index under your configured RAG directory.
Typical files:
faiss_index.bin— vector indexdocs_metadata.npy— aligned chunk textschunks_meta.npy— per-chunk metadatarag_state.json— per-file indexing staterag_meta.json— convenience metadata
Reliability note:
- If loading fails, LokumAI quarantines the store files (renames with
.corrupt.<timestamp>) instead of silently appearing empty.
Recommended baseline for large models (e.g. 27B 6-bit on Apple Silicon):
batch_size = 1max_seq_len = 384(then try 512)- run validation after training (training-time eval can spike memory)
Why training can OOM even with “free RAM”: Apple Metal memory can fail due to peak allocations + fragmentation, even if system monitors show headroom.
This repo includes a generator that produces a multi-turn ChatML dataset that:
- asks questions only for blocking unclear spots
- continues immediately after the user answers
- avoids invalid samples (ChatML tags are never sliced during presplitting)
python3 tools/build_prompt_dataset.pyOutputs (default):
~/.lokumai/lora_data/train.jsonl~/.lokumai/lora_data/valid.jsonl
Change dataset size:
LOKUMAI_PROMPT_DATASET_SIZE=20000 python3 tools/build_prompt_dataset.pyCore modules:
main.py— UI, streaming, persistence, Dev toolsrag_engine.py— ingestion + indexing + retrievalfile_ingest.py— extraction + chunking (PDF/DOCX/ZIM/OCR)finetune_engine.py— MLX LoRA runner + ChatML-aware presplitlokum_paths.py— centralized path & secrets management
- The app is local-first: chats, RAG, and LoRA artifacts are stored under
~/.lokumai/by default. - Repo
.gitignoreis configured to ignore sensitive/large artifacts (DBs, datasets, adapters, binaries). - See internal notes:
INTERNAL_SECURITY.md
- Set
model_pathinprompts.jsonto a valid MLX model folder.
- Install requirements and ensure:
sentence-transformersfaiss-cpu
brew install tesseract