Package dev.langchain4j.data.segment
Class TextSegment
-
- All Implemented Interfaces:
public class 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 Constructor Description TextSegment(String text, Metadata metadata)
Creates a new text segment.
-
Method Summary
Modifier and Type Method Description String
text()
Returns the text. Metadata
metadata()
Returns the metadata. String
metadata(String key)
Returns the metadata value for the given key. boolean
equals(Object o)
int
hashCode()
String
toString()
static TextSegment
from(String text)
Creates a new text segment. static TextSegment
from(String text, Metadata metadata)
Creates a new text segment. static TextSegment
textSegment(String text)
Creates a new text segment. static TextSegment
textSegment(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.
-
-
-
-