Package com.tnsai.rag

Record Class KnowledgeSelection

java.lang.Object
java.lang.Record
com.tnsai.rag.KnowledgeSelection
Record Components:
entries - the sources in scope, in declaration order
search - the merged search configuration over the SEARCH sources, or empty when the scope has none; its sources are the SEARCH names

public record KnowledgeSelection(List<KnowledgeEntry> entries, Optional<RetrievalConfig> search) extends Record
The knowledge one scope sees: an action's named sources, or a chat turn's whole agent knowledge.

Every source behaves by its own Knowledge.Use: DIRECT sources enter whole, SEARCH sources run through one engine configured by search(), and a SEQUENTIAL source contributes its next unit. The blocks join in entries() order, which is declaration order.

Since:
0.18.0
  • Field Details

    • EMPTY

      public static final KnowledgeSelection EMPTY
      A scope that sees no knowledge.
    • DEFAULT_DIRECT_SHARE_PERCENT

      public static final int DEFAULT_DIRECT_SHARE_PERCENT
      Share of the model input window DIRECT sources may fill by default.
      See Also:
  • Constructor Details

    • KnowledgeSelection

      public KnowledgeSelection(List<KnowledgeEntry> entries, Optional<RetrievalConfig> search)
      Creates an instance of a KnowledgeSelection record class.
      Parameters:
      entries - the value for the entries record component
      search - the value for the search record component
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns:
      true when the scope sees no knowledge
    • sources

      public List<KnowledgeSourceConfig> sources()
      Returns:
      the source configurations in scope, in declaration order
    • entries

      public List<KnowledgeEntry> entries(Knowledge.Use use)
      Parameters:
      use - a usage mode
      Returns:
      the entries with that mode, in declaration order
    • needsInputWindow

      public boolean needsInputWindow()
      Returns:
      true when a DIRECT source relies on the default budget, which needs the model input window
    • requireDirectBudget

      public void requireDirectBudget(Map<String,Integer> measuredTokens, int maxInputTokens)
      Checks the DIRECT sources' measured size against their budgets.

      A source with maxTokens must fit that on its own. The sources without it share 25% of the model input window, counted over their sum. Nothing falls back to search: a source that does not fit is a configuration error. Every failure names the source, its measured tokens and the budget; a shared-budget failure lists each source's tokens and their sum.

      Parameters:
      measuredTokens - tokens each DIRECT source renders to, by name
      maxInputTokens - the model input window, or a non-positive value when it is unknown
      Throws:
      IllegalStateException - when a source is over its budget, or the default budget is needed and the window is unknown
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • entries

      public List<KnowledgeEntry> entries()
      Returns the value of the entries record component.
      Returns:
      the value of the entries record component
    • search

      public Optional<RetrievalConfig> search()
      Returns the value of the search record component.
      Returns:
      the value of the search record component