What this thread does
Do first: Run pip install langchain-community.
When you need it
Use this to generate synthetic evaluation data from documents for a RAG pipeline. The page's quickstart loads Markdown documents and generates a testset that you can review before selecting queries.
Steps
1. Install the document loader and the OpenAI integration shown on the page:
pip install langchain-community
pip install langchain-openai
2. Obtain the page's sample documents:
git clone https://huggingface.co/datasets/vibrantlabsai/Sample_Docs_Markdown
3. Load the Markdown files:
from langchain_community.document_loaders import DirectoryLoader
path = "Sample_Docs_Markdown/"
loader = DirectoryLoader(path, glob="**/*.md")
docs = loader.load()
4. Make OPENAI_API_KEY available in the environment as the page requires. Initialize its OpenAI generation model and embeddings:
from ragas.llms import LangchainLLMWrapper
from langchain_openai import ChatOpenAI
from ragas.embeddings import OpenAIEmbeddings
import openai
generator_llm = LangchainLLMWrapper(ChatOpenAI(model="gpt-4o"))
openai_client = openai.OpenAI()
generator_embeddings = OpenAIEmbeddings(client=openai_client)
5. Generate the testset with the page's example size:
from ragas.testset import TestsetGenerator
generator = TestsetGenerator(llm=generator_llm, embedding_model=generator_embeddings)
dataset = generator.generate_with_langchain_docs(docs, testset_size=10)
Check it worked
Use the page's inspection call and review the generated queries to select those suitable for the final testset:
dataset.to_pandas()
Limits
The OpenAI example requires OPENAI_API_KEY. For documents loaded with llama_index, the page directs you to generate_with_llama_index_docs instead. The sample documents may be replaced with your own documents. The page does not name a version of Ragas for this procedure.
Not for: scoring retrieval and answer quality; see ragas-score-retrieval-and-answer-quality.
Sources
- Testset Generation for RAG, Ragas documentation, read 2026-11-24: "You can replace this with your own documents."
Checked
2026-11-24; read <https://docs.ragas.io/en/stable/getstarted/rag_testset_generation/>; no command was run.
Started from a post by @Ragas, packaged by the editor. Original post