Skip to content

Index

数据集模块。

BaseLlamaDataExample #

Bases: BaseModel

基础的羊驼数据集示例类。

Source code in llama_index/core/llama_dataset/base.py
54
55
56
57
58
59
60
61
class BaseLlamaDataExample(BaseModel):
    """基础的羊驼数据集示例类。"""

    @property
    @abstractmethod
    def class_name(self) -> str:
        """类名。"""
        return "BaseLlamaDataExample"

class_name abstractmethod property #

class_name: str

类名。

BaseLlamaDataset #

Bases: BaseModel, Generic[P]

Source code in llama_index/core/llama_dataset/base.py
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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
class BaseLlamaDataset(BaseModel, Generic[P]):
    _example_type: Type[BaseLlamaDataExample] = BaseLlamaDataExample  # type: ignore[misc]
    examples: List[BaseLlamaDataExample] = Field(
        default=[], description="Data examples of this dataset."
    )
    _predictions_cache: List[BaseLlamaExamplePrediction] = PrivateAttr(
        default_factory=list
    )

    def __getitem__(self, val: Union[slice, int]) -> List[BaseLlamaDataExample]:
        """启用切片和索引。

返回`examples`上的所需切片。
"""
        return self.examples[val]

    @abstractmethod
    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""

    def save_json(self, path: str) -> None:
        """保存json。"""
        with open(path, "w") as f:
            examples = [self._example_type.dict(el) for el in self.examples]
            data = {
                "examples": examples,
            }

            json.dump(data, f, indent=4)

    @classmethod
    def from_json(cls, path: str) -> "BaseLlamaDataset":
        """加载json。"""
        with open(path) as f:
            data = json.load(f)

        examples = [cls._example_type.parse_obj(el) for el in data["examples"]]

        return cls(
            examples=examples,
        )

    @abstractmethod
    def _construct_prediction_dataset(
        self, predictions: List[BaseLlamaExamplePrediction]
    ) -> BaseLlamaPredictionDataset:
        """构建特定的预测数据集。

Args:
    predictions (List[BaseLlamaExamplePrediction]): 预测列表。

Returns:
    BaseLlamaPredictionDataset: 一个包含预测的数据集。
"""

    @abstractmethod
    def _predict_example(
        self,
        predictor: P,
        example: BaseLlamaDataExample,
        sleep_time_in_seconds: int = 0,
    ) -> BaseLlamaExamplePrediction:
        """在单个示例上进行预测。

注意:子类需要实现这个方法。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    example (BaseLlamaDataExample): 要进行预测的示例。

Returns:
    BaseLlamaExamplePrediction: 预测结果。
"""

    def make_predictions_with(
        self,
        predictor: P,
        show_progress: bool = False,
        batch_size: int = 20,
        sleep_time_in_seconds: int = 0,
    ) -> BaseLlamaPredictionDataset:
        """使用给定的查询引擎进行预测。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    show_progress (bool, optional): 显示预测进度。
    batch_size (int): 用于批量异步调用,特别是为了减少因openai而出现RateLimitError的机会。
    sleep_time_in_seconds (int): 在批量调用之间休眠的时间量,以减少因openai而出现RateLimitError的机会。

Returns:
    BaseLlamaPredictionDataset: 一个预测数据集。
"""
        if self._predictions_cache:
            start_example_position = len(self._predictions_cache)
        else:
            start_example_position = 0

        for batch in self._batch_examples(
            batch_size=batch_size, start_position=start_example_position
        ):
            if show_progress:
                example_iterator = tqdm.tqdm(batch)
            else:
                example_iterator = batch
            for example in example_iterator:
                self._predictions_cache.append(
                    self._predict_example(predictor, example, sleep_time_in_seconds)
                )

        return self._construct_prediction_dataset(predictions=self._predictions_cache)

    # async methods
    @abstractmethod
    async def _apredict_example(
        self,
        predictor: P,
        example: BaseLlamaDataExample,
        sleep_time_in_seconds: int,
    ) -> BaseLlamaExamplePrediction:
        """异步预测单个样本。

注意:子类需要实现这个方法。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    example (BaseLlamaDataExample): 要进行预测的样本。

Returns:
    BaseLlamaExamplePrediction: 预测结果。
"""

    def _batch_examples(
        self,
        batch_size: int = 20,
        start_position: int = 0,
    ) -> Generator[List[BaseLlamaDataExample], None, None]:
        """使用给定的batch_size对示例和预测进行分批处理。"""
        num_examples = len(self.examples)
        for ndx in range(start_position, num_examples, batch_size):
            yield self.examples[ndx : min(ndx + batch_size, num_examples)]

    async def amake_predictions_with(
        self,
        predictor: P,
        show_progress: bool = False,
        batch_size: int = 20,
        sleep_time_in_seconds: int = 1,
    ) -> BaseLlamaPredictionDataset:
        """使用给定的查询引擎进行异步预测。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    show_progress (bool, 可选): 显示预测进度。
    batch_size (int): 用于批量异步调用,特别是为了减少因openai而触发RateLimitError的机会。
    sleep_time_in_seconds (int): 在批量调用之间休眠的时间量,以减少因openai而触发RateLimitError的机会。

Returns:
    BaseLlamaPredictionDataset: 预测的数据集。
"""
        if self._predictions_cache:
            start_example_position = len(self._predictions_cache)
        else:
            start_example_position = 0

        for batch in self._batch_examples(
            batch_size=batch_size, start_position=start_example_position
        ):
            tasks = []
            for example in batch:
                tasks.append(
                    self._apredict_example(predictor, example, sleep_time_in_seconds)
                )
            asyncio_mod = asyncio_module(show_progress=show_progress)

            try:
                if show_progress:
                    batch_predictions = await asyncio_mod.gather(
                        *tasks, desc="Batch processing of predictions"
                    )
                else:
                    batch_predictions = await asyncio_mod.gather(*tasks)
            except RateLimitError as err:
                if show_progress:
                    asyncio_mod.close()
                raise ValueError(
                    "You've hit rate limits on your OpenAI subscription. This"
                    " class caches previous predictions after each successful"
                    " batch execution. Based off this cache, when executing this"
                    " command again it will attempt to predict on only the examples "
                    "that have not yet been predicted. Try reducing your batch_size."
                ) from err
            self._predictions_cache += batch_predictions
            # time.sleep(sleep_time_in_seconds)

        prediction_dataset = self._construct_prediction_dataset(
            predictions=self._predictions_cache
        )
        self._predictions_cache = []  # clear cache
        return prediction_dataset

    @property
    @abstractmethod
    def class_name(self) -> str:
        """类名。"""
        return "BaseLlamaDataset"

class_name abstractmethod property #

class_name: str

类名。

to_pandas abstractmethod #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/base.py
130
131
132
@abstractmethod
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""

save_json #

save_json(path: str) -> None

保存json。

Source code in llama_index/core/llama_dataset/base.py
134
135
136
137
138
139
140
141
142
def save_json(self, path: str) -> None:
    """保存json。"""
    with open(path, "w") as f:
        examples = [self._example_type.dict(el) for el in self.examples]
        data = {
            "examples": examples,
        }

        json.dump(data, f, indent=4)

from_json classmethod #

from_json(path: str) -> BaseLlamaDataset

加载json。

Source code in llama_index/core/llama_dataset/base.py
144
145
146
147
148
149
150
151
152
153
154
@classmethod
def from_json(cls, path: str) -> "BaseLlamaDataset":
    """加载json。"""
    with open(path) as f:
        data = json.load(f)

    examples = [cls._example_type.parse_obj(el) for el in data["examples"]]

    return cls(
        examples=examples,
    )

make_predictions_with #

make_predictions_with(
    predictor: P,
    show_progress: bool = False,
    batch_size: int = 20,
    sleep_time_in_seconds: int = 0,
) -> BaseLlamaPredictionDataset

使用给定的查询引擎进行预测。

Parameters:

Name Type Description Default
predictor PredictorType

用于进行预测的预测器。

required
show_progress bool

显示预测进度。

False
batch_size int

用于批量异步调用,特别是为了减少因openai而出现RateLimitError的机会。

20
sleep_time_in_seconds int

在批量调用之间休眠的时间量,以减少因openai而出现RateLimitError的机会。

0

Returns:

Name Type Description
BaseLlamaPredictionDataset BaseLlamaPredictionDataset

一个预测数据集。

Source code in llama_index/core/llama_dataset/base.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
    def make_predictions_with(
        self,
        predictor: P,
        show_progress: bool = False,
        batch_size: int = 20,
        sleep_time_in_seconds: int = 0,
    ) -> BaseLlamaPredictionDataset:
        """使用给定的查询引擎进行预测。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    show_progress (bool, optional): 显示预测进度。
    batch_size (int): 用于批量异步调用,特别是为了减少因openai而出现RateLimitError的机会。
    sleep_time_in_seconds (int): 在批量调用之间休眠的时间量,以减少因openai而出现RateLimitError的机会。

Returns:
    BaseLlamaPredictionDataset: 一个预测数据集。
"""
        if self._predictions_cache:
            start_example_position = len(self._predictions_cache)
        else:
            start_example_position = 0

        for batch in self._batch_examples(
            batch_size=batch_size, start_position=start_example_position
        ):
            if show_progress:
                example_iterator = tqdm.tqdm(batch)
            else:
                example_iterator = batch
            for example in example_iterator:
                self._predictions_cache.append(
                    self._predict_example(predictor, example, sleep_time_in_seconds)
                )

        return self._construct_prediction_dataset(predictions=self._predictions_cache)

amake_predictions_with async #

amake_predictions_with(
    predictor: P,
    show_progress: bool = False,
    batch_size: int = 20,
    sleep_time_in_seconds: int = 1,
) -> BaseLlamaPredictionDataset

使用给定的查询引擎进行异步预测。

Parameters:

Name Type Description Default
predictor PredictorType

用于进行预测的预测器。

required
show_progress (bool, 可选)

显示预测进度。

False
batch_size int

用于批量异步调用,特别是为了减少因openai而触发RateLimitError的机会。

20
sleep_time_in_seconds int

在批量调用之间休眠的时间量,以减少因openai而触发RateLimitError的机会。

1

Returns:

Name Type Description
BaseLlamaPredictionDataset BaseLlamaPredictionDataset

预测的数据集。

Source code in llama_index/core/llama_dataset/base.py
255
256
257
258
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
    async def amake_predictions_with(
        self,
        predictor: P,
        show_progress: bool = False,
        batch_size: int = 20,
        sleep_time_in_seconds: int = 1,
    ) -> BaseLlamaPredictionDataset:
        """使用给定的查询引擎进行异步预测。

Args:
    predictor (PredictorType): 用于进行预测的预测器。
    show_progress (bool, 可选): 显示预测进度。
    batch_size (int): 用于批量异步调用,特别是为了减少因openai而触发RateLimitError的机会。
    sleep_time_in_seconds (int): 在批量调用之间休眠的时间量,以减少因openai而触发RateLimitError的机会。

Returns:
    BaseLlamaPredictionDataset: 预测的数据集。
"""
        if self._predictions_cache:
            start_example_position = len(self._predictions_cache)
        else:
            start_example_position = 0

        for batch in self._batch_examples(
            batch_size=batch_size, start_position=start_example_position
        ):
            tasks = []
            for example in batch:
                tasks.append(
                    self._apredict_example(predictor, example, sleep_time_in_seconds)
                )
            asyncio_mod = asyncio_module(show_progress=show_progress)

            try:
                if show_progress:
                    batch_predictions = await asyncio_mod.gather(
                        *tasks, desc="Batch processing of predictions"
                    )
                else:
                    batch_predictions = await asyncio_mod.gather(*tasks)
            except RateLimitError as err:
                if show_progress:
                    asyncio_mod.close()
                raise ValueError(
                    "You've hit rate limits on your OpenAI subscription. This"
                    " class caches previous predictions after each successful"
                    " batch execution. Based off this cache, when executing this"
                    " command again it will attempt to predict on only the examples "
                    "that have not yet been predicted. Try reducing your batch_size."
                ) from err
            self._predictions_cache += batch_predictions
            # time.sleep(sleep_time_in_seconds)

        prediction_dataset = self._construct_prediction_dataset(
            predictions=self._predictions_cache
        )
        self._predictions_cache = []  # clear cache
        return prediction_dataset

BaseLlamaExamplePrediction #

Bases: BaseModel

基础的羊驼数据集示例类。

Source code in llama_index/core/llama_dataset/base.py
44
45
46
47
48
49
50
51
class BaseLlamaExamplePrediction(BaseModel):
    """基础的羊驼数据集示例类。"""

    @property
    @abstractmethod
    def class_name(self) -> str:
        """类名。"""
        return "BaseLlamaPrediction"

class_name abstractmethod property #

class_name: str

类名。

BaseLlamaPredictionDataset #

Bases: BaseModel

Source code in llama_index/core/llama_dataset/base.py
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class BaseLlamaPredictionDataset(BaseModel):
    _prediction_type: Type[BaseLlamaExamplePrediction] = BaseLlamaExamplePrediction  # type: ignore[misc]
    predictions: List[BaseLlamaExamplePrediction] = Field(
        default=list, description="Predictions on train_examples."
    )

    def __getitem__(self, val: Union[slice, int]) -> List[BaseLlamaExamplePrediction]:
        """启用切片和索引。

返回`predictions`上的所需切片。
"""
        return self.predictions[val]

    @abstractmethod
    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""

    def save_json(self, path: str) -> None:
        """保存json。"""
        with open(path, "w") as f:
            predictions = None
            if self.predictions:
                predictions = [
                    self._prediction_type.dict(el) for el in self.predictions
                ]
            data = {
                "predictions": predictions,
            }

            json.dump(data, f, indent=4)

    @classmethod
    def from_json(cls, path: str) -> "BaseLlamaPredictionDataset":
        """加载json。"""
        with open(path) as f:
            data = json.load(f)

        predictions = [cls._prediction_type.parse_obj(el) for el in data["predictions"]]

        return cls(
            predictions=predictions,
        )

    @property
    @abstractmethod
    def class_name(self) -> str:
        """类名。"""
        return "BaseLlamaPredictionDataset"

class_name abstractmethod property #

class_name: str

类名。

to_pandas abstractmethod #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/base.py
77
78
79
@abstractmethod
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""

save_json #

save_json(path: str) -> None

保存json。

Source code in llama_index/core/llama_dataset/base.py
81
82
83
84
85
86
87
88
89
90
91
92
93
def save_json(self, path: str) -> None:
    """保存json。"""
    with open(path, "w") as f:
        predictions = None
        if self.predictions:
            predictions = [
                self._prediction_type.dict(el) for el in self.predictions
            ]
        data = {
            "predictions": predictions,
        }

        json.dump(data, f, indent=4)

from_json classmethod #

from_json(path: str) -> BaseLlamaPredictionDataset

加载json。

Source code in llama_index/core/llama_dataset/base.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def from_json(cls, path: str) -> "BaseLlamaPredictionDataset":
    """加载json。"""
    with open(path) as f:
        data = json.load(f)

    predictions = [cls._prediction_type.parse_obj(el) for el in data["predictions"]]

    return cls(
        predictions=predictions,
    )

CreatedByType #

Bases: str, Enum

例子中的原始数据类型。

Source code in llama_index/core/llama_dataset/base.py
21
22
23
24
25
26
27
28
class CreatedByType(str, Enum):
    """例子中的原始数据类型。"""

    HUMAN = "human"
    AI = "ai"

    def __str__(self) -> str:
        return self.value

EvaluatorExamplePrediction #

Bases: BaseLlamaExamplePrediction

评估示例预测类。

Parameters:

Name Type Description Default
feedback 可选[str]

评估者的反馈。

required
score 可选[float]

评估者的分数。

required
Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class EvaluatorExamplePrediction(BaseLlamaExamplePrediction):
    """评估示例预测类。

    Args:
        feedback (可选[str]): 评估者的反馈。
        score (可选[float]): 评估者的分数。"""

    feedback: str = Field(
        default_factory=str,
        description="The generated (predicted) response that can be compared to a reference (ground-truth) answer.",
    )
    score: Optional[float] = Field(
        default=None,
        description="The generated (predicted) response that can be compared to a reference (ground-truth) answer.",
    )
    invalid_prediction: bool = Field(
        default=False, description="Whether or not the prediction is a valid one."
    )
    invalid_reason: Optional[str] = Field(
        default=None, description="Reason as to why prediction is invalid."
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "EvaluatorExamplePrediction"

class_name property #

class_name: str

数据示例类名称。

EvaluatorPredictionDataset #

Bases: BaseLlamaPredictionDataset

评估预测数据集类。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class EvaluatorPredictionDataset(BaseLlamaPredictionDataset):
    """评估预测数据集类。"""

    _prediction_type = EvaluatorExamplePrediction

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {}
        if self.predictions:
            data = {
                "feedback": [t.feedback for t in self.predictions],
                "score": [t.score for t in self.predictions],
            }

        return PandasDataFrame(data)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "EvaluatorPredictionDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
114
115
116
117
118
119
120
121
122
123
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {}
    if self.predictions:
        data = {
            "feedback": [t.feedback for t in self.predictions],
            "score": [t.score for t in self.predictions],
        }

    return PandasDataFrame(data)

LabelledEvaluatorDataExample #

Bases: BaseLlamaDataExample

评估示例类。

该数据类包含执行新的“预测”即评估所需的要素。在这里,评估器旨在评估响应与相关查询以及可选上下文。

Parameters:

Name Type Description Default
query str

用户查询

required
query_by CreatedBy

由人类或AI生成的查询(模型名称)

required
contexts Optional[List[str]]

用于响应的上下文

required
answer str

要评估的查询的答案。

required
answer_by

由人类或AI生成的参考答案(模型名称)。

required
ground_truth_answer Optional[str]
required
ground_truth_answer_by Optional[CreatedBy]
required
reference_feedback str

参考反馈评估。

required
reference_score float

参考分数评估。

required
reference_evaluation_by CreatedBy

由人类或AI生成的评估(模型名称)

required
Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
class LabelledEvaluatorDataExample(BaseLlamaDataExample):
    """评估示例类。

    该数据类包含执行新的“预测”即评估所需的要素。在这里,评估器旨在评估响应与相关查询以及可选上下文。

    Args:
        query (str): 用户查询
        query_by (CreatedBy): 由人类或AI生成的查询(模型名称)
        contexts (Optional[List[str]]): 用于响应的上下文
        answer (str): 要评估的查询的答案。
        answer_by: 由人类或AI生成的参考答案(模型名称)。
        ground_truth_answer (Optional[str]):
        ground_truth_answer_by (Optional[CreatedBy]):
        reference_feedback (str): 参考反馈评估。
        reference_score (float): 参考分数评估。
        reference_evaluation_by (CreatedBy): 由人类或AI生成的评估(模型名称)"""

    query: str = Field(
        default_factory=str, description="The user query for the example."
    )
    query_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the query."
    )
    contexts: Optional[List[str]] = Field(
        default_factory=None,
        description="The contexts used to generate the answer.",
    )
    answer: str = Field(
        default_factory=str,
        description="The provided answer to the example that is to be evaluated.",
    )
    answer_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the answer."
    )
    ground_truth_answer: Optional[str] = Field(
        default=None,
        description="The ground truth answer to the example that is used to evaluate the provided `answer`.",
    )
    ground_truth_answer_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the ground-truth answer."
    )
    reference_feedback: Optional[str] = Field(
        default=None,
        description="The reference feedback (ground-truth).",
    )
    reference_score: float = Field(
        default_factory=float, description="The reference score (ground-truth)."
    )
    reference_evaluation_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the evaluation (feedback and score)."
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "LabelledEvaluatorDataExample"

class_name property #

class_name: str

数据示例类名称。

LabelledEvaluatorDataset #

Bases: BaseLlamaDataset[BaseEvaluator]

标记评估数据集类。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
class LabelledEvaluatorDataset(BaseLlamaDataset[BaseEvaluator]):
    """标记评估数据集类。"""

    _example_type = LabelledEvaluatorDataExample

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {
            "query": [t.query for t in self.examples],
            "answer": [t.answer for t in self.examples],
            "contexts": [t.contexts for t in self.examples],
            "ground_truth_answer": [t.ground_truth_answer for t in self.examples],
            "query_by": [str(t.query_by) for t in self.examples],
            "answer_by": [str(t.answer_by) for t in self.examples],
            "ground_truth_answer_by": [
                str(t.ground_truth_answer_by) for t in self.examples
            ],
            "reference_feedback": [t.reference_feedback for t in self.examples],
            "reference_score": [t.reference_score for t in self.examples],
            "reference_evaluation_by": [
                t.reference_evaluation_by for t in self.examples
            ],
        }

        return PandasDataFrame(data)

    async def _apredict_example(
        self,
        predictor: BaseEvaluator,
        example: LabelledEvaluatorDataExample,
        sleep_time_in_seconds: int,
    ) -> EvaluatorExamplePrediction:
        """使用查询引擎进行异步预测RAG示例。"""
        await asyncio.sleep(sleep_time_in_seconds)
        try:
            eval_result: EvaluationResult = await predictor.aevaluate(
                query=example.query,
                response=example.answer,
                contexts=example.contexts,
                reference=example.ground_truth_answer,
                sleep_time_in_seconds=sleep_time_in_seconds,
            )
        except Exception as err:
            # TODO: raise warning here as well
            return EvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=f"Caught error {err!s}"
            )

        if not eval_result.invalid_result:
            return EvaluatorExamplePrediction(
                feedback=eval_result.feedback, score=eval_result.score
            )
        else:
            return EvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=eval_result.invalid_reason
            )

    def _predict_example(
        self,
        predictor: BaseEvaluator,
        example: LabelledEvaluatorDataExample,
        sleep_time_in_seconds: int = 0,
    ) -> EvaluatorExamplePrediction:
        """使用查询引擎预测RAG示例。"""
        time.sleep(sleep_time_in_seconds)
        try:
            eval_result: EvaluationResult = predictor.evaluate(
                query=example.query,
                response=example.answer,
                contexts=example.contexts,
                reference=example.ground_truth_answer,
                sleep_time_in_seconds=sleep_time_in_seconds,
            )
        except Exception as err:
            # TODO: raise warning here as well
            return EvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=f"Caught error {err!s}"
            )

        if not eval_result.invalid_result:
            return EvaluatorExamplePrediction(
                feedback=eval_result.feedback, score=eval_result.score
            )
        else:
            return EvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=eval_result.invalid_reason
            )

    def _construct_prediction_dataset(
        self, predictions: List[EvaluatorExamplePrediction]
    ) -> EvaluatorPredictionDataset:
        """构建预测数据集。"""
        return EvaluatorPredictionDataset(predictions=predictions)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "LabelledEvaluatorDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {
        "query": [t.query for t in self.examples],
        "answer": [t.answer for t in self.examples],
        "contexts": [t.contexts for t in self.examples],
        "ground_truth_answer": [t.ground_truth_answer for t in self.examples],
        "query_by": [str(t.query_by) for t in self.examples],
        "answer_by": [str(t.answer_by) for t in self.examples],
        "ground_truth_answer_by": [
            str(t.ground_truth_answer_by) for t in self.examples
        ],
        "reference_feedback": [t.reference_feedback for t in self.examples],
        "reference_score": [t.reference_score for t in self.examples],
        "reference_evaluation_by": [
            t.reference_evaluation_by for t in self.examples
        ],
    }

    return PandasDataFrame(data)

LabelledPairwiseEvaluatorDataExample #

Bases: LabelledEvaluatorDataExample

标记的成对评估数据示例类。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
class LabelledPairwiseEvaluatorDataExample(LabelledEvaluatorDataExample):
    """标记的成对评估数据示例类。"""

    second_answer: str = Field(
        default_factory=str,
        description="The second answer to the example that is to be evaluated along versus `answer`.",
    )
    second_answer_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the second answer."
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "LabelledPairwiseEvaluatorDataExample"

class_name property #

class_name: str

数据示例类名称。

LabelledPairwiseEvaluatorDataset #

Bases: BaseLlamaDataset[BaseEvaluator]

标记的成对评估数据集。用于评估执行成对评估的评估者。

Parameters:

Name Type Description Default
BaseLlamaDataset _type_

description

required
Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
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
class LabelledPairwiseEvaluatorDataset(BaseLlamaDataset[BaseEvaluator]):
    """标记的成对评估数据集。用于评估执行成对评估的评估者。

    Args:
        BaseLlamaDataset (_type_): _description_"""

    _example_type = LabelledPairwiseEvaluatorDataExample

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {
            "query": [t.query for t in self.examples],
            "answer": [t.answer for t in self.examples],
            "second_answer": [t.second_answer for t in self.examples],
            "contexts": [t.contexts for t in self.examples],
            "ground_truth_answer": [t.ground_truth_answer for t in self.examples],
            "query_by": [str(t.query_by) for t in self.examples],
            "answer_by": [str(t.answer_by) for t in self.examples],
            "second_answer_by": [str(t.second_answer_by) for t in self.examples],
            "ground_truth_answer_by": [
                str(t.ground_truth_answer_by) for t in self.examples
            ],
            "reference_feedback": [t.reference_feedback for t in self.examples],
            "reference_score": [t.reference_score for t in self.examples],
            "reference_evaluation_by": [
                t.reference_evaluation_by for t in self.examples
            ],
        }

        return PandasDataFrame(data)

    async def _apredict_example(
        self,
        predictor: BaseEvaluator,
        example: LabelledPairwiseEvaluatorDataExample,
        sleep_time_in_seconds: int,
    ) -> PairwiseEvaluatorExamplePrediction:
        """使用Evaluator进行异步预测评估的示例。"""
        await asyncio.sleep(sleep_time_in_seconds)
        try:
            eval_result: EvaluationResult = await predictor.aevaluate(
                query=example.query,
                response=example.answer,
                second_response=example.second_answer,
                contexts=example.contexts,
                reference=example.ground_truth_answer,
                sleep_time_in_seconds=sleep_time_in_seconds,
            )
        except Exception as err:
            # TODO: raise warning here as well
            return PairwiseEvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=f"Caught error {err!s}"
            )

        if not eval_result.invalid_result:
            return PairwiseEvaluatorExamplePrediction(
                feedback=eval_result.feedback,
                score=eval_result.score,
                evaluation_source=eval_result.pairwise_source,
            )
        else:
            return PairwiseEvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=eval_result.invalid_reason
            )

    def _predict_example(
        self,
        predictor: BaseEvaluator,
        example: LabelledPairwiseEvaluatorDataExample,
        sleep_time_in_seconds: int = 0,
    ) -> PairwiseEvaluatorExamplePrediction:
        """使用查询引擎预测RAG示例。"""
        time.sleep(sleep_time_in_seconds)
        try:
            eval_result: EvaluationResult = predictor.evaluate(
                query=example.query,
                response=example.answer,
                second_response=example.second_answer,
                contexts=example.contexts,
                reference=example.ground_truth_answer,
                sleep_time_in_seconds=sleep_time_in_seconds,
            )
        except Exception as err:
            # TODO: raise warning here as well
            return PairwiseEvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=f"Caught error {err!s}"
            )

        if not eval_result.invalid_result:
            return PairwiseEvaluatorExamplePrediction(
                feedback=eval_result.feedback,
                score=eval_result.score,
                evaluation_source=eval_result.pairwise_source,
            )
        else:
            return PairwiseEvaluatorExamplePrediction(
                invalid_prediction=True, invalid_reason=eval_result.invalid_reason
            )

    def _construct_prediction_dataset(
        self, predictions: List[PairwiseEvaluatorExamplePrediction]
    ) -> PairwiseEvaluatorPredictionDataset:
        """构建预测数据集。"""
        return PairwiseEvaluatorPredictionDataset(predictions=predictions)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "LabelledPairwiseEvaluatorDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {
        "query": [t.query for t in self.examples],
        "answer": [t.answer for t in self.examples],
        "second_answer": [t.second_answer for t in self.examples],
        "contexts": [t.contexts for t in self.examples],
        "ground_truth_answer": [t.ground_truth_answer for t in self.examples],
        "query_by": [str(t.query_by) for t in self.examples],
        "answer_by": [str(t.answer_by) for t in self.examples],
        "second_answer_by": [str(t.second_answer_by) for t in self.examples],
        "ground_truth_answer_by": [
            str(t.ground_truth_answer_by) for t in self.examples
        ],
        "reference_feedback": [t.reference_feedback for t in self.examples],
        "reference_score": [t.reference_score for t in self.examples],
        "reference_evaluation_by": [
            t.reference_evaluation_by for t in self.examples
        ],
    }

    return PandasDataFrame(data)

PairwiseEvaluatorExamplePrediction #

Bases: BaseLlamaExamplePrediction

Pairwise evaluation example prediction class. 一对一评估示例预测类。

Parameters:

Name Type Description Default
feedback Optional[str]

评估者的反馈。

required
score Optional[float]

评估者的分数。

required
evaluation_source EvaluationSource

评估来源,原始顺序、翻转或不确定。

required
Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
class PairwiseEvaluatorExamplePrediction(BaseLlamaExamplePrediction):
    """Pairwise evaluation example prediction class.
一对一评估示例预测类。

Args:
    feedback (Optional[str]): 评估者的反馈。
    score (Optional[float]): 评估者的分数。
    evaluation_source (EvaluationSource): 评估来源,原始顺序、翻转或不确定。"""

    feedback: str = Field(
        default_factory=str,
        description="The generated (predicted) response that can be compared to a reference (ground-truth) answer.",
    )
    score: Optional[float] = Field(
        default=None,
        description="The generated (predicted) response that can be compared to a reference (ground-truth) answer.",
    )
    evaluation_source: Optional[EvaluationSource] = Field(
        default=None,
        description=(
            "Whether the evaluation comes from original, or flipped ordering. Can also be neither here indicating inconclusive judgement."
        ),
    )
    invalid_prediction: bool = Field(
        default=False, description="Whether or not the prediction is a valid one."
    )
    invalid_reason: Optional[str] = Field(
        default=None, description="Reason as to why prediction is invalid."
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "PairwiseEvaluatorExamplePrediction"

class_name property #

class_name: str

数据示例类名称。

PairwiseEvaluatorPredictionDataset #

Bases: BaseLlamaPredictionDataset

成对评估预测数据集类。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
class PairwiseEvaluatorPredictionDataset(BaseLlamaPredictionDataset):
    """成对评估预测数据集类。"""

    _prediction_type = PairwiseEvaluatorExamplePrediction

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {}
        if self.predictions:
            data = {
                "feedback": [t.feedback for t in self.predictions],
                "score": [t.score for t in self.predictions],
                "ordering": [t.evaluation_source.value for t in self.predictions],
            }

        return PandasDataFrame(data)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "PairwiseEvaluatorPredictionDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/evaluator_evaluation.py
272
273
274
275
276
277
278
279
280
281
282
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {}
    if self.predictions:
        data = {
            "feedback": [t.feedback for t in self.predictions],
            "score": [t.score for t in self.predictions],
            "ordering": [t.evaluation_source.value for t in self.predictions],
        }

    return PandasDataFrame(data)

LabelledRagDataExample #

Bases: BaseLlamaDataExample

RAG示例类。类似于传统的ML数据集,该数据集包含用于进行预测的“特征”(即查询+上下文)和用于评估预测的“标签”(即响应)。

Source code in llama_index/core/llama_dataset/rag.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class LabelledRagDataExample(BaseLlamaDataExample):
    """RAG示例类。类似于传统的ML数据集,该数据集包含用于进行预测的“特征”(即查询+上下文)和用于评估预测的“标签”(即响应)。

Args:
    query(str):用户查询
    query_by(CreatedBy):由人类或AI生成的查询(模型名称)
    reference_contexts(Optional[List[str]]):用于响应的上下文
    reference_answer([str]):查询的参考答案。在评估时将获得满分的答案。
    reference_answer_by:由人类或AI生成的参考答案(模型名称)。"""

    query: str = Field(
        default_factory=str, description="The user query for the example."
    )
    query_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the query."
    )
    reference_contexts: Optional[List[str]] = Field(
        default_factory=None,
        description="The contexts used to generate the reference answer.",
    )
    reference_answer: str = Field(
        default_factory=str,
        description="The reference (ground-truth) answer to the example.",
    )
    reference_answer_by: Optional[CreatedBy] = Field(
        default=None, description="What generated the reference answer."
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "LabelledRagDataExample"

class_name property #

class_name: str

数据示例类名称。

LabelledRagDataset #

Bases: BaseLlamaDataset[BaseQueryEngine]

RagDataset类。

Source code in llama_index/core/llama_dataset/rag.py
 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
class LabelledRagDataset(BaseLlamaDataset[BaseQueryEngine]):
    """RagDataset类。"""

    _example_type = LabelledRagDataExample

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {
            "query": [t.query for t in self.examples],
            "reference_contexts": [t.reference_contexts for t in self.examples],
            "reference_answer": [t.reference_answer for t in self.examples],
            "reference_answer_by": [str(t.reference_answer_by) for t in self.examples],
            "query_by": [str(t.query_by) for t in self.examples],
        }

        return PandasDataFrame(data)

    async def _apredict_example(
        self,
        predictor: BaseQueryEngine,
        example: LabelledRagDataExample,
        sleep_time_in_seconds: int,
    ) -> RagExamplePrediction:
        """使用查询引擎进行异步预测RAG示例。"""
        await asyncio.sleep(sleep_time_in_seconds)
        response = await predictor.aquery(example.query)
        return RagExamplePrediction(
            response=str(response), contexts=[s.text for s in response.source_nodes]
        )

    def _predict_example(
        self,
        predictor: BaseQueryEngine,
        example: LabelledRagDataExample,
        sleep_time_in_seconds: int = 0,
    ) -> RagExamplePrediction:
        """使用查询引擎预测RAG示例。"""
        time.sleep(sleep_time_in_seconds)
        response = predictor.query(example.query)
        return RagExamplePrediction(
            response=str(response), contexts=[s.text for s in response.source_nodes]
        )

    def _construct_prediction_dataset(
        self, predictions: List[RagExamplePrediction]
    ) -> RagPredictionDataset:
        """构建预测数据集。"""
        return RagPredictionDataset(predictions=predictions)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "LabelledRagDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/rag.py
102
103
104
105
106
107
108
109
110
111
112
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {
        "query": [t.query for t in self.examples],
        "reference_contexts": [t.reference_contexts for t in self.examples],
        "reference_answer": [t.reference_answer for t in self.examples],
        "reference_answer_by": [str(t.reference_answer_by) for t in self.examples],
        "query_by": [str(t.query_by) for t in self.examples],
    }

    return PandasDataFrame(data)

RagExamplePrediction #

Bases: BaseLlamaExamplePrediction

RAG示例预测类。

Parameters:

Name Type Description Default
response str

LLM生成的响应。

required
contexts Optional[List[str]]

用于生成响应的检索到的上下文(文本)。

required
Source code in llama_index/core/llama_dataset/rag.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class RagExamplePrediction(BaseLlamaExamplePrediction):
    """RAG示例预测类。

    Args:
        response (str): LLM生成的响应。
        contexts (Optional[List[str]]): 用于生成响应的检索到的上下文(文本)。"""

    response: str = Field(
        default_factory=str,
        description="The generated (predicted) response that can be compared to a reference (ground-truth) answer.",
    )
    contexts: Optional[List[str]] = Field(
        default_factory=None,
        description="The contexts in raw text form used to generate the response.",
    )

    @property
    def class_name(self) -> str:
        """数据示例类名称。"""
        return "RagExamplePrediction"

class_name property #

class_name: str

数据示例类名称。

RagPredictionDataset #

Bases: BaseLlamaPredictionDataset

RagDataset类。

Source code in llama_index/core/llama_dataset/rag.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class RagPredictionDataset(BaseLlamaPredictionDataset):
    """RagDataset类。"""

    _prediction_type = RagExamplePrediction

    def to_pandas(self) -> PandasDataFrame:
        """创建pandas数据框。"""
        data = {}
        if self.predictions:
            data = {
                "response": [t.response for t in self.predictions],
                "contexts": [t.contexts for t in self.predictions],
            }

        return PandasDataFrame(data)

    @property
    def class_name(self) -> str:
        """类名。"""
        return "RagPredictionDataset"

class_name property #

class_name: str

类名。

to_pandas #

to_pandas() -> DataFrame

创建pandas数据框。

Source code in llama_index/core/llama_dataset/rag.py
80
81
82
83
84
85
86
87
88
89
def to_pandas(self) -> PandasDataFrame:
    """创建pandas数据框。"""
    data = {}
    if self.predictions:
        data = {
            "response": [t.response for t in self.predictions],
            "contexts": [t.contexts for t in self.predictions],
        }

    return PandasDataFrame(data)

download_llama_dataset #

download_llama_dataset(
    llama_dataset_class: str,
    download_dir: str,
    llama_datasets_url: str = LLAMA_DATASETS_URL,
    llama_datasets_lfs_url: str = LLAMA_DATASETS_LFS_URL,
    llama_datasets_source_files_tree_url: str = LLAMA_DATASETS_SOURCE_FILES_GITHUB_TREE_URL,
    show_progress: bool = False,
    load_documents: bool = True,
) -> Tuple[Type[BaseLlamaDataset], List[Document]]

从datasets-LFS和llamahub下载数据集。

Parameters:

Name Type Description Default
dataset_class

您想要下载的llamadataset类的名称,例如PaulGrahamEssayDataset

required
custom_dir

要下载加载器的自定义目录名称(在父文件夹下)。

required
custom_path

要下载加载器的自定义目录路径。

required
llama_datasets_url str

从llama_datasets存储库获取普通文件的URL

LLAMA_DATASETS_URL
llama_datasets_lfs_url str

从llama_datasets存储库获取lfs-traced文件的URL

LLAMA_DATASETS_LFS_URL
llama_datasets_source_files_tree_url str

列出source_files内容的URL

LLAMA_DATASETS_SOURCE_FILES_GITHUB_TREE_URL
refresh_cache

如果为true,则将跳过本地缓存,并直接从远程存储库获取加载器。

required
source_files_dirpath

存储源文件的目录

required
library_path

库文件的文件名。

required
base_file_name

rag数据集的json文件

required
disable_library_cache

控制库缓存的布尔值

required
override_path

控制覆盖路径的布尔值

required
show_progress bool

控制是否显示下载源文件的进度的布尔值

False
load_documents bool

控制是否加载LabelledRagDataset的source_files的布尔值。

True

Returns:

Type Description
Tuple[Type[BaseLlamaDataset], List[Document]]

BaseLlamaDatasetList[Document]

Source code in llama_index/core/llama_dataset/download.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def download_llama_dataset(
    llama_dataset_class: str,
    download_dir: str,
    llama_datasets_url: str = LLAMA_DATASETS_URL,
    llama_datasets_lfs_url: str = LLAMA_DATASETS_LFS_URL,
    llama_datasets_source_files_tree_url: str = LLAMA_DATASETS_SOURCE_FILES_GITHUB_TREE_URL,
    show_progress: bool = False,
    load_documents: bool = True,
) -> Tuple[Type[BaseLlamaDataset], List[Document]]:
    """从datasets-LFS和llamahub下载数据集。

Args:
    dataset_class: 您想要下载的llamadataset类的名称,例如`PaulGrahamEssayDataset`。
    custom_dir: 要下载加载器的自定义目录名称(在父文件夹下)。
    custom_path: 要下载加载器的自定义目录路径。
    llama_datasets_url: 从llama_datasets存储库获取普通文件的URL
    llama_datasets_lfs_url: 从llama_datasets存储库获取lfs-traced文件的URL
    llama_datasets_source_files_tree_url: 列出source_files内容的URL
    refresh_cache: 如果为true,则将跳过本地缓存,并直接从远程存储库获取加载器。
    source_files_dirpath: 存储源文件的目录
    library_path: 库文件的文件名。
    base_file_name: rag数据集的json文件
    disable_library_cache: 控制库缓存的布尔值
    override_path: 控制覆盖路径的布尔值
    show_progress: 控制是否显示下载源文件的进度的布尔值
    load_documents: 控制是否加载LabelledRagDataset的source_files的布尔值。

Returns:
    `BaseLlamaDataset`和`List[Document]`
"""
    filenames: Tuple[str, str] = download(
        llama_dataset_class,
        llama_datasets_url=llama_datasets_url,
        llama_datasets_lfs_url=llama_datasets_lfs_url,
        llama_datasets_source_files_tree_url=llama_datasets_source_files_tree_url,
        refresh_cache=True,
        custom_path=download_dir,
        library_path="library.json",
        disable_library_cache=True,
        override_path=True,
        show_progress=show_progress,
    )
    dataset_filename, source_files_dir = filenames
    track_download(llama_dataset_class, MODULE_TYPE.DATASETS)

    dataset = _resolve_dataset_class(dataset_filename).from_json(dataset_filename)
    documents = []

    # for now only rag datasets need to provide the documents
    # in order to build an index over them
    if "rag_dataset.json" in dataset_filename and load_documents:
        documents = SimpleDirectoryReader(input_dir=source_files_dir).load_data(
            show_progress=show_progress
        )

    return (dataset, documents)