Package dev.langchain4j.data.document
Class Metadata
java.lang.Object
dev.langchain4j.data.document.Metadata
Represents metadata of a
For a
For a
The metadata is stored as a key-value map, where the key is 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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, useput(String, String)
,put(String, int)
,put(String, long)
,put(String, float)
,put(String, double)
instead.asMap()
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usetoMap()
instead.boolean
containsKey
(String key) Check whether thisMetadata
contains a given key.copy()
Copies the metadata.boolean
static Metadata
Deprecated, for removal: This API element is subject to removal in a future version.Usefrom(String, String)
insteadstatic Metadata
Constructs a Metadata object from a single key-value pair.static Metadata
Constructs a Metadata object from a map of key-value pairs.Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usegetString(String)
,getInteger(String)
,getLong(String)
,getFloat(String)
,getDouble(String)
instead.Returns theDouble
value associated with the given key.Returns theFloat
value associated with the given key.getInteger
(String key) Returns theInteger
value associated with the given key.Returns theLong
value associated with the given key.Returns theString
value associated with the given key.Returns theUUID
value associated with the given key.int
hashCode()
static Metadata
Deprecated, for removal: This API element is subject to removal in a future version.Usemetadata(String, String)
insteadstatic Metadata
Constructs a Metadata object from a single key-value pair.Adds a key-value pair to the metadata.Adds a key-value pair to the metadata.Adds a key-value pair to the metadata.Adds a key-value pair to the metadata.Adds a key-value pair to the metadata.Adds a key-value pair to the metadata.Removes the given key from the metadata.toMap()
Get a copy of the metadata as a map of key-value pairs.toString()
-
Constructor Details
-
Metadata
public Metadata()Construct a Metadata object with an empty map of key-value pairs. -
Metadata
Constructs a Metadata object from a map of key-value pairs.
-
-
Method Details
-
get
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usegetString(String)
,getInteger(String)
,getLong(String)
,getFloat(String)
,getDouble(String)
instead.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
Returns theString
value associated with the given key.- Parameters:
key
- the key- Returns:
- the
String
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is not of type String
-
getUUID
Returns theUUID
value associated with the given key.- Parameters:
key
- the key- Returns:
- the
UUID
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is not of type String
-
getInteger
Returns theInteger
value associated with the given key.
SomeEmbeddingStore
implementations (still) storeMetadata
values asString
s. In this case, theString
value will be parsed into anInteger
when this method is called.
SomeEmbeddingStore
implementations storeMetadata
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 anInteger
and then deserialize it as aLong
. Or serialize aFloat
and then deserialize it as aDouble
, and so on. In such cases, the actual value will be cast to anInteger
when this method is called.- Parameters:
key
- the key- Returns:
- the
Integer
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is notNumber
-
getLong
Returns theLong
value associated with the given key.
SomeEmbeddingStore
implementations (still) storeMetadata
values asString
s. In this case, theString
value will be parsed into anLong
when this method is called.
SomeEmbeddingStore
implementations storeMetadata
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 anInteger
and then deserialize it as aLong
. Or serialize aFloat
and then deserialize it as aDouble
, and so on. In such cases, the actual value will be cast to aLong
when this method is called.- Parameters:
key
- the key- Returns:
- the
Long
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is notNumber
-
getFloat
Returns theFloat
value associated with the given key.
SomeEmbeddingStore
implementations (still) storeMetadata
values asString
s. In this case, theString
value will be parsed into aFloat
when this method is called.
SomeEmbeddingStore
implementations storeMetadata
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 anInteger
and then deserialize it as aLong
. Or serialize aFloat
and then deserialize it as aDouble
, and so on. In such cases, the actual value will be cast to aFloat
when this method is called.- Parameters:
key
- the key- Returns:
- the
Float
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is notNumber
-
getDouble
Returns theDouble
value associated with the given key.
SomeEmbeddingStore
implementations (still) storeMetadata
values asString
s. In this case, theString
value will be parsed into aDouble
when this method is called.
SomeEmbeddingStore
implementations storeMetadata
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 anInteger
and then deserialize it as aLong
. Or serialize aFloat
and then deserialize it as aDouble
, and so on. In such cases, the actual value will be cast to aDouble
when this method is called.- Parameters:
key
- the key- Returns:
- the
Double
value associated with the given key, ornull
if the key is not present. - Throws:
RuntimeException
- if the value is notNumber
-
containsKey
Check whether thisMetadata
contains a given key.- Parameters:
key
- the key- Returns:
true
if this metadata contains a given key;false
otherwise.
-
add
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, useput(String, String)
,put(String, int)
,put(String, long)
,put(String, float)
,put(String, double)
instead.Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
add
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, useput(String, String)
,put(String, int)
,put(String, long)
,put(String, float)
,put(String, double)
instead.Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
put
Adds a key-value pair to the metadata.- Parameters:
key
- the keyvalue
- the value- Returns:
this
-
remove
Removes the given key from the metadata.- Parameters:
key
- the key- Returns:
this
-
copy
Copies the metadata.- Returns:
- a copy of this Metadata object.
-
asMap
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usetoMap()
instead.Get a copy of the metadata as a map of key-value pairs.- Returns:
- the metadata as a map of key-value pairs.
-
toMap
Get a copy of the metadata as a map of key-value pairs.- Returns:
- the metadata as a map of key-value pairs.
-
equals
-
hashCode
public int hashCode() -
toString
-
from
Constructs a Metadata object from a single key-value pair.- Parameters:
key
- the keyvalue
- the value- Returns:
- a Metadata object
-
from
Deprecated, for removal: This API element is subject to removal in a future version.Usefrom(String, String)
instead- Parameters:
key
- the keyvalue
- the value- Returns:
- a Metadata object
-
from
Constructs a Metadata object from a map of key-value pairs.- Parameters:
metadata
- the map of key-value pairs- Returns:
- a Metadata object
-
metadata
Constructs a Metadata object from a single key-value pair.- Parameters:
key
- the keyvalue
- the value- Returns:
- a Metadata object
-
metadata
Deprecated, for removal: This API element is subject to removal in a future version.Usemetadata(String, String)
instead- Parameters:
key
- the keyvalue
- the value- Returns:
- a Metadata object
-
put(String, String)
,put(String, int)
,put(String, long)
,put(String, float)
,put(String, double)
instead.