Class MemoryStoreFactory

java.lang.Object
com.tnsai.memory.MemoryStoreFactory

public final class MemoryStoreFactory extends Object
Factory for creating MemoryStore instances based on MemorySpec annotation.

This factory enables annotation-driven memory configuration, creating the appropriate memory store implementation based on annotation parameters.

Supported Configurations

  • type: CONVERSATION, VECTOR, HYBRID, WORKING, EPISODIC
  • capacity: Maximum number of messages (0 = unbounded; the default of 100 is a real, enforced limit)
  • pruneStrategy: SLIDING_WINDOW, RELEVANCE, SUMMARIZE, TOKEN_LIMIT, NONE
  • persistence: IN_MEMORY, REDIS, DATABASE, FILE
  • maxContextTokens: Token limit for context window

Usage Example


 // From annotation
 MemorySpec config = agentClass.getAnnotation(MemorySpec.class);
 MemoryStore store = MemoryStoreFactory.create(config);

 // With defaults
 MemoryStore defaultStore = MemoryStoreFactory.createDefault();
 
Author:
TnsAI Team
See Also:
  • Method Details

    • create

      public static MemoryStore create(MemorySpec config)
      Creates a MemoryStore based on the given @MemorySpec annotation. Delegates to create(MemoryConfig) via MemoryConfig.from(MemorySpec) so the annotation and programmatic paths share one codepath (TNS-546).
      Parameters:
      config - the MemorySpec annotation
      Returns:
      configured MemoryStore instance
    • create

      public static MemoryStore create(MemoryConfig config)
      Creates a MemoryStore from a programmatic MemoryConfig — the canonical factory both the annotation path (create(MemorySpec)) and AgentBuilder.memoryConfig(...) flow through (TNS-546).
      Parameters:
      config - the memory configuration
      Returns:
      configured MemoryStore instance
    • createDefault

      public static MemoryStore createDefault()
      Creates a default MemoryStore (in-memory, no limits).
      Returns:
      default InMemoryStore