Class VectorSearchMemoryStore

java.lang.Object
com.tnsai.memory.vector.VectorSearchMemoryStore
All Implemented Interfaces:
MemoryStore

public final class VectorSearchMemoryStore extends Object implements MemoryStore
Conversation MemoryStore whose search(java.lang.String, int) is backed by a VectorMemoryStore instead of TF-IDF.
Since:
0.14.0
  • Constructor Details

  • Method Details

    • init

      public void init(String agentId)
      Description copied from interface: MemoryStore
      Initializes the memory store for a specific agent.
      Specified by:
      init in interface MemoryStore
      Parameters:
      agentId - The unique ID of the agent
    • addMessage

      public void addMessage(String role, String content)
      Description copied from interface: MemoryStore
      Adds a message to the memory.
      Specified by:
      addMessage in interface MemoryStore
      Parameters:
      role - The role of the message sender (user, assistant, system)
      content - The text content of the message
    • addMessage

      public void addMessage(Map<String,Object> message)
      Description copied from interface: MemoryStore
      Adds a structured message (e.g. with tool calls) to memory.
      Specified by:
      addMessage in interface MemoryStore
      Parameters:
      message - The full message object
    • getHistory

      public List<Map<String,Object>> getHistory()
      Description copied from interface: MemoryStore
      Retrieves the full conversation history.
      Specified by:
      getHistory in interface MemoryStore
      Returns:
      List of message maps
    • getRecentHistory

      public List<Map<String,Object>> getRecentHistory(int limit)
      Description copied from interface: MemoryStore
      Retrieves the last N messages.
      Specified by:
      getRecentHistory in interface MemoryStore
      Parameters:
      limit - Number of messages to retrieve
      Returns:
      List of message maps
    • clear

      public void clear()
      Description copied from interface: MemoryStore
      Clears the memory.
      Specified by:
      clear in interface MemoryStore
    • prune

      public void prune(int maxTokens)
      Description copied from interface: MemoryStore
      Prunes the memory to keep it within a specific token limit. Removes oldest messages first, preserving system prompts if possible.
      Specified by:
      prune in interface MemoryStore
      Parameters:
      maxTokens - The maximum estimated tokens allowed
    • replaceHistory

      public void replaceHistory(List<Map<String,Object>> newHistory)
      Description copied from interface: MemoryStore
      Atomically replaces the entire conversation history with the given list.

      Used by MemoryConsolidationPipeline to swap in a consolidated history (summary + preserved messages) in a single call, minimizing the window in which concurrently added messages could be lost (TAN-5180).

      The default implementation falls back to MemoryStore.clear() followed by MemoryStore.addMessage(Map) for each message — behaviorally identical to the legacy rewrite, so existing stores remain source- and behavior-compatible. Implementations with an internal lock (e.g. those based on AbstractMemoryStore) SHOULD override this to perform the swap under a single lock hold, making the rewrite atomic with respect to concurrent writers.

      Specified by:
      replaceHistory in interface MemoryStore
      Parameters:
      newHistory - the complete new history, in order (must not be null)
    • search

      public List<String> search(String query, int limit)
      Description copied from interface: MemoryStore
      Performs a semantic search on the memory (Optional). Useful for RAG (Retrieval-Augmented Generation).
      Specified by:
      search in interface MemoryStore
      Parameters:
      query - The search query
      limit - Max results
      Returns:
      List of relevant memory segments