Skip to content

ollama_embedding_driver

OllamaEmbeddingDriver

Bases: BaseEmbeddingDriver

Ollama Embedding Driver.

Attributes:

Name Type Description
model str

Ollama embedding model name.

host Optional[str]

Optional Ollama host.

client Client

Ollama Client.

Source code in griptape/drivers/embedding/ollama_embedding_driver.py
@define
class OllamaEmbeddingDriver(BaseEmbeddingDriver):
    """Ollama Embedding Driver.

    Attributes:
        model: Ollama embedding model name.
        host: Optional Ollama host.
        client: Ollama `Client`.
    """

    model: str = field(kw_only=True, metadata={"serializable": True})
    host: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True})
    _client: Client = field(default=None, kw_only=True, alias="client", metadata={"serializable": False})

    @lazy_property()
    def client(self) -> Client:
        return import_optional_dependency("ollama").Client(host=self.host)

    def try_embed_chunk(self, chunk: str) -> list[float]:
        return list(self.client.embeddings(model=self.model, prompt=chunk)["embedding"])

host: Optional[str] = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

model: str = field(kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

client()

Source code in griptape/drivers/embedding/ollama_embedding_driver.py
@lazy_property()
def client(self) -> Client:
    return import_optional_dependency("ollama").Client(host=self.host)

try_embed_chunk(chunk)

Source code in griptape/drivers/embedding/ollama_embedding_driver.py
def try_embed_chunk(self, chunk: str) -> list[float]:
    return list(self.client.embeddings(model=self.model, prompt=chunk)["embedding"])