Interface EmbeddingProvider
- All Known Implementing Classes:
OllamaEmbeddingProvider,OpenAIEmbeddingProvider
Follows the same pattern as LLMProvider: this interface lives in
agenor-core with no external dependencies; concrete implementations
(OpenAI, Ollama) live in agenor-adapters and are instantiated via
EmbeddingProviderFactory.
Example usage:
EmbeddingProvider provider = EmbeddingProviderFactory.openAI(System.getenv("OPENAI_API_KEY"));
float[] vector = provider.embed("What is the return policy?").join();
All operations return CompletableFuture to allow non-blocking
I/O in virtual-thread or reactive contexts.
-
Method Summary
Modifier and TypeMethodDescriptionintReturns the dimensionality of the vectors produced by this provider.CompletableFuture<float[]> Generates a dense embedding vector for the given text.default CompletableFuture<List<float[]>> Generates embedding vectors for a batch of texts.modelId()Returns the model identifier used by this provider instance.
-
Method Details
-
embed
Generates a dense embedding vector for the given text.- Parameters:
text- input text (non-null, non-blank)- Returns:
- a
CompletableFuturethat resolves to the embedding vector; the array length equalsdimensions() - Throws:
EmbeddingException- (wrapped in the future) on provider errors
-
embedAll
Generates embedding vectors for a batch of texts.The default implementation delegates to
embed(String)for each element sequentially. Provider implementations should override this method to use a single batched HTTP request where the API supports it (e.g. OpenAI/v1/embeddingswith an array input).- Parameters:
texts- list of input texts (non-null, non-empty)- Returns:
- a
CompletableFutureresolving to an ordered list of embedding vectors, one per input text - Throws:
EmbeddingException- (wrapped in the future) on provider errors
-
dimensions
int dimensions()Returns the dimensionality of the vectors produced by this provider.All vectors returned by
embed(java.lang.String)andembedAll(java.util.List<java.lang.String>)have exactly this many elements. Callers must use this value when allocating vector stores or computing similarity scores.- Returns:
- positive integer (e.g. 1536 for
text-embedding-3-small)
-
modelId
String modelId()Returns the model identifier used by this provider instance.The format is provider-specific (e.g.
"text-embedding-3-small"for OpenAI,"nomic-embed-text"for Ollama).- Returns:
- non-null, non-blank model identifier
-