class

Memo::Providers::OpenAI

Inherits Memo::Providers::Base < Reference < Object

OpenAI embedding provider

Generates embeddings using OpenAI's embeddings API. Compatible with OpenAI, Azure OpenAI, and other OpenAI-compatible APIs.

Constants

DEFAULT_BASE_URL = "https://api.openai.com/v1"

Constructors

new(api_key : String, model : String = "text-embedding-3-small", base_url : String = DEFAULT_BASE_URL, dimensions : Int32 | Nil = nil)
Source

Class methods

shortenable?(model : String) : Bool

text-embedding-3 models can return shorter vectors (the dimensions parameter); older models such as ada-002 reject it.

Source

Instance methods

api_key
Source
base_url
Source
embed_text(text : String, input_type : String | Nil = nil) : Tuple(Array(Float64), Int32)

Embed a single text

Returns tuple of (embedding vector, token count) input_type: "query" or "document" (used by Voyage AI for optimized embeddings)

Source
embed_texts(texts : Array(String), input_type : String | Nil = nil) : EmbedResult

Embed multiple texts in a batch

Returns EmbedResult with embeddings and token counts input_type: "query" or "document" (used by Voyage AI for optimized embeddings)

Source
model
Source