Package dev.langchain4j.data.segment
Class TextSegment
java.lang.Object
dev.langchain4j.data.segment.TextSegment
Represents a semantically meaningful segment (chunk/piece/fragment) of a larger entity such as a document or chat conversation.
This might be a sentence, a paragraph, or any other discrete unit of text that carries meaning.
This class encapsulates a piece of text and its associated metadata.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic TextSegmentCreates a new text segment.static TextSegmentCreates a new text segment.inthashCode()metadata()Returns the metadata.Deprecated.text()Returns the text.static TextSegmenttextSegment(String text) Creates a new text segment.static TextSegmenttextSegment(String text, Metadata metadata) Creates a new text segment.toString()
-
Constructor Details
-
TextSegment
Creates a new text segment.- Parameters:
text- the text.metadata- the metadata.
-
-
Method Details
-
text
Returns the text.- Returns:
- the text.
-
metadata
Returns the metadata.- Returns:
- the metadata.
-
metadata
Deprecated.as of 0.31.0, usemetadata()and thenMetadata.getString(String),Metadata.getInteger(String),Metadata.getLong(String),Metadata.getFloat(String),Metadata.getDouble(String)instead.Returns the metadata value for the given key.- Parameters:
key- the key.- Returns:
- the metadata value, or null if not found.
-
equals
-
hashCode
public int hashCode() -
toString
-
from
Creates a new text segment.- Parameters:
text- the text.- Returns:
- the text segment.
-
from
Creates a new text segment.- Parameters:
text- the text.metadata- the metadata.- Returns:
- the text segment.
-
textSegment
Creates a new text segment.- Parameters:
text- the text.- Returns:
- the text segment.
-
textSegment
Creates a new text segment.- Parameters:
text- the text.metadata- the metadata.- Returns:
- the text segment.
-
metadata()and thenMetadata.getString(String),Metadata.getInteger(String),Metadata.getLong(String),Metadata.getFloat(String),Metadata.getDouble(String)instead.