Skip to content

Fix: Update RAG initialization and data loading for Ragas v0.2+ (#2048) #2049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions docs/getstarted/rag_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,33 @@ sample_docs = [
```

```python
# Initialize RAG instance
rag = RAG()
from ragas import evaluate, EvaluationDataset

# Load documents
rag.load_documents(sample_docs)
# The RAG() class and its methods are deprecated in Ragas v0.2+
# Instead of initializing a RAG instance, we directly prepare the dataset

# Query and retrieve the most relevant document
# Sample data: query and expected response
query = "Who introduced the theory of relativity?"
relevant_doc = rag.get_most_relevant_docs(query)
relevant_doc = ["Albert Einstein proposed the theory of relativity, which transformed our understanding of time, space, and gravity."]
answer = "Albert Einstein introduced the theory of relativity."

# Manually construct the dataset to align with the new API requirements
dataset = [
{
"user_input": query,
"retrieved_contexts": relevant_doc, # Manually specifying the relevant document
"response": answer,
"reference": answer # Assuming the generated answer matches the expected response
}
]

# Generate an answer
answer = rag.generate_answer(query, relevant_doc)
# Load the structured dataset into an EvaluationDataset object
evaluation_dataset = EvaluationDataset.from_list(dataset)

print(f"Query: {query}")
print(f"Relevant Document: {relevant_doc}")
print(f"Answer: {answer}")

```


Expand Down