gleamstral/embeddings

Types

pub type Config {
  Config(encoding_format: EncodingFormat)
}

Constructors

  • Config(encoding_format: EncodingFormat)
pub type EmbeddingData {
  EmbeddingData(index: Int, embedding: List(Float))
}

Constructors

  • EmbeddingData(index: Int, embedding: List(Float))

Represents an embeddings service with configuration options

Use this to generate vector embeddings for text inputs

pub type Embeddings {
  Embeddings(client: client.Client, config: Config)
}

Constructors

  • Embeddings(client: client.Client, config: Config)

Format of the generated embeddings

  • Float: Standard floating point format for vector embeddings
pub type EncodingFormat {
  Float
}

Constructors

  • Float
pub type Response {
  Response(
    id: String,
    object: String,
    data: List(EmbeddingData),
    model: String,
    usage: Usage,
  )
}

Constructors

  • Response(
      id: String,
      object: String,
      data: List(EmbeddingData),
      model: String,
      usage: Usage,
    )
pub type Usage {
  Usage(prompt_tokens: Int, total_tokens: Int)
}

Constructors

  • Usage(prompt_tokens: Int, total_tokens: Int)

Functions

pub fn create_request(
  embeddings: Embeddings,
  model: Model,
  inputs: List(String),
) -> Request(String)

Creates an HTTP request for the Embeddings API endpoint

This function prepares a request to be sent to the Mistral AI Embeddings API. It needs to be paired with an HTTP client to actually send the request, and the response should be handled with client.handle_response using the appropriate decoder.

Example

// Create the request
let req = embeddings
  |> embeddings.create_request(
    model.EmbeddingMistral,
    ["Text to embed", "Another text to embed"]
  )

// Send the request with your HTTP client
use response <- result.try(http_client.send(req))

// Handle the response with the appropriate decoder
client.handle_response(response, using: embeddings.response_decoder())
pub fn handle_response(
  response: Response(String),
) -> Result(gleamstral/embeddings.Response, Error)

Handle HTTP responses from an embeddings request

Example

let assert Ok(response) =
  embeddings.create_request(embeddings, model.EmbeddingMistral, ["Text to embed"])
  |> httpc.send
let assert Ok(response) =
  embeddings.handle_response(response)
pub fn new(client: Client) -> Embeddings

Creates a new Embeddings instance with default configuration using the provided client

Example

let client = client.new("your-api-key")
let embeddings = embeddings.new(client)
pub fn response_decoder() -> Decoder(Response)
pub fn set_encoding_format(
  embeddings: Embeddings,
  encoding_format: EncodingFormat,
) -> Embeddings
Search Document