Class OpenAiEmbeddingClient
java.lang.Object
org.snmp4j.mcp.tool.mib.semantic.OpenAiEmbeddingClient
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault output dimension (256 is compact yet high-quality for MIB RAG).static final StringDefault embedding model used when none is specified.static final StringEnvironment variable name for the OpenAI API key.static final intMaximum number of texts sent in a single API call.static final StringJVM system property name for the OpenAI API key. -
Method Summary
Modifier and TypeMethodDescriptionList<float[]> batchEmbed(List<String> texts) Embeds multiple text chunks in one or more batched calls.Returns a builder for constructing anOpenAiEmbeddingClient.float[]Embeds a single text chunk and returns a unit-length float vector.static OpenAiEmbeddingClientReads the API key from system property "openai.api.key" or environment variable "OPENAI_API_KEY".intGets the number of dimensions in every returned vector.Gets the model identifier for this embedding client.
-
Field Details
-
PROP_API_KEY
-
ENV_API_KEY
-
DEFAULT_MODEL
Default embedding model used when none is specified.- See Also:
-
DEFAULT_DIMENSION
public static final int DEFAULT_DIMENSIONDefault output dimension (256 is compact yet high-quality for MIB RAG).- See Also:
-
MAX_BATCH_SIZE
public static final int MAX_BATCH_SIZEMaximum number of texts sent in a single API call.- See Also:
-
-
Method Details
-
builder
Returns a builder for constructing anOpenAiEmbeddingClient.- Parameters:
apiKey- OpenAI API key (non-null, non-blank)- Returns:
- a new builder
-
fromEnvironment
Reads the API key from system property "openai.api.key" or environment variable "OPENAI_API_KEY".- Returns:
- client with default model/dimension, or
nullif no key found
-
embed
Description copied from interface:EmbeddingClientEmbeds a single text chunk and returns a unit-length float vector.- Specified by:
embedin interfaceEmbeddingClient- 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
Description copied from interface:EmbeddingClientEmbeds multiple text chunks in one or more batched calls.The returned list has the same size and ordering as
texts.- Specified by:
batchEmbedin interfaceEmbeddingClient- 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:EmbeddingClientGets the number of dimensions in every returned vector.- Specified by:
getDimensionin interfaceEmbeddingClient- Returns:
- number of dimensions in every returned vector
-
getModelId
Description copied from interface:EmbeddingClientGets the model identifier for this embedding client.- Specified by:
getModelIdin interfaceEmbeddingClient- Returns:
- human-readable model identifier (e.g.
"text-embedding-3-small")
-