Class TemporalRAGStrategy

java.lang.Object
com.tnsai.intelligence.rag.TemporalRAGStrategy
All Implemented Interfaces:
RAGStrategy

public final class TemporalRAGStrategy extends Object implements RAGStrategy
Re-ranks content-relevant child hits with bounded time decay.

Freshness affects only twenty percent of the default score multiplier; the remaining relevance floor protects a clearly relevant older document from being displaced solely because another document is newer. Undated documents receive the conservative floor. Small future-clock skew is clamped to the retrieval instant, while excessive future dates fail loudly.

Since:
0.13.0
  • Field Details

    • DEFAULT_HALF_LIFE

      public static final Duration DEFAULT_HALF_LIFE
      Default interval after which the freshness component halves.
    • DEFAULT_RELEVANCE_FLOOR

      public static final double DEFAULT_RELEVANCE_FLOOR
      Default minimum fraction of content relevance retained.
      See Also:
    • DEFAULT_MAX_FUTURE_SKEW

      public static final Duration DEFAULT_MAX_FUTURE_SKEW
      Default tolerated producer/consumer clock skew.
  • Constructor Details

    • TemporalRAGStrategy

      public TemporalRAGStrategy(RAGStrategy childStrategy, TemporalIndex index, Set<String> allowedSources, Clock clock, Duration halfLife, double relevanceFloor, Duration maxFutureSkew)
      Creates a temporal retrieval strategy.
      Parameters:
      childStrategy - strategy producing content-relevant candidates
      index - indexed documents and canonical timestamps
      allowedSources - selected source groups; empty allows every group
      clock - retrieval clock, injectable for deterministic behavior
      halfLife - interval after which freshness decays by half
      relevanceFloor - minimum content-score multiplier, from zero to one
      maxFutureSkew - tolerated future timestamp offset
  • Method Details

    • name

      public String name()
      Description copied from interface: RAGStrategy
      Returns the unique name of this strategy (e.g., "vector", "keyword", "hybrid").

      Names are compared case-insensitively using Locale.ROOT.

      Specified by:
      name in interface RAGStrategy
      Returns:
      the strategy name, never null
    • retrieve

      public List<RetrievedDocument> retrieve(String query, RAGContext context)
      Description copied from interface: RAGStrategy
      Retrieves documents relevant to the given query.

      Every returned document must exactly match all metadata filters in the context. Implementations apply that constraint before limiting the result to RAGContext.maxResults().

      Specified by:
      retrieve in interface RAGStrategy
      Parameters:
      query - the search query (never null)
      context - retrieval parameters (max results, min score, exact metadata filters)
      Returns:
      an unmodifiable list of retrieved documents, sorted by descending relevance