Package dev.langchain4j.data.segment
Class TextSegment
-
- All Implemented Interfaces:
public class TextSegmentRepresents 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 Constructor Description TextSegment(String text, Metadata metadata)Creates a new text segment.
-
Method Summary
Modifier and Type Method Description Stringtext()Returns the text. Metadatametadata()Returns the metadata. Stringmetadata(String key)Returns the metadata value for the given key. booleanequals(Object o)inthashCode()StringtoString()static TextSegmentfrom(String text)Creates a new text segment. static TextSegmentfrom(String text, Metadata metadata)Creates a new text segment. static TextSegmenttextSegment(String text)Creates a new text segment. static TextSegmenttextSegment(String text, Metadata metadata)Creates a new text segment. -
-
Method Detail
-
metadata
@Deprecated(forRemoval = true) String metadata(String key)
Returns the metadata value for the given key.
- Parameters:
key- the key.- Returns:
the metadata value, or null if not found.
-
hashCode
int hashCode()
-
from
static TextSegment from(String text)
Creates a new text segment.
- Parameters:
text- the text.- Returns:
the text segment.
-
from
static TextSegment from(String text, Metadata metadata)
Creates a new text segment.
- Parameters:
text- the text.metadata- the metadata.- Returns:
the text segment.
-
textSegment
static TextSegment textSegment(String text)
Creates a new text segment.
- Parameters:
text- the text.- Returns:
the text segment.
-
textSegment
static TextSegment textSegment(String text, Metadata metadata)
Creates a new text segment.
- Parameters:
text- the text.metadata- the metadata.- Returns:
the text segment.
-
-
-
-