Skip to content

Voyage query engine

VoyageQueryEnginePack #

Bases: BaseLlamaPack

Source code in llama_index/packs/voyage_query_engine/base.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class VoyageQueryEnginePack(BaseLlamaPack):
    def __init__(self, documents: List[Document]) -> None:
        llm = OpenAI(model="gpt-4")
        embed_model = VoyageEmbedding(
            model_name="voyage-01", voyage_api_key=os.environ["VOYAGE_API_KEY"]
        )
        service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
        self.llm = llm
        self.index = VectorStoreIndex.from_documents(
            documents, service_context=service_context
        )

    def get_modules(self) -> Dict[str, Any]:
        """获取模块。"""
        return {"llm": self.llm, "index": self.index}

    def run(self, query_str: str, **kwargs: Any) -> Any:
        """运行流水线。"""
        query_engine = self.index.as_query_engine(**kwargs)
        return query_engine.query(query_str)

get_modules #

get_modules() -> Dict[str, Any]

获取模块。

Source code in llama_index/packs/voyage_query_engine/base.py
23
24
25
def get_modules(self) -> Dict[str, Any]:
    """获取模块。"""
    return {"llm": self.llm, "index": self.index}

run #

run(query_str: str, **kwargs: Any) -> Any

运行流水线。

Source code in llama_index/packs/voyage_query_engine/base.py
27
28
29
30
def run(self, query_str: str, **kwargs: Any) -> Any:
    """运行流水线。"""
    query_engine = self.index.as_query_engine(**kwargs)
    return query_engine.query(query_str)