ragas
Expert guidance for Ragas, the framework for evaluating Retrieval-Augmented Generation pipelines. Helps developers measure and improve the quality of their RAG systems across retrieval accuracy, answer faithfulness, and response relevance.
What this skill does
# Ragas — RAG Evaluation Framework
## Overview
Ragas, the framework for evaluating Retrieval-Augmented Generation pipelines. Helps developers measure and improve the quality of their RAG systems across retrieval accuracy, answer faithfulness, and response relevance.
## Instructions
### Basic Evaluation
Evaluate a RAG pipeline with standard metrics:
```python
# evaluate_rag.py — Run Ragas evaluation on a RAG pipeline
from ragas import evaluate
from ragas.metrics import (
faithfulness, # Is the answer grounded in retrieved context?
answer_relevancy, # Does the answer address the question?
context_precision, # Are retrieved docs relevant and well-ranked?
context_recall, # Did retrieval find all necessary information?
)
from datasets import Dataset
# Prepare evaluation dataset — each row is one question with ground truth
eval_data = {
"question": [
"What is the refund policy for annual subscriptions?",
"How do I reset my password?",
"What integrations are available with Slack?",
],
"answer": [
"Annual subscriptions can be refunded within 30 days of purchase.",
"Click 'Forgot Password' on the login page and follow the email link.",
"We offer native Slack integration with channel notifications and slash commands.",
],
"contexts": [
# Retrieved documents for each question
[
"Refund Policy: Annual plans are eligible for a full refund within 30 days. Monthly plans are non-refundable.",
"Billing FAQ: Contact [email protected] for billing inquiries.",
],
[
"Password Reset: Navigate to login page, click 'Forgot Password', enter your email.",
"Security: All password reset links expire after 24 hours.",
],
[
"Integrations: Connect with Slack, Teams, and Discord. Slack supports notifications and /commands.",
"API: Use webhooks for custom integrations with any platform.",
],
],
"ground_truth": [
"Annual subscriptions are eligible for a full refund within 30 days of purchase. Monthly plans cannot be refunded.",
"Go to the login page, click 'Forgot Password', enter your email address, and follow the reset link sent to your inbox.",
"Slack integration includes channel notifications, slash commands, and is available as a native integration.",
],
}
dataset = Dataset.from_dict(eval_data)
# Run evaluation across all metrics
results = evaluate(
dataset=dataset,
metrics=[faithfulness, answer_relevancy, context_precision, context_recall],
)
# Results are a dict of metric_name → score (0.0 to 1.0)
print(results)
# {'faithfulness': 0.95, 'answer_relevancy': 0.88, 'context_precision': 0.92, 'context_recall': 0.85}
# Convert to pandas DataFrame for per-question analysis
df = results.to_pandas()
print(df[['question', 'faithfulness', 'answer_relevancy']].to_string())
```
### Custom Test Sets with Synthetic Data
Generate evaluation datasets from your own documents:
```python
# generate_testset.py — Create synthetic Q&A pairs from documents
from ragas.testset import TestsetGenerator
from ragas.testset.evolutions import simple, reasoning, multi_context
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_community.document_loaders import DirectoryLoader
# Load your knowledge base documents
loader = DirectoryLoader("./docs/", glob="**/*.md")
documents = loader.load()
# Configure the generator with an LLM
generator = TestsetGenerator.from_langchain(
generator_llm=ChatOpenAI(model="gpt-4o"),
critic_llm=ChatOpenAI(model="gpt-4o"),
embeddings=OpenAIEmbeddings(),
)
# Generate test set with different question complexities
# simple: straightforward factual questions
# reasoning: questions requiring inference across a single document
# multi_context: questions needing information from multiple documents
testset = generator.generate_with_langchain_docs(
documents,
test_size=50, # Generate 50 Q&A pairs
distributions={
simple: 0.4, # 40% simple factual
reasoning: 0.3, # 30% reasoning required
multi_context: 0.3, # 30% multi-document synthesis
},
)
# Export for reuse across evaluation runs
test_df = testset.to_pandas()
test_df.to_csv("eval_testset.csv", index=False)
print(f"Generated {len(test_df)} test questions")
print(f"Distribution: {test_df['evolution_type'].value_counts().to_dict()}")
```
### Evaluating Specific Components
Isolate and measure individual RAG components:
```python
# eval_retriever.py — Evaluate retrieval quality independently
from ragas.metrics import (
context_precision, # Are top results relevant? (ranking quality)
context_recall, # Are all relevant docs retrieved? (coverage)
context_entity_recall, # Are key entities from ground truth in context?
)
from ragas import evaluate
from datasets import Dataset
def evaluate_retriever(retriever, test_questions, ground_truths):
"""Evaluate retriever independently from the generator.
Args:
retriever: Your retrieval function that takes a query and returns docs
test_questions: List of test queries
ground_truths: List of expected answers for recall measurement
"""
contexts = []
for question in test_questions:
# Your retriever returns a list of document strings
docs = retriever.retrieve(question, top_k=5)
contexts.append([doc.page_content for doc in docs])
dataset = Dataset.from_dict({
"question": test_questions,
"contexts": contexts,
"ground_truth": ground_truths,
})
results = evaluate(
dataset=dataset,
metrics=[context_precision, context_recall, context_entity_recall],
)
return results
# eval_generator.py — Evaluate answer generation quality
from ragas.metrics import (
faithfulness, # Hallucination detection
answer_relevancy, # Does it answer the question?
answer_similarity, # Semantic similarity to ground truth
answer_correctness, # Factual correctness vs ground truth
)
def evaluate_generator(rag_pipeline, test_questions, contexts, ground_truths):
"""Evaluate the generation component with fixed retrieval context.
Args:
rag_pipeline: Your generation function
test_questions: List of test queries
contexts: Pre-retrieved contexts (fixed to isolate generator)
ground_truths: Expected correct answers
"""
answers = []
for question, ctx in zip(test_questions, contexts):
answer = rag_pipeline.generate(question, context=ctx)
answers.append(answer)
dataset = Dataset.from_dict({
"question": test_questions,
"answer": answers,
"contexts": contexts,
"ground_truth": ground_truths,
})
return evaluate(
dataset=dataset,
metrics=[faithfulness, answer_relevancy, answer_correctness],
)
```
### CI Integration
Run Ragas evaluations in your CI pipeline:
```python
# tests/test_rag_quality.py — Pytest integration for continuous RAG evaluation
import pytest
from ragas import evaluate
from ragas.metrics import faithfulness, answer_relevancy, context_precision
from datasets import Dataset
import json
# Load the pre-generated test set (created by generate_testset.py)
QUALITY_THRESHOLDS = {
"faithfulness": 0.85, # Minimum acceptable faithfulness
"answer_relevancy": 0.80, # Minimum answer relevance
"context_precision": 0.75, # Minimum retrieval precision
}
@pytest.fixture(scope="session")
def eval_results(rag_pipeline, test_dataset):
"""Run evaluation once per test session and share results."""
questions, ground_truths = test_dataset
# Run the full RAG pipeline on test questions
answers, contexts = [], []
for q in questions:
result = rag_pipeline.qRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.