Class Metadata
-
- All Implemented Interfaces:
public class MetadataRepresents 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.
nullvalues are not permitted.
-
-
Method Summary
Modifier and Type Method Description Stringget(String key)Returns the value associated with the given key. StringgetString(String key)Returns the Stringvalue associated with the given key.UUIDgetUUID(String key)Returns the UUIDvalue associated with the given key.IntegergetInteger(String key)Returns the Integervalue associated with the given key.LonggetLong(String key)Returns the Longvalue associated with the given key.FloatgetFloat(String key)Returns the Floatvalue associated with the given key.DoublegetDouble(String key)Returns the Doublevalue associated with the given key.booleancontainsKey(String key)Check whether this Metadatacontains a given key.Metadataadd(String key, Object value)Adds a key-value pair to the metadata. Metadataadd(String key, String value)Adds a key-value pair to the metadata. Metadataput(String key, String value)Adds a key-value pair to the metadata. Metadataput(String key, UUID value)Adds a key-value pair to the metadata. Metadataput(String key, int value)Adds a key-value pair to the metadata. Metadataput(String key, long value)Adds a key-value pair to the metadata. Metadataput(String key, float value)Adds a key-value pair to the metadata. Metadataput(String key, double value)Adds a key-value pair to the metadata. Metadataremove(String key)Removes the given key from the metadata. Metadatacopy()Copies the metadata. Map<String, String>asMap()Get a copy of the metadata as a map of key-value pairs. Map<String, Object>toMap()Get a copy of the metadata as a map of key-value pairs. booleanequals(Object o)inthashCode()StringtoString()static Metadatafrom(String key, String value)Constructs a Metadata object from a single key-value pair. static Metadatafrom(String key, Object value)static Metadatafrom(Map<String, out Object> metadata)Constructs a Metadata object from a map of key-value pairs. static Metadatametadata(String key, String value)Constructs a Metadata object from a single key-value pair. static Metadatametadata(String key, Object value)Metadatamerge(@Nullable() Metadata another)Merges the current Metadata object with another Metadata object. -
-
Method Detail
-
get
@Deprecated(forRemoval = true)@Nullable() 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
nullif the key is not present.
-
getString
@Nullable() String getString(String key)
Returns the
Stringvalue associated with the given key.- Parameters:
key- the key- Returns:
the
Stringvalue associated with the given key, ornullif the key is not present.
-
getUUID
@Nullable() UUID getUUID(String key)
Returns the
UUIDvalue associated with the given key.- Parameters:
key- the key- Returns:
the
UUIDvalue associated with the given key, ornullif the key is not present.
-
getInteger
@Nullable() Integer getInteger(String key)
Returns the
Integervalue associated with the given key. Some EmbeddingStore implementations (still) storeMetadatavalues asStrings. In this case, theStringvalue will be parsed into anIntegerwhen this method is called. Some EmbeddingStore implementations storeMetadatakey-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 anIntegerand then deserialize it as aLong. Or serialize aFloatand then deserialize it as aDouble, and so on. In such cases, the actual value will be cast to anIntegerwhen this method is called.- Parameters:
key- the key- Returns:
the Integer value associated with the given key, or
nullif the key is not present.
-
getLong
@Nullable() Long getLong(String key)
Returns the
Longvalue associated with the given key. Some EmbeddingStore implementations (still) storeMetadatavalues asStrings. In this case, theStringvalue will be parsed into anLongwhen this method is called. Some EmbeddingStore implementations storeMetadatakey-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 anIntegerand then deserialize it as aLong. Or serialize aFloatand then deserialize it as aDouble, and so on. In such cases, the actual value will be cast to aLongwhen this method is called.- Parameters:
key- the key- Returns:
the
Longvalue associated with the given key, ornullif the key is not present.
-
getFloat
@Nullable() Float getFloat(String key)
Returns the
Floatvalue associated with the given key. Some EmbeddingStore implementations (still) storeMetadatavalues asStrings. In this case, theStringvalue will be parsed into aFloatwhen this method is called. Some EmbeddingStore implementations storeMetadatakey-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 anIntegerand then deserialize it as aLong. Or serialize aFloatand then deserialize it as aDouble, and so on. In such cases, the actual value will be cast to aFloatwhen this method is called.- Parameters:
key- the key- Returns:
the
Floatvalue associated with the given key, ornullif the key is not present.
-
getDouble
@Nullable() Double getDouble(String key)
Returns the
Doublevalue associated with the given key. Some EmbeddingStore implementations (still) storeMetadatavalues asStrings. In this case, theStringvalue will be parsed into aDoublewhen this method is called. Some EmbeddingStore implementations storeMetadatakey-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 anIntegerand then deserialize it as aLong. Or serialize aFloatand then deserialize it as aDouble, and so on. In such cases, the actual value will be cast to aDoublewhen this method is called.- Parameters:
key- the key- Returns:
the
Doublevalue associated with the given key, ornullif the key is not present.
-
containsKey
boolean containsKey(String key)
Check whether this
Metadatacontains a given key.- Parameters:
key- the key- Returns:
trueif this metadata contains a given key;falseotherwise.
-
add
@Deprecated(forRemoval = true) Metadata add(String key, Object value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- 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 keyvalue- the value- Returns:
this
-
put
Metadata put(String key, String value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
put
Metadata put(String key, UUID value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
put
Metadata put(String key, int value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
put
Metadata put(String key, long value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
put
Metadata put(String key, float value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
put
Metadata put(String key, double value)
Adds a key-value pair to the metadata.
- Parameters:
key- the keyvalue- the value- Returns:
this
-
remove
Metadata remove(String key)
Removes the given key from the metadata.
- Parameters:
key- the key- Returns:
this
-
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.
-
hashCode
int hashCode()
-
from
static Metadata from(String key, String value)
Constructs a Metadata object from a single key-value pair.
- Parameters:
key- the keyvalue- the value- Returns:
a Metadata object
-
from
@Deprecated(forRemoval = true) static Metadata from(String key, Object value)
- Parameters:
key- the keyvalue- 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 keyvalue- the value- Returns:
a Metadata object
-
metadata
@Deprecated(forRemoval = true) static Metadata metadata(String key, Object value)
- Parameters:
key- the keyvalue- the value- Returns:
a Metadata object
-
merge
Metadata merge(@Nullable() Metadata another)
Merges the current Metadata object with another Metadata object. The two Metadata objects must not have any common keys.
- Parameters:
another- The Metadata object to be merged with the current Metadata object.- Returns:
A new Metadata object that contains all key-value pairs from both Metadata objects.
-
-
-
-