Class NeverEvictStrategy

java.lang.Object
org.springframework.ai.tool.toolsearch.eviction.NeverEvictStrategy
All Implemented Interfaces:
ToolIndexEvictionStrategy

public final class NeverEvictStrategy extends Object implements ToolIndexEvictionStrategy
A ToolIndexEvictionStrategy that never evicts sessions automatically.

Tool indexes persist across requests for the lifetime of the ToolSearchToolCallingAdvisor bean, or until explicitly released via ToolSearchToolCallingAdvisor#evictSession(String).

Memory warning: this strategy accumulates one index entry per distinct session ID and never frees them. In a service that handles many short-lived conversations (e.g. HTTP sessions, anonymous users) the index map will grow without bound, eventually exhausting heap (Lucene ByteBuffersDirectory instances) or remote vector-store quota. For production deployments use LruEvictionStrategy to cap the number of concurrently retained indexes, TtlEvictionStrategy to expire idle sessions, or a CompositeEvictionStrategy combining both.

This strategy is appropriate only when the set of active sessions is small and stable (e.g. a single-user tool or a bounded pool of long-running agents), or when the application manages session lifecycle explicitly via ToolSearchToolCallingAdvisor#evictSession(String).

Since:
2.0.0
Author:
Christian Tzolov
  • Field Details

  • Method Details

    • onAccess

      public Set<String> onAccess(String sessionId)
      Description copied from interface: ToolIndexEvictionStrategy
      Called each time a session is accessed at the start of request processing.

      Implementations should update their internal tracking state for sessionId and return the set of session IDs whose tool indexes must now be cleared. The returned set must never include the currently-accessed sessionId.

      Specified by:
      onAccess in interface ToolIndexEvictionStrategy
      Parameters:
      sessionId - the session being accessed
      Returns:
      session IDs to evict; never null, may be empty
    • onRemoved

      public void onRemoved(String sessionId)
      Description copied from interface: ToolIndexEvictionStrategy
      Called after a session's tool index has been cleared — either because this strategy returned it from ToolIndexEvictionStrategy.onAccess(java.lang.String), or because of an explicit eviction request.

      Implementations should remove any internal tracking state for the evicted session.

      Specified by:
      onRemoved in interface ToolIndexEvictionStrategy
      Parameters:
      sessionId - the session that was evicted