ollama#

  • __all__ = ['OllamaEmbeddingDriver'] module-attribute

Bases: BaseEmbeddingDriver “)

Attributes#

Name

Type

Description

<a href="ollama.mdx#griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.model" title="model = field(kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.model)"><code class="language-python">model</code></a>

str

Ollama embedding model name.<br/>

<a href="ollama.mdx#griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.host" title="host = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.host)"><code class="language-python">host</code></a>

Optional[str]

Optional Ollama host.<br/>

<a href="ollama.mdx#griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.client" title="client() (griptape.drivers.embedding.ollama.OllamaEmbeddingDriver.client)"><code class="language-python">client</code></a>

Client

Ollama Client.<br/>

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: Optional[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, **kwargs) -> list[float]:
        return list(self.client.embeddings(model=self.model, prompt=chunk)["embedding"])
  • _client = field(default=None, kw_only=True, alias='client', metadata={'serializable': False}) class-attribute instance-attribute

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

  • model = 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, **kwargs)#

Source Code in griptape/drivers/embedding/ollama_embedding_driver.py

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