Home Knowledge Base TruLens

TruLens is an open-source library for evaluating and tracking LLM applications using the RAG Triad framework — providing feedback functions that score context relevance, groundedness, and answer relevance as continuous metrics across every application interaction, enabling data-driven quality improvement for RAG systems, agents, and any LLM-powered workflow.

What Is TruLens?

Why TruLens Matters

The RAG Triad in Detail

Context Relevance (Retriever Quality):

Groundedness (Generation Quality — Hallucination):

Answer Relevance (Response Usefulness):

Core TruLens Usage

LangChain Integration:

from trulens.apps.langchain import TruChain
from trulens.core import TruSession
from trulens.providers.openai import OpenAI as TruOpenAI

session = TruSession()
session.reset_database()

provider = TruOpenAI(model_engine="gpt-4o")

from trulens.core.feedback import Feedback
f_groundedness = Feedback(provider.groundedness_measure_with_cot_reasons).on_input_output()
f_context_relevance = Feedback(provider.context_relevance).on_input_output()
f_answer_relevance = Feedback(provider.relevance).on_input_output()

tru_rag = TruChain(
    rag_chain,
    app_name="CustomerFAQ-RAG",
    feedbacks=[f_groundedness, f_context_relevance, f_answer_relevance]
)

with tru_rag as recording:
    response = rag_chain.invoke({"query": "What is the return policy?"})

session.get_leaderboard()  # Show experiment comparison

TruLens Dashboard:

from trulens.dashboard import run_dashboard
run_dashboard(session)  # Opens at http://localhost:8501

Custom Feedback Function:

def technical_accuracy(question: str, response: str) -> float:
    """Returns 1.0 if response uses correct technical terminology, 0.0 otherwise."""
    required_terms = get_required_terms(question)
    return sum(1 for term in required_terms if term in response) / len(required_terms)

f_technical = Feedback(technical_accuracy).on_input_output()

TruLens vs Alternatives

FeatureTruLensRAGASDeepEvalLangfuse
RAG TriadNativeEquivalentSimilarNo
LangChain integrationTruChainGoodGoodNative
LlamaIndex integrationTruLlamaGoodGoodGood
DashboardBuilt-inNoConfident AIBuilt-in
Custom feedback fnsExcellentLimitedLimitedCustom scorers
Open sourceYesYesYesYes

TruLens is the evaluation library that makes RAG quality measurement concrete and actionable through the RAG Triad framework — by decomposing RAG quality into three independently measurable dimensions, TruLens enables teams to diagnose exactly where their retrieval-augmented generation system is failing and validate that fixes actually improve the right metric without degrading the others.

trulensfeedbackeval

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.