Gemma 4 and OpenCode: Build a local RAG with llama.cpp

Follow a local PDF chat app build with Gemma 4, OpenCode and LangChain on an M4 MacBook with 48 GB unified memory, including retrieval failures and fixes.

Player not loading? Watch on YouTube

The speaker tests Gemma 4 as a coding assistant in OpenCode by building a Python RAG application for PDF chat. llama.cpp serves the coding model, while a separate Ollama instance supplies a Qwen3 4B chat model and the app's embeddings. The intended interface supports PDF uploads, Markdown conversion and model selection in Streamlit.

The local LLM test uses a 4-bit quantized 26-billion-parameter model with 4 billion active parameters on an M4 MacBook with 48 GB of unified memory. The speaker reports roughly 57 tokens per second, compared with about 40 in an earlier 8-bit test. These are observations from his setup. He builds llama.cpp from its development head to include a Gemma 4 tokenizer fix and configures OpenCode with a localhost OpenAI-compatible endpoint and a 256K context limit.

The build needs manual intervention. Problems include LangChain imports, Python package paths and an incorrect field for listing Ollama models. PyMuPDF4LLM handles PDF conversion, while ChromaDB stores document embeddings. A chat model initially fails because it does not support embeddings, prompting a switch to nomic-embed-text.

Retrieval remains unreliable until the speaker changes to Qwen3-Embedding 0.6B and rebuilds the stored vectors. The app then finds the paper's Nvidia A100 detail. Later attempts to add source references and test multiple PDFs produce worse answers, leaving an unfinished debugging exercise rather than a validated application.