JEmbeddingClient

org.llm4s.javaapi.JEmbeddingClient
See theJEmbeddingClient companion object
final class JEmbeddingClient

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)));

Obtain one with Llm4s.createDefaultEmbeddingClient, which reads the model from llm4s.embeddings.model (EMBEDDING_MODEL).

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.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def dimensions: Int

The length of the vectors the model makes, as its provider module declares it.

The length of the vectors the model makes, as its provider module declares it.

Attributes

def embed(texts: List[String]): LlmResult[JEmbeddings]

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).

Attributes

def embed(texts: List[String], purpose: JEmbeddingPurpose): LlmResult[JEmbeddings]

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.

Attributes

def model: String

The embedding model this client asks for, as configured.

The embedding model this client asks for, as configured.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any