Segment

public final classSegment


Represents a specific segment within aContent object, often used to pinpoint the exact location of text or data that grounding information refers to.

Summary

Public fields

final int

The zero-based end index of the segment within the specifiedPart, measured in UTF-8 bytes.

final int

The zero-based index of thePart object within theparts array of its parentContent object.

final int

The zero-based start index of the segment within the specifiedPart, measured in UTF-8 bytes.

final @NonNullString

The text corresponding to the segment from the response.

Public constructors

Segment(int startIndex, int endIndex, int partIndex, @NonNullString text)

Public fields

endIndex

public final int endIndex

The zero-based end index of the segment within the specifiedPart, measured in UTF-8 bytes. This offset is exclusive, meaning the character at this index is not included in the segment.

partIndex

public final int partIndex

The zero-based index of thePart object within theparts array of its parentContent object. This identifies which part of the content the segment belongs to.

startIndex

public final int startIndex

The zero-based start index of the segment within the specifiedPart, measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the beginning of the part's content.

text

public final @NonNullString text

The text corresponding to the segment from the response.

Public constructors

Segment

public Segment(int startIndex, int endIndex, int partIndex, @NonNullString text)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.