Package com.tnsai.rag

Enum Class ChunkContext

java.lang.Object
java.lang.Enum<ChunkContext>
com.tnsai.rag.ChunkContext
All Implemented Interfaces:
Serializable, Comparable<ChunkContext>, Constable

public enum ChunkContext extends Enum<ChunkContext>
Opt-in ingest-time transform that prepends chunk context before embedding and BM25 indexing.

NONE is the default: the indexed text is the chunk body, and the fingerprint payload carries no extra context fields. STRUCTURAL prepends provenance the chunker already computed. LLM prepends a short description from an installed ChunkContextGenerator.

The prefix is indexed only. The original body is what the model sees, so the prefix does not consume @Search.contextWindow.

@Knowledge.unit = LINE is rejected: a 50–100 token preamble on a single line inverts the signal.

Since:
0.15.0
  • Enum Constant Details

    • NONE

      public static final ChunkContext NONE
      No prefix. Indexed text equals the chunk body.
    • STRUCTURAL

      public static final ChunkContext STRUCTURAL
      Deterministic prefix from origin, structural path, and line range. No model call.
    • LLM

      public static final ChunkContext LLM
      Prefix from an installed ChunkContextGenerator. TnsAI ships none; a missing provider fails ingest rather than publishing a half-contextualised index.
  • Field Details

    • DISPLAY_BODY_METADATA_KEY

      public static final String DISPLAY_BODY_METADATA_KEY
      Metadata key holding the original chunk body when a prefix is indexed. Retrieval output uses this value so the prefix stays index-only.
      Since:
      0.15.0
      See Also:
    • MAX_PREFIX_CHARS

      public static final int MAX_PREFIX_CHARS
      Maximum length of a structural or generated prefix, in characters (~100 tokens). Longer provider output is truncated before indexing.
      Since:
      0.15.0
      See Also:
    • MAX_SURROUNDING_CHARS

      public static final int MAX_SURROUNDING_CHARS
      Maximum characters of adjacent-chunk text passed to an LLM generator as surrounding context.
      Since:
      0.15.0
      See Also:
  • Method Details

    • values

      public static ChunkContext[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ChunkContext valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • modelVisibleContent

      public static String modelVisibleContent(String indexedContent, Map<String,?> metadata)
      Returns the model-visible chunk body: the stored display body when present, otherwise the indexed content.
      Parameters:
      indexedContent - text stored for embedding and BM25
      metadata - ingest metadata, possibly containing DISPLAY_BODY_METADATA_KEY
      Returns:
      original body, or indexedContent when none was stored
      Since:
      0.15.0
    • modelVisibleContent

      public static String modelVisibleContent(Document document)
      Returns the model-visible body of a stored document.
      Parameters:
      document - indexed document, possibly carrying a display body
      Returns:
      original body, or the indexed content when none was stored
      Since:
      0.15.0