跳到内容

查询转换

Bases: QueryComponent

查询转换组件。

参数

名称 类型 描述 默认值
query_transform BaseQueryTransform

查询转换。

必需
源代码位于 llama-index-core/llama_index/core/indices/query/query_transform/base.py
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
class QueryTransformComponent(QueryComponent):
    """Query transform component."""

    model_config = ConfigDict(arbitrary_types_allowed=True)
    query_transform: BaseQueryTransform = Field(..., description="Query transform.")

    def set_callback_manager(self, callback_manager: Any) -> None:
        """Set callback manager."""
        # TODO: not implemented yet

    def _validate_component_inputs(self, input: Dict[str, Any]) -> Dict[str, Any]:
        """Validate component inputs during run_component."""
        if "query_str" not in input:
            raise ValueError("Input must have key 'query_str'")
        input["query_str"] = validate_and_convert_stringable(input["query_str"])

        input["metadata"] = input.get("metadata", {})

        return input

    def _run_component(self, **kwargs: Any) -> Any:
        """Run component."""
        output = self.query_transform.run(
            kwargs["query_str"],
            metadata=kwargs["metadata"],
        )
        return {"query_str": output.query_str}

    async def _arun_component(self, **kwargs: Any) -> Any:
        """Run component."""
        # TODO: true async not implemented yet
        return self._run_component(**kwargs)

    @property
    def input_keys(self) -> InputKeys:
        """Input keys."""
        return InputKeys.from_keys({"query_str"}, optional_keys={"metadata"})

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

input_keys property #

input_keys: InputKeys

输入键。

output_keys property #

output_keys: OutputKeys

输出键。

set_callback_manager #

set_callback_manager(callback_manager: Any) -> None

设置回调管理器。

源代码位于 llama-index-core/llama_index/core/indices/query/query_transform/base.py
342
343
def set_callback_manager(self, callback_manager: Any) -> None:
    """Set callback manager."""