ollama-haskell-0.2.0.0: Haskell client for ollama.
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <[email protected]>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.Ollama.Embeddings

Description

This module provides functions to generate text embeddings from an Ollama model. It includes both high-level (embedding, embeddingM) and low-level (embeddingOps, embeddingOpsM) APIs for generating embeddings, with support for customizing model options, truncation, and keep-alive settings. The embeddings are returned as a list of float vectors, suitable for tasks like semantic search or text similarity analysis.

The EmbeddingOps type configures the embedding request, and EmbeddingResp represents the response containing the model name and the generated embeddings. The defaultEmbeddingOps provides a default configuration for convenience.

Example:

>>> embedding "llama3.2" ["Hello, world!"]
Right (EmbeddingResp "llama3.2" [[0.1, 0.2, ...]])
Synopsis

Embedding API

embedding Source #

Arguments

:: Text

Model name

-> [Text]

List of input texts

-> IO (Either OllamaError EmbeddingResp) 

Simplified API for generating embeddings.

A higher-level function that generates embeddings using default settings for truncation, keep-alive, model options, and Ollama configuration. Suitable for basic use cases.

embeddingOps Source #

Arguments

:: Text

Model name

-> [Text]

List of input texts

-> Maybe Bool

Optional truncation flag

-> Maybe Int

Optional keep-alive timeout in minutes

-> Maybe ModelOptions

Optional model options

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError EmbeddingResp) 

Generates embeddings for a list of input texts with full configuration.

Sends a POST request to the "api/embed" endpoint to generate embeddings for the provided inputs. Allows customization of truncation, keep-alive settings, model options, and Ollama configuration. Returns Right with an EmbeddingResp on success or Left with an OllamaError on failure.

embeddingM :: MonadIO m => Text -> [Text] -> m (Either OllamaError EmbeddingResp) Source #

MonadIO version of embedding for use in monadic contexts.

Lifts the embedding function into a MonadIO context, allowing it to be used in monadic computations.

embeddingOpsM :: MonadIO m => Text -> [Text] -> Maybe Bool -> Maybe Int -> Maybe ModelOptions -> Maybe OllamaConfig -> m (Either OllamaError EmbeddingResp) Source #

MonadIO version of embeddingOps for use in monadic contexts.

Lifts the embeddingOps function into a MonadIO context, allowing it to be used in monadic computations with full configuration options.

Configuration and Response Types

defaultEmbeddingOps :: EmbeddingOps Source #

Default configuration for embedding requests.

Provides a default EmbeddingOps with the "llama3.2" model, an empty input list, and no additional options. Can be customized by modifying fields as needed.

data EmbeddingOps Source #

Configuration for an embedding request.

Constructors

EmbeddingOps 

Fields

data EmbeddingResp Source #

Response type for an embedding request.

Constructors

EmbeddingResp 

Fields

Model Options

defaultModelOptions :: ModelOptions Source #

Default model options for API requests.

Provides a default ModelOptions configuration with all fields set to Nothing, suitable as a starting point for customizing model parameters like temperature or token limits.

Example:

>>> let opts = defaultModelOptions { temperature = Just 0.7 }