MLflow, LangChain and Ollama: RAG evaluation tutorial

Learn to trace and evaluate an Ollama RAG pipeline in MLflow using five test questions, keyword retrieval and four custom Python scorers.

Player not loading? Watch on YouTube

This tutorial builds a RAG evaluation workflow with LangChain, Ollama and MLflow. A keyword retriever selects two documents by default from a small in-memory corpus. The chain sends those documents and the question to a local LLM, with a prompt that asks it to admit when the context lacks an answer.

The setup connects to Ollama at localhost:11434 and an MLflow tracking server at localhost:6001, enables autologging and sets the model temperature to 0.1. The speaker uses a dummy OpenAI API key to avoid warnings and says the local Ollama setup does not need a real key. The transcript does not clearly identify the model name.

Five evaluation questions run through four custom scorers: nonempty output, an expected keyword, a response length of 5 to 100 words, and a check for refusal phrases. Although the speaker calls the last check "not hallucinating," its implementation tests for those phrases rather than checking factual accuracy. An empty response even passes that scorer in the demonstrated results.

The MLflow walkthrough examines retrieved context, generated answers and per-sample scores alongside aggregate metrics. It includes a RAG question whose retrieval misses the relevant document, plus a LangChain question with relevant context but an empty answer. These examples show how the traces help separate retrieval failures from response failures.