Class TextSegment

java.lang.Object
dev.langchain4j.data.segment.TextSegment

public class TextSegment extends Object
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 Details

    • TextSegment

      public TextSegment(String text, Metadata metadata)
      Creates a new text segment.
      Parameters:
      text - the text.
      metadata - the metadata.
  • Method Details

    • text

      public String text()
      Returns the text.
      Returns:
      the text.
    • metadata

      public Metadata metadata()
      Returns the metadata.
      Returns:
      the metadata.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • from

      public static TextSegment from(String text)
      Creates a new text segment.
      Parameters:
      text - the text.
      Returns:
      the text segment.
    • from

      public static TextSegment from(String text, Metadata metadata)
      Creates a new text segment.
      Parameters:
      text - the text.
      metadata - the metadata.
      Returns:
      the text segment.
    • textSegment

      public static TextSegment textSegment(String text)
      Creates a new text segment.
      Parameters:
      text - the text.
      Returns:
      the text segment.
    • textSegment

      public static TextSegment textSegment(String text, Metadata metadata)
      Creates a new text segment.
      Parameters:
      text - the text.
      metadata - the metadata.
      Returns:
      the text segment.