Generation
TestsetGenerator
dataclass
TestsetGenerator(llm: BaseRagasLLM, knowledge_graph: KnowledgeGraph = KnowledgeGraph(), persona_list: Optional[List[Persona]] = None)
Generates an evaluation dataset based on given scenarios and parameters.
Attributes:
Name | Type | Description |
---|---|---|
llm |
BaseRagasLLM
|
The language model to use for the generation process. |
knowledge_graph |
KnowledgeGraph, default empty
|
The knowledge graph to use for the generation process. |
from_langchain
classmethod
from_langchain(llm: BaseLanguageModel, knowledge_graph: Optional[KnowledgeGraph] = None) -> TestsetGenerator
Creates a TestsetGenerator
from a Langchain LLMs.
Source code in src/ragas/testset/synthesizers/generate.py
from_llama_index
classmethod
from_llama_index(llm: BaseLLM, knowledge_graph: Optional[KnowledgeGraph] = None) -> TestsetGenerator
Creates a TestsetGenerator
from a LlamaIndex LLM and embedding model.
Source code in src/ragas/testset/synthesizers/generate.py
generate_with_langchain_docs
generate_with_langchain_docs(documents: Sequence[Document], testset_size: int, transforms: Optional[Transforms] = None, transforms_llm: Optional[BaseRagasLLM] = None, transforms_embedding_model: Optional[BaseRagasEmbeddings] = None, query_distribution: Optional[QueryDistribution] = None, run_config: Optional[RunConfig] = None, callbacks: Optional[Callbacks] = None, with_debugging_logs=False, raise_exceptions: bool = True) -> Testset
Generates an evaluation dataset based on given Langchain documents and parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
Sequence[Document]
|
A sequence of Langchain documents to use as source material |
required |
testset_size
|
int
|
The number of test samples to generate |
required |
transforms
|
Optional[Transforms]
|
Custom transforms to apply to the documents, by default None |
None
|
transforms_llm
|
Optional[BaseRagasLLM]
|
LLM to use for transforms if different from instance LLM, by default None |
None
|
transforms_embedding_model
|
Optional[BaseRagasEmbeddings]
|
Embedding model to use for transforms if different from instance model, by default None |
None
|
query_distribution
|
Optional[QueryDistribution]
|
Distribution of query types to generate, by default None |
None
|
run_config
|
Optional[RunConfig]
|
Configuration for the generation run, by default None |
None
|
callbacks
|
Optional[Callbacks]
|
Callbacks to use during generation, by default None |
None
|
with_debugging_logs
|
bool
|
Whether to include debug logs, by default False |
False
|
raise_exceptions
|
bool
|
Whether to raise exceptions during generation, by default True |
True
|
Returns:
Type | Description |
---|---|
Testset
|
The generated evaluation dataset |
Raises:
Type | Description |
---|---|
ValueError
|
If no LLM or embedding model is provided either during initialization or as arguments |
Source code in src/ragas/testset/synthesizers/generate.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
generate_with_llamaindex_docs
generate_with_llamaindex_docs(documents: Sequence[Document], testset_size: int, transforms: Optional[Transforms] = None, transforms_llm: Optional[BaseLLM] = None, transforms_embedding_model: Optional[BaseEmbedding] = None, query_distribution: Optional[QueryDistribution] = None, run_config: Optional[RunConfig] = None, callbacks: Optional[Callbacks] = None, with_debugging_logs=False, raise_exceptions: bool = True)
Generates an evaluation dataset based on given scenarios and parameters.
Source code in src/ragas/testset/synthesizers/generate.py
generate
generate(testset_size: int, query_distribution: Optional[QueryDistribution] = None, num_personas: int = 3, run_config: Optional[RunConfig] = None, batch_size: Optional[int] = None, callbacks: Optional[Callbacks] = None, token_usage_parser: Optional[TokenUsageParser] = None, with_debugging_logs=False, raise_exceptions: bool = True) -> Testset
Generate an evaluation dataset based on given scenarios and parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
testset_size
|
int
|
The number of samples to generate. |
required |
query_distribution
|
Optional[QueryDistribution]
|
A list of tuples containing scenario simulators and their probabilities. If None, default simulators will be used. |
None
|
num_personas
|
int
|
The number of personas to generate or use from the persona_list. |
3
|
run_config
|
Optional[RunConfig]
|
Configuration for running the generation process. |
None
|
batch_size
|
Optional[int]
|
How large should batches be. If set to None (default), no batching is done. |
None
|
callbacks
|
Optional[Callbacks]
|
Langchain style callbacks to use for the generation process. You can use this to log the generation process or add other metadata. |
None
|
token_usage_parser
|
Optional[TokenUsageParser]
|
Parse the LLMResult object and return a TokenUsage object. This is used to calculate the cost of the generation process. |
None
|
with_debugging_logs
|
bool
|
If True, enable debug logging for various components. |
False
|
raise_exceptions
|
bool
|
If True, raise exceptions during the generation process. |
True
|
Returns:
Type | Description |
---|---|
Testset
|
A dataset containing the generated TestsetSamples. |
Notes
This function performs the following steps: 1. Set up scenarios and debug logging if required. 2. Generate scenarios using an Executor. 3. Calculate split values for different scenario types. 4. Generate samples for each scenario. 5. Compile the results into an EvaluationDataset.
Source code in src/ragas/testset/synthesizers/generate.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|