Record Class PoolingConfig

java.lang.Object
java.lang.Record
com.oracle.coherence.rag.model.PoolingConfig
Record Components:
dimension - the dimensionality of the word embeddings
clsToken - whether CLS token pooling is enabled
mean - whether mean token pooling is enabled

public record PoolingConfig(int dimension, boolean clsToken, boolean mean) extends Record
Configuration record for pooling settings in transformer-based embedding models.

This record encapsulates the pooling configuration parameters that determine how token embeddings are aggregated into a single sentence or document embedding. It supports the common pooling strategies used in BERT-style transformer models.

The configuration is designed to be serialized from/to JSON configuration files that typically accompany pre-trained embedding models, using JSON-B annotations to map to the standard configuration format used by sentence-transformers and similar libraries.

Supported pooling modes:

  • CLS token pooling: Uses the [CLS] token embedding as the sentence representation
  • Mean token pooling: Averages all token embeddings to create the sentence representation

Since:
25.09
Author:
Aleks Seovic 2025.07.04
  • Constructor Summary

    Constructors
    Constructor
    Description
    PoolingConfig(int dimension, boolean clsToken, boolean mean)
    Creates an instance of a PoolingConfig record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns the value of the clsToken record component.
    int
    Returns the value of the dimension record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Returns the value of the mean record component.
    Determines the pooling mode based on the configuration flags.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PoolingConfig

      public PoolingConfig(int dimension, boolean clsToken, boolean mean)
      Creates an instance of a PoolingConfig record class.
      Parameters:
      dimension - the value for the dimension record component
      clsToken - the value for the clsToken record component
      mean - the value for the mean record component
  • Method Details

    • mode

      public PoolingMode mode()
      Determines the pooling mode based on the configuration flags.

      This method validates that exactly one pooling mode is enabled and returns the corresponding PoolingMode enum value. The configuration must specify either CLS token pooling or mean pooling, but not both.

      Returns:
      the pooling mode to use for sentence embedding
      Throws:
      IllegalStateException - if both or neither pooling modes are enabled
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • dimension

      public int dimension()
      Returns the value of the dimension record component.
      Returns:
      the value of the dimension record component
    • clsToken

      public boolean clsToken()
      Returns the value of the clsToken record component.
      Returns:
      the value of the clsToken record component
    • mean

      public boolean mean()
      Returns the value of the mean record component.
      Returns:
      the value of the mean record component