{
 "schema_version": 1,
 "generated": "2026-10-31",
 "id": "ml-explore-mlx-lm--ask-many-questions-of-a-long-document-with-prompt-caching",
 "repo": "ml-explore/mlx-lm",
 "repo_url": "https://github.com/ml-explore/mlx-lm",
 "repo_slug": "ml-explore-mlx-lm",
 "title": "Ask many questions about one long document quickly",
 "page_title": "How to ask many questions about one long document quickly with MLX LM",
 "summary": "Cache a long prompt once with mlx_lm.cache_prompt and reuse it for each new question.",
 "who": "Someone querying the same long report or codebase dump many times on a Mac.",
 "problem": "Re-reading a long context for every question is slow and memory hungry.",
 "outcome": "Fast follow-up answers that reuse a saved prompt cache file.",
 "steps": [
  "Install with `pip install mlx-lm`",
  "Cache the document: pipe prompt.txt into mlx_lm.cache_prompt with --model, --prompt - and --prompt-cache-file mistral_prompt.safetensors, as in the README",
  "Ask a question with mlx_lm.generate using --prompt-cache-file mistral_prompt.safetensors and your prompt; the model is read from the cache",
  "Lower peak memory while reading long prompts with --prefill-step-size",
  "Use the rotating KV cache with --max-kv-size for very long generations"
 ],
 "agent_prompt": "Using ml-explore/mlx-lm, cache <document> with mlx_lm.cache_prompt into a safetensors file, then answer these questions one by one with mlx_lm.generate --prompt-cache-file: <questions>.",
 "agents": [
  "claude-code",
  "codex",
  "cursor",
  "gemini-cli"
 ],
 "difficulty": "Intermediate",
 "time": "20 minutes",
 "basis": "readme",
 "caveat": "Smaller --max-kv-size values save RAM but lower quality, as the README warns.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "python",
 "requirements": [
  "A Mac with Apple silicon",
  "Python with pip or conda",
  "macOS 15 or later to speed up models that are large relative to RAM",
  "Optional: a Hugging Face account to upload converted models"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.8,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/ml-explore-mlx-lm/ask-many-questions-of-a-long-document-with-prompt-caching/",
 "md": "https://dedupedai.com/use-cases/ml-explore-mlx-lm/ask-many-questions-of-a-long-document-with-prompt-caching/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/ml-explore-mlx-lm--ask-many-questions-of-a-long-document-with-prompt-caching.json",
 "api_version": "v1"
}
