Skip to main content

Observability with Langfuse

Overview

RAGLight integrates with Langfuse to give you full visibility over your RAG pipeline. Every call to generate() or generate_streaming() produces a structured trace showing exactly what happened at each step.

Retrieve

See which documents were retrieved, from which collection, with which query.

Rerank

Inspect the reranking step when a CrossEncoder is active.

Generate

Trace the LLM call — prompt, model, latency, and token counts.

Installation

This installs langfuse==4.0.0 alongside RAGLight.

Configuration

Tracing is configured via LangfuseConfig, a dataclass that holds your Langfuse credentials.
Pass this config to your pipeline — the rest is automatic.

Usage with RAGPipeline


Usage with the Builder API


Streaming support

Langfuse tracing works identically for streaming. The trace is emitted when the stream completes.
All LLM providers support streaming traces: Ollama, OpenAI, Mistral, Gemini, LMStudio, and AWS Bedrock.

Session ID

By default, a UUID is generated once per RAG instance and reused for every generate() call. This groups all turns of the same conversation under a single Langfuse session. You can pin a custom session ID:

Use with raglight serve

When using the REST API, pass Langfuse credentials as environment variables:
.env
Then start the server:
When LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST (or LANGFUSE_BASE_URL) are all set, tracing is enabled automatically. If any of these are missing, RAGLight disables Langfuse entirely — no connection attempt is made to localhost:3000.

Run Langfuse locally

The fastest way to get Langfuse running locally is Docker Compose:
Langfuse will be available at http://localhost:3000.

Summary

  • Install with pip install "raglight[langfuse]"
  • Pass LangfuseConfig to RAGConfig or build_rag()
  • Both generate() and generate_streaming() are traced automatically
  • All LLM providers are supported
  • Sessions group all turns of a conversation together
  • For raglight serve, set LANGFUSE_* env vars — no code changes needed