Class FixedDimensionEmbeddingModel

java.lang.Object
org.springframework.ai.test.vectorstore.FixedDimensionEmbeddingModel
All Implemented Interfaces:
EmbeddingModel, Model<EmbeddingRequest,EmbeddingResponse>

public final class FixedDimensionEmbeddingModel extends Object implements EmbeddingModel
A minimal deterministic EmbeddingModel that returns a constant vector of a configured dimension, for tests that must not depend on a hosted embedding provider.

It is the query-side model for the AbstractVectorStoreUpsertTests suite: upsert supplies its own vectors, and the suite reads back with similarityThresholdAll() regardless of ranking, so a constant vector is sufficient and no API key is needed. Wire it into a store's upsert integration test and size the store's index to dimensions().

Since:
2.1.0
Author:
Soby Chacko
  • Constructor Details

    • FixedDimensionEmbeddingModel

      public FixedDimensionEmbeddingModel(int dimensions)
  • Method Details

    • embed

      public float[] embed(Document document)
      Description copied from interface: EmbeddingModel
      Embeds the given document's content into a vector.
      Specified by:
      embed in interface EmbeddingModel
      Parameters:
      document - the document to embed.
      Returns:
      the embedded vector.
    • embed

      public float[] embed(String text)
      Description copied from interface: EmbeddingModel
      Embeds the given text into a vector.
      Specified by:
      embed in interface EmbeddingModel
      Parameters:
      text - the text to embed.
      Returns:
      the embedded vector.
    • call

      public EmbeddingResponse call(EmbeddingRequest request)
      Description copied from interface: Model
      Executes a method call to the AI model.
      Specified by:
      call in interface EmbeddingModel
      Specified by:
      call in interface Model<EmbeddingRequest,EmbeddingResponse>
      Parameters:
      request - the request object to be sent to the AI model
      Returns:
      the response from the AI model
    • dimensions

      public int dimensions()
      Description copied from interface: EmbeddingModel
      Get the number of dimensions of the embedded vectors. Note that by default, this method will call the remote Embedding endpoint to get the dimensions of the embedded vectors. If the dimensions are known ahead of time, it is recommended to override this method.
      Specified by:
      dimensions in interface EmbeddingModel
      Returns:
      the number of dimensions of the embedded vectors.