Record Class DefaultContent

java.lang.Object
java.lang.Record
dev.langchain4j.rag.content.DefaultContent
All Implemented Interfaces:
Content

public record DefaultContent(TextSegment textSegment, Map<ContentMetadata,Object> metadata) extends Record implements Content
A default implementation of a Content.
The class includes optional metadata which can store additional information about the content. This metadata is supplementary and is intentionally excluded from equality and hash calculations. See equals(Object) and hashCode() for details.
  • Constructor Details

    • DefaultContent

      public DefaultContent(TextSegment textSegment, Map<ContentMetadata,Object> metadata)
      Creates an instance of a DefaultContent record class.
      Parameters:
      textSegment - the value for the textSegment record component
      metadata - the value for the metadata record component
    • DefaultContent

      public DefaultContent(String text)
    • DefaultContent

      public DefaultContent(TextSegment textSegment)
  • Method Details

    • equals

      public boolean equals(Object o)
      Compares this Content with another object for equality.
      The metadata field is intentionally excluded from the equality check. Metadata is considered supplementary information and does not contribute to the core identity of the Content.
      Specified by:
      equals in class Record
    • hashCode

      public int hashCode()
      Computes the hash code for this Content.
      The metadata field is excluded from the hash code calculation. This ensures that two logically identical Content objects with differing metadata produce the same hash code, maintaining consistent behavior in hash-based collections.
      Specified by:
      hashCode in class Record
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • textSegment

      public TextSegment textSegment()
      Returns the value of the textSegment record component.
      Specified by:
      textSegment in interface Content
      Returns:
      the value of the textSegment record component
    • metadata

      public Map<ContentMetadata,Object> metadata()
      Returns the value of the metadata record component.
      Specified by:
      metadata in interface Content
      Returns:
      the value of the metadata record component