LokumAI engines: RAG + MLX LoRA fine-tuning utilities
Project description
lokum-engine
Developer-first building blocks extracted from LokumAI:
- RAGEngine: persistent retrieval (FAISS + sentence-transformers) over local files
- FinetuneEngine: MLX LoRA runner utilities + ChatML-safe dataset presplitting
Repo: https://github.com/fox7524/lokum-engine
Install
pip install lokum-engine
This package intentionally includes “heavy” deps (FAISS, sentence-transformers, PyMuPDF, MLX, …).
Quickstart (RAG)
from lokum_engine import RAGEngineMid
rag = RAGEngineMid() # base | mid | fab
rag.ingest_folder("/path/to/your/docs", recursive=True)
ctx = rag.query("What is this project about?", k=5)
print(ctx)
Quality profiles (RAG)
RAG has 3 preset profiles:
- base: faster / lighter defaults
- mid: balanced defaults (matches the original engine behavior)
- fab: quality-oriented (more aggressive retrieval + heavier embedding model)
Use whichever style you prefer:
from lokum_engine import RAGEngineBase, RAGEngineMid, RAGEngineFab
rag_fast = RAGEngineBase()
rag_balanced = RAGEngineMid()
rag_best = RAGEngineFab()
Persistence & storage paths
By default RAG state is stored under ~/.lokumai/rag.
Override with env vars:
LOKUMAI_HOME— base app folder (default:~/.lokumai)LOKUMAI_RAG_DIR— RAG store dir (default:~/.lokumai/rag)
Tip: If you change the embedding model later, old FAISS indexes might not be compatible (different vector dim).
Configuration (RAG)
LOKUMAI_RAG_QUALITY—base|mid|fab(if you don’t passquality=in code)LOKUMAI_EMBED_MODEL— override embedding model name (HuggingFace / sentence-transformers)LOKUMAI_EMBED_DEVICE—cpuormps(auto-detects MPS if available)LOKUMAI_EMBED_BATCH— embedding batch sizeLOKUMAI_RAG_CHECKPOINT_CHUNKS— periodic save threshold (chunk count)LOKUMAI_RAG_CHECKPOINT_SECS— periodic save threshold (seconds)
Quickstart (MLX LoRA fine-tuning)
from lokum_engine import FinetuneEngineMid
ft = FinetuneEngineMid(model_path="/path/to/mlx/model")
# (Optional) build a basic dataset from raw text chunks
train_fp, valid_fp = ft.prepare_dataset(["some text chunk", "another chunk"])
# Recommended: presplit to avoid OOM & never cut ChatML tags
ft.presplit_dataset(ft.dataset_dir, max_seq_length=512, batch_size=2)
proc = ft.start_training(
dataset_path=ft.dataset_dir,
batch_size=2,
num_layers=16,
iters=100,
)
print("PID:", proc.pid)
Quality profiles (Fine-tune)
Fine-tune also has 3 preset profiles:
from lokum_engine import FinetuneEngineBase, FinetuneEngineMid, FinetuneEngineFab
ft_fast = FinetuneEngineBase(model_path="...")
ft_balanced = FinetuneEngineMid(model_path="...")
ft_best = FinetuneEngineFab(model_path="...")
Notes:
- fab is more aggressive and can OOM depending on model + hardware. Use env overrides to dial it down.
Configuration (Fine-tune)
LOKUMAI_FT_QUALITY—base|mid|fabLOKUMAI_FT_PRESPLIT—1|0LOKUMAI_FT_PRESPLIT_CHARS_PER_TOKEN— presplit aggressiveness (lower = more splitting)LOKUMAI_FT_MAX_SEQ_LENGTHLOKUMAI_FT_CLEAR_CACHE_THRESHOLDLOKUMAI_FT_STEPS_PER_EVALLOKUMAI_FT_VAL_BATCHESLOKUMAI_FT_GRAD_CHECKPOINT—1|0
Troubleshooting
RAGEngine.enabled == False
RAG requires (at minimum):
sentence-transformersfaiss-cpu
OCR returns empty text
pytesseract needs the system tesseract binary installed.
macOS:
brew install tesseract
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lokum_engine-0.1.2.tar.gz.
File metadata
- Download URL: lokum_engine-0.1.2.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fafbf7384af8d8139c20f4c44ff78ed26adab43cf7b083166382771ce7a831b5
|
|
| MD5 |
ff55661bd9da4a8f9919c0ae3fb77fe9
|
|
| BLAKE2b-256 |
646e6074c17a2ffd422d156c39f3d3a4f259ec5bf328f912f2692e88d6e3d505
|
File details
Details for the file lokum_engine-0.1.2-py3-none-any.whl.
File metadata
- Download URL: lokum_engine-0.1.2-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dda9d230c31a1b7c56b2eb98f7d9d7f62f86c4626243e5275ae6deb794aed98c
|
|
| MD5 |
6b61f16d082bc873a1c6d6e4ff3e7bf9
|
|
| BLAKE2b-256 |
9f27a3b74892002e842dc5ed0fab1810291dacea263515407fe3f8d964f3467b
|