Skip to content

Ollama query engine

OllamaQueryEnginePack #

Bases: BaseLlamaPack

Source code in llama_index/packs/ollama_query_engine/base.py
15
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
class OllamaQueryEnginePack(BaseLlamaPack):
    def __init__(
        self,
        model: str,
        base_url: str = DEFAULT_OLLAMA_BASE_URL,
        documents: List[Document] = None,
    ) -> None:
        self._model = model
        self._base_url = base_url

        llm = Ollama(model=self._model, base_url=self._base_url)

        embed_model = OllamaEmbedding(model_name=self._model, base_url=self._base_url)

        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/ollama_query_engine/base.py
36
37
38
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/ollama_query_engine/base.py
40
41
42
43
def run(self, query_str: str, **kwargs: Any) -> Any:
    """运行流水线。"""
    query_engine = self.index.as_query_engine(**kwargs)
    return query_engine.query(query_str)