跳过内容

检索器

基础类:QueryComponent

检索器组件。

参数

名称 类型 描述 默认值
retriever BaseRetriever

检索器

必填
源代码位于 llama-index-core/llama_index/core/base/base_retriever.py
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
class RetrieverComponent(QueryComponent):
    """Retriever component."""

    model_config = ConfigDict(arbitrary_types_allowed=True)
    retriever: BaseRetriever = Field(..., description="Retriever")

    def set_callback_manager(self, callback_manager: CallbackManager) -> None:
        """Set callback manager."""
        self.retriever.callback_manager = callback_manager

    def _validate_component_inputs(self, input: Dict[str, Any]) -> Dict[str, Any]:
        """Validate component inputs during run_component."""
        # make sure input is a string
        input["input"] = validate_and_convert_stringable(input["input"])
        return input

    def _run_component(self, **kwargs: Any) -> Any:
        """Run component."""
        output = self.retriever.retrieve(kwargs["input"])
        return {"output": output}

    async def _arun_component(self, **kwargs: Any) -> Any:
        """Run component."""
        output = await self.retriever.aretrieve(kwargs["input"])
        return {"output": output}

    @property
    def input_keys(self) -> InputKeys:
        """Input keys."""
        return InputKeys.from_keys({"input"})

    @property
    def output_keys(self) -> OutputKeys:
        """Output keys."""
        return OutputKeys.from_keys({"output"})

input_keys property #

input_keys: InputKeys

输入键。

output_keys property #

output_keys: OutputKeys

输出键。

set_callback_manager #

set_callback_manager(callback_manager: CallbackManager) -> None

设置回调管理器。

源代码位于 llama-index-core/llama_index/core/base/base_retriever.py
323
324
325
def set_callback_manager(self, callback_manager: CallbackManager) -> None:
    """Set callback manager."""
    self.retriever.callback_manager = callback_manager