Class Metadata

  • All Implemented Interfaces:

    
    public class Metadata
    
                        

    Represents metadata of a Document or a TextSegment. For a Document, the metadata could store information such as the source, creation date, owner, or any other relevant details. For a TextSegment, in addition to metadata inherited from a Document, it can also include segment-specific information, such as the page number, the position of the segment within the document, chapter, etc. The metadata is stored as a key-value map, where the key is a String and the value can be one of: String, UUID, Integer, Long, Float, Double. If you require additional types, please open an issue. null values are not permitted.

    • Constructor Detail

      • Metadata

        Metadata()
        Construct a Metadata object with an empty map of key-value pairs.
      • Metadata

        Metadata(Map<String, out Object> metadata)
        Constructs a Metadata object from a map of key-value pairs.
        Parameters:
        metadata - the map of key-value pairs; must not be null.
    • Method Detail

      • get

        @Deprecated(forRemoval = true) String get(String key)

        Returns the value associated with the given key.

        Parameters:
        key - the key
        Returns:

        the value associated with the given key, or null if the key is not present.

      • getString

         String getString(String key)

        Returns the String value associated with the given key.

        Parameters:
        key - the key
        Returns:

        the String value associated with the given key, or null if the key is not present.

      • getUUID

         UUID getUUID(String key)

        Returns the UUID value associated with the given key.

        Parameters:
        key - the key
        Returns:

        the UUID value associated with the given key, or null if the key is not present.

      • getInteger

         Integer getInteger(String key)

        Returns the Integer value associated with the given key. Some EmbeddingStore implementations (still) store Metadata values as Strings. In this case, the String value will be parsed into an Integer when this method is called. Some EmbeddingStore implementations store Metadata key-value pairs as JSON. In this case, type information is lost when serializing to JSON and then deserializing back from JSON. JSON libraries can, for example, serialize an Integer and then deserialize it as a Long. Or serialize a Float and then deserialize it as a Double, and so on. In such cases, the actual value will be cast to an Integer when this method is called.

        Parameters:
        key - the key
        Returns:

        the Integer value associated with the given key, or null if the key is not present.

      • getLong

         Long getLong(String key)

        Returns the Long value associated with the given key. Some EmbeddingStore implementations (still) store Metadata values as Strings. In this case, the String value will be parsed into an Long when this method is called. Some EmbeddingStore implementations store Metadata key-value pairs as JSON. In this case, type information is lost when serializing to JSON and then deserializing back from JSON. JSON libraries can, for example, serialize an Integer and then deserialize it as a Long. Or serialize a Float and then deserialize it as a Double, and so on. In such cases, the actual value will be cast to a Long when this method is called.

        Parameters:
        key - the key
        Returns:

        the Long value associated with the given key, or null if the key is not present.

      • getFloat

         Float getFloat(String key)

        Returns the Float value associated with the given key. Some EmbeddingStore implementations (still) store Metadata values as Strings. In this case, the String value will be parsed into a Float when this method is called. Some EmbeddingStore implementations store Metadata key-value pairs as JSON. In this case, type information is lost when serializing to JSON and then deserializing back from JSON. JSON libraries can, for example, serialize an Integer and then deserialize it as a Long. Or serialize a Float and then deserialize it as a Double, and so on. In such cases, the actual value will be cast to a Float when this method is called.

        Parameters:
        key - the key
        Returns:

        the Float value associated with the given key, or null if the key is not present.

      • getDouble

         Double getDouble(String key)

        Returns the Double value associated with the given key. Some EmbeddingStore implementations (still) store Metadata values as Strings. In this case, the String value will be parsed into a Double when this method is called. Some EmbeddingStore implementations store Metadata key-value pairs as JSON. In this case, type information is lost when serializing to JSON and then deserializing back from JSON. JSON libraries can, for example, serialize an Integer and then deserialize it as a Long. Or serialize a Float and then deserialize it as a Double, and so on. In such cases, the actual value will be cast to a Double when this method is called.

        Parameters:
        key - the key
        Returns:

        the Double value associated with the given key, or null if the key is not present.

      • containsKey

         boolean containsKey(String key)

        Check whether this Metadata contains a given key.

        Parameters:
        key - the key
        Returns:

        true if this metadata contains a given key; false otherwise.

      • add

        @Deprecated(forRemoval = true) Metadata add(String key, Object value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • add

        @Deprecated(forRemoval = true) Metadata add(String key, String value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, String value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, UUID value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, int value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, long value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, float value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • put

         Metadata put(String key, double value)

        Adds a key-value pair to the metadata.

        Parameters:
        key - the key
        value - the value
        Returns:

        this

      • remove

         Metadata remove(String key)

        Removes the given key from the metadata.

        Parameters:
        key - the key
        Returns:

        this

      • copy

         Metadata copy()

        Copies the metadata.

        Returns:

        a copy of this Metadata object.

      • asMap

        @Deprecated(forRemoval = true) Map<String, String> asMap()

        Get a copy of the metadata as a map of key-value pairs.

        Returns:

        the metadata as a map of key-value pairs.

      • toMap

         Map<String, Object> toMap()

        Get a copy of the metadata as a map of key-value pairs.

        Returns:

        the metadata as a map of key-value pairs.

      • from

         static Metadata from(String key, String value)

        Constructs a Metadata object from a single key-value pair.

        Parameters:
        key - the key
        value - the value
        Returns:

        a Metadata object

      • from

         static Metadata from(Map<String, out Object> metadata)

        Constructs a Metadata object from a map of key-value pairs.

        Parameters:
        metadata - the map of key-value pairs
        Returns:

        a Metadata object

      • metadata

         static Metadata metadata(String key, String value)

        Constructs a Metadata object from a single key-value pair.

        Parameters:
        key - the key
        value - the value
        Returns:

        a Metadata object