跳至内容

Arize phoenix 查询引擎

ArizePhoenixQueryEnginePack #

基础类: BaseLlamaPack

Arize-Phoenix LlamaPack展示了如何通过追踪功能来增强您的LlamaIndex查询引擎。它会在后台启动Phoenix,基于输入的节点列表构建索引,并在该索引上实例化并集成一个查询引擎,从而将每次查询的追踪数据发送至Phoenix平台。

注意:使用此LlamaPack需要将您的OpenAI API密钥通过OPENAI_API_KEY环境变量设置。

Source code in llama-index-packs/llama-index-packs-arize-phoenix-query-engine/llama_index/packs/arize_phoenix_query_engine/base.py
16
17
18
19
20
21
22
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
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
class ArizePhoenixQueryEnginePack(BaseLlamaPack):
    """
    The Arize-Phoenix LlamaPack show how to instrument your LlamaIndex query
    engine with tracing. It launches Phoenix in the background, builds an index
    over an input list of nodes, and instantiates and instruments a query engine
    over that index so that trace data from each query is sent to Phoenix.

    Note: Using this LlamaPack requires that your OpenAI API key is set via the
    OPENAI_API_KEY environment variable.
    """

    def __init__(
        self,
        nodes: List[TextNode],
        **kwargs: Any,
    ) -> None:
        """
        Initializes a new instance of ArizePhoenixQueryEnginePack.

        Args:
            nodes (List[TextNode]): An input list of nodes over which the index
            will be built.

        """
        try:
            import phoenix as px
        except ImportError:
            raise ImportError(
                "The arize-phoenix package could not be found. "
                "Please install with `pip install arize-phoenix`."
            )
        self._session: "PhoenixSession" = px.launch_app()
        set_global_handler("arize_phoenix")
        self._index = VectorStoreIndex(nodes, **kwargs)
        self._query_engine = self._index.as_query_engine()

    def get_modules(self) -> Dict[str, Any]:
        """
        Returns a dictionary containing the internals of the LlamaPack.

        Returns:
            Dict[str, Any]: A dictionary containing the internals of the
            LlamaPack.

        """
        return {
            "session": self._session,
            "session_url": self._session.url,
            "index": self._index,
            "query_engine": self._query_engine,
        }

    def run(self, *args: Any, **kwargs: Any) -> Any:
        """
        Runs queries against the index.

        Returns:
            Any: A response from the query engine.

        """
        return self._query_engine.query(*args, **kwargs)

get_modules #

get_modules() -> Dict[str, Any]

返回一个包含LlamaPack内部信息的字典。

返回:

类型 描述
Dict[str, Any]

Dict[str, Any]: 包含内部数据的字典

Dict[str, Any]

LlamaPack.

Source code in llama-index-packs/llama-index-packs-arize-phoenix-query-engine/llama_index/packs/arize_phoenix_query_engine/base.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def get_modules(self) -> Dict[str, Any]:
    """
    Returns a dictionary containing the internals of the LlamaPack.

    Returns:
        Dict[str, Any]: A dictionary containing the internals of the
        LlamaPack.

    """
    return {
        "session": self._session,
        "session_url": self._session.url,
        "index": self._index,
        "query_engine": self._query_engine,
    }

运行 #

run(*args: Any, **kwargs: Any) -> Any

对索引运行查询。

返回:

名称 类型 描述
Any Any

来自查询引擎的响应。

Source code in llama-index-packs/llama-index-packs-arize-phoenix-query-engine/llama_index/packs/arize_phoenix_query_engine/base.py
68
69
70
71
72
73
74
75
76
def run(self, *args: Any, **kwargs: Any) -> Any:
    """
    Runs queries against the index.

    Returns:
        Any: A response from the query engine.

    """
    return self._query_engine.query(*args, **kwargs)