Class OllamaTextEmbedding

java.lang.Object
io.agentscope.core.embedding.ollama.OllamaTextEmbedding
All Implemented Interfaces:
EmbeddingModel

public class OllamaTextEmbedding extends Object implements EmbeddingModel
Ollama Text Embedding Model implementation.

This implementation provides access to Ollama's text embedding API, supporting both single text embedding and batch embedding operations.

Supports only TextBlock content blocks. Other content block types will result in an EmbeddingException.

Supports timeout and retry configuration through ExecutionConfig.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for OllamaTextEmbedding.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OllamaTextEmbedding(String baseUrl, String modelName, int dimensions, io.agentscope.core.model.ExecutionConfig defaultExecutionConfig)
    Creates a new Ollama text embedding model instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder for OllamaTextEmbedding.
    reactor.core.publisher.Mono<double[]>
    embed(io.agentscope.core.message.ContentBlock block)
    Generate embedding vector for a single content block.
    int
    Get the dimension of embedding vectors produced by this model.
    Get the model name for logging and identification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OllamaTextEmbedding

      public OllamaTextEmbedding(String baseUrl, String modelName, int dimensions, io.agentscope.core.model.ExecutionConfig defaultExecutionConfig)
      Creates a new Ollama text embedding model instance.
      Parameters:
      baseUrl - the base URL for Ollama API (e.g., "http://localhost:11434")
      modelName - the model name (e.g., "nomic-embed-text", "all-minilm")
      dimensions - the dimension of embedding vectors
      defaultExecutionConfig - default execution configuration for timeout and retry
  • Method Details

    • builder

      public static OllamaTextEmbedding.Builder builder()
      Creates a new builder for OllamaTextEmbedding.
      Returns:
      a new Builder instance
    • embed

      public reactor.core.publisher.Mono<double[]> embed(io.agentscope.core.message.ContentBlock block)
      Description copied from interface: EmbeddingModel
      Generate embedding vector for a single content block.

      Implementations should check the content block type and throw EmbeddingException if the type is not supported.

      Specified by:
      embed in interface EmbeddingModel
      Parameters:
      block - the content block to embed (e.g., TextBlock, ImageBlock)
      Returns:
      Mono that emits a double array representing the embedding vector
    • getModelName

      public String getModelName()
      Description copied from interface: EmbeddingModel
      Get the model name for logging and identification.
      Specified by:
      getModelName in interface EmbeddingModel
      Returns:
      the model name
    • getDimensions

      public int getDimensions()
      Description copied from interface: EmbeddingModel
      Get the dimension of embedding vectors produced by this model. The default value is 1024 if not specified.
      Specified by:
      getDimensions in interface EmbeddingModel
      Returns:
      the dimension of embedding vectors