Package dev.langchain4j.data.document
Class Metadata
java.lang.Object
dev.langchain4j.data.document.Metadata
Represents metadata of a Document or a TextSegment.
The metadata is stored in a key-value map, where both keys and values are strings.
For a Document, the metadata could include information such as the source, creation date,
owner, or any other relevant details.
For a TextSegment, in addition to metadata copied 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Adds a key-value pair to the metadata.asMap()Get a copy of the metadata as a map of key-value pairs.copy()Copies the metadata.booleanstatic MetadataDeprecated.Usefrom(String, String)insteadstatic MetadataConstructs a Metadata object from a single key-value pair.static MetadataConstructs a Metadata object from a map of key-value pairs.Returns the value associated with the given key.inthashCode()static MetadataDeprecated.Usemetadata(String, String)insteadstatic MetadataConstructs a Metadata object from a single key-value pair.Removes the given key from the metadata.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.- Parameters:
metadata- the map of key-value pairs; must not be null.
-
-
Method Details
-
get
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.
-
add
Adds a key-value pair to the metadata.- Parameters:
key- the keyvalue- the value- Returns:
this
-
add
Deprecated.Useadd(String, String)instead- 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
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.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.Usemetadata(String, String)instead- Parameters:
key- the keyvalue- the value- Returns:
- a Metadata object
-
add(String, String)instead