Class OpenAiEmbeddingClient

java.lang.Object
org.snmp4j.mcp.tool.mib.semantic.OpenAiEmbeddingClient
All Implemented Interfaces:
EmbeddingClient

public class OpenAiEmbeddingClient extends Object implements EmbeddingClient
EmbeddingClient that calls the OpenAI Embeddings API (POST https://api.openai.com/v1/embeddings).

Configure via PROP_API_KEY system property or OPENAI_API_KEY environment variable. Model and dimension are configurable through the builder; defaults are text-embedding-3-small at 256 dimensions (compact, high quality, cost-effective for MIB RAG).

Since:
0.1.0
  • Field Details

    • PROP_API_KEY

      public static final String PROP_API_KEY
      JVM system property name for the OpenAI API key.
      See Also:
    • ENV_API_KEY

      public static final String ENV_API_KEY
      Environment variable name for the OpenAI API key.
      See Also:
    • DEFAULT_MODEL

      public static final String DEFAULT_MODEL
      Default embedding model used when none is specified.
      See Also:
    • DEFAULT_DIMENSION

      public static final int DEFAULT_DIMENSION
      Default output dimension (256 is compact yet high-quality for MIB RAG).
      See Also:
    • MAX_BATCH_SIZE

      public static final int MAX_BATCH_SIZE
      Maximum number of texts sent in a single API call.
      See Also:
  • Method Details

    • builder

      public static OpenAiEmbeddingClient.Builder builder(String apiKey)
      Returns a builder for constructing an OpenAiEmbeddingClient.
      Parameters:
      apiKey - OpenAI API key (non-null, non-blank)
      Returns:
      a new builder
    • fromEnvironment

      public static OpenAiEmbeddingClient fromEnvironment()
      Reads the API key from system property "openai.api.key" or environment variable "OPENAI_API_KEY".
      Returns:
      client with default model/dimension, or null if no key found
    • embed

      public float[] embed(String text) throws IOException
      Description copied from interface: EmbeddingClient
      Embeds a single text chunk and returns a unit-length float vector.
      Specified by:
      embed in interface EmbeddingClient
      Parameters:
      text - the text to embed (non-null, non-blank)
      Returns:
      float vector of length EmbeddingClient.getDimension()
      Throws:
      IOException - on transport or API errors
    • batchEmbed

      public List<float[]> batchEmbed(List<String> texts) throws IOException
      Description copied from interface: EmbeddingClient
      Embeds multiple text chunks in one or more batched calls.

      The returned list has the same size and ordering as texts.

      Specified by:
      batchEmbed in interface EmbeddingClient
      Parameters:
      texts - the texts to embed
      Returns:
      list of float vectors, one per input text
      Throws:
      IOException - on transport or API errors
    • getDimension

      public int getDimension()
      Description copied from interface: EmbeddingClient
      Gets the number of dimensions in every returned vector.
      Specified by:
      getDimension in interface EmbeddingClient
      Returns:
      number of dimensions in every returned vector
    • getModelId

      public String getModelId()
      Description copied from interface: EmbeddingClient
      Gets the model identifier for this embedding client.
      Specified by:
      getModelId in interface EmbeddingClient
      Returns:
      human-readable model identifier (e.g. "text-embedding-3-small")