Interface TokenCountEstimator

All Known Implementing Classes:
AzureOpenAiEmbeddingModel, OpenAiEmbeddingModel

public interface TokenCountEstimator
Represents an interface for estimating the count of tokens in various texts, text segments, etc. This can be useful when it's necessary to know in advance the cost of processing a specified text by the LLM.
  • Method Summary

    Modifier and Type
    Method
    Description
    default int
    Estimates the count of tokens in the given text segment.
    int
    Estimates the count of tokens in the given text.
    default int
    Estimates the count of tokens in the given text segments.
  • Method Details

    • estimateTokenCount

      int estimateTokenCount(String text)
      Estimates the count of tokens in the given text.
      Parameters:
      text - the text.
      Returns:
      the estimated count of tokens.
    • estimateTokenCount

      default int estimateTokenCount(TextSegment textSegment)
      Estimates the count of tokens in the given text segment.

      The metadata will not be included in the estimate.

      Parameters:
      textSegment - the text segment.
      Returns:
      the estimated count of tokens.
    • estimateTokenCount

      default int estimateTokenCount(List<TextSegment> textSegments)
      Estimates the count of tokens in the given text segments.

      The metadata will not be included in the estimate.

      Parameters:
      textSegments - the text segments.
      Returns:
      the estimated count of tokens.