Skip to main content
Botmartz AI Solutions Private Limited
LANGCHAIN

RAG Evaluation with LangSmith: Faithfulness, Relevancy, Context Precision, and Automated Scoring

RAG answers can be fluent but wrong. Use LangSmith to evaluate faithfulness (grounded in context), relevancy (answers the question), and context precision (retrieved docs are relevant).

Soham Sharma
Soham Sharma
AI Engineer, Botmartz · Dec 4, 2026
Depth
Full Spec
Failure Modes
5
Code Snippets
4
Runnable Notebook
0
RAG Evaluation with LangSmith: Faithfulness, Relevancy, Context Precision, and Automated Scoring

RAG evaluation is hard: answers can sound fluent but hallucinate (not grounded in context). LangSmith provides automated metrics: faithfulness (uses context), relevancy (answers the question), and context precision (retrieved documents are relevant). This post covers setup and interpretation.

Setting Up LangSmith

Code Snippet
from langsmith import Client

client = Client()

# Log runs to LangSmith
@client.traced()
def rag_chain(question):
    context = retriever.get_relevant_documents(question)
    answer = llm.generate(question, context)
    return {"answer": answer, "context": context}

result = rag_chain("What is transformers?")

Evaluating Faithfulness

Code Snippet
from langsmith.evaluation import evaluate_string

# Evaluate if answer is grounded in context
def faithfulness_evaluator(run_output, context):
    answer = run_output["answer"]
    context_text = "\n".join([doc.page_content for doc in context])
    # Use LLM to check if answer is supported by context
    return {"score": check_if_grounded(answer, context_text)}

Conclusion

LangSmith provides visibility into RAG quality. Faithfulness, relevancy, and context precision metrics help identify failure modes. Automated evaluation enables rapid iteration and production monitoring. Next: ReAct agents—how to give LLMs tools and reasoning loops.

#LangChain#Evaluation#RAG Quality#LangSmith#Metrics
1 views
Soham Sharma
Soham Sharma
Leading AI systems research, enterprise RAG, and multi-agent workflow architecture at Botmartz AI Solutions.