Package com.tnsai.rag

Record Class KnowledgeUsage

java.lang.Object
java.lang.Record
com.tnsai.rag.KnowledgeUsage
Record Components:
source - the knowledge name
mode - how the source was used
documentCount - documents (or units) that reached the model
tokens - estimated tokens those documents rendered to

public record KnowledgeUsage(String source, Knowledge.Use mode, int documentCount, int tokens) extends Record
What one knowledge source gave a chat turn or an action call.

A call reports one row per enabled source in its scope, in declaration order, including a source that gave nothing (count and tokens 0):

  • DIRECT: the documents given whole and their estimated tokens
  • SEARCH: the retrieved documents that fit the context window and reached the model, attributed to the source each came from. With one SEARCH source in scope, every fitted document is that source's; a GRAPH source is always alone, so its row counts the graph evidence rendered. Tokens are the sum of each document's rendered estimate.
  • SEQUENTIAL: 1 when the source gave its next unit, 0 when it is exhausted, with that unit's estimated tokens

Actions publish the rows under RetrievalSpi.RETRIEVED_KNOWLEDGE_USAGE_KEY; an agent built with AgentBuilder.knowledgeUsageListener also receives them for each chat turn and action call.

Since:
0.18.0
  • Constructor Details

    • KnowledgeUsage

      public KnowledgeUsage(String source, Knowledge.Use mode, int documentCount, int tokens)
      Creates an instance of a KnowledgeUsage record class.
      Parameters:
      source - the value for the source record component
      mode - the value for the mode record component
      documentCount - the value for the documentCount record component
      tokens - the value for the tokens record component
  • Method Details

    • 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
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • source

      public String source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component
    • mode

      public Knowledge.Use mode()
      Returns the value of the mode record component.
      Returns:
      the value of the mode record component
    • documentCount

      public int documentCount()
      Returns the value of the documentCount record component.
      Returns:
      the value of the documentCount record component
    • tokens

      public int tokens()
      Returns the value of the tokens record component.
      Returns:
      the value of the tokens record component