Java-friendly wrapper around core's EmbeddingClient: turns texts into vectors, for semantic search and similarity, with no Scala type in sight.
JEmbeddingClient embedder = Llm4s.createDefaultEmbeddingClient().get();
JEmbeddings embeddings = embedder.embed(List.of("The cat sat on the mat.", "A kitten lay on the rug.")).get();
List<float[]> vectors = embeddings.vectors();
System.out.println(JEmbeddings.cosineSimilarity(vectors.get(0), vectors.get(1)));
Every embed sends all its texts to the provider in one request, blocks the calling thread and never throws: a failure - of the provider, the network or an argument - comes back inside the LlmResult, and its getKind() says which. An embedding provider's error response reads by its HTTP status, as a chat provider's does: 401 and 403 as AUTHENTICATION, 429 as RATE_LIMIT, 400 as VALIDATION, any other as SERVICE. Interrupting the blocked thread returns a failed result whose kind is CANCELLED, with the thread's interrupt flag still set; InterruptedException is never thrown.
Embeds texts as documents to be indexed - core's default - returning one vector per text, in order. The same as embed(texts, JEmbeddingPurpose.DOCUMENT).
Embeds texts as documents to be indexed - core's default - returning one vector per text, in order. The same as embed(texts, JEmbeddingPurpose.DOCUMENT).
Embeds texts for purpose - documents to index, or queries to run against them - returning one vector per text, in order, from a single request. An empty list returns no vectors and calls no provider.
Embeds texts for purpose - documents to index, or queries to run against them - returning one vector per text, in order, from a single request. An empty list returns no vectors and calls no provider.
A null list, null text or null purpose yields a failed result of kind VALIDATION, never an exception. Blocks the calling thread; an interrupt yields a failed result of kind CANCELLED, with the interrupt flag left set.