Package com.tnsai.memory.vector
Class VectorSearchMemoryStore
java.lang.Object
com.tnsai.memory.vector.VectorSearchMemoryStore
- All Implemented Interfaces:
MemoryStore
Conversation
MemoryStore whose search(java.lang.String, int) is backed by a
VectorMemoryStore instead of TF-IDF.- Since:
- 0.14.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMessage(String role, String content) Adds a message to the memory.voidaddMessage(Map<String, Object> message) Adds a structured message (e.g. with tool calls) to memory.voidclear()Clears the memory.Retrieves the full conversation history.getRecentHistory(int limit) Retrieves the last N messages.voidInitializes the memory store for a specific agent.voidprune(int maxTokens) Prunes the memory to keep it within a specific token limit.voidreplaceHistory(List<Map<String, Object>> newHistory) Atomically replaces the entire conversation history with the given list.Performs a semantic search on the memory (Optional).
-
Constructor Details
-
VectorSearchMemoryStore
-
-
Method Details
-
init
Description copied from interface:MemoryStoreInitializes the memory store for a specific agent.- Specified by:
initin interfaceMemoryStore- Parameters:
agentId- The unique ID of the agent
-
addMessage
Description copied from interface:MemoryStoreAdds a message to the memory.- Specified by:
addMessagein interfaceMemoryStore- Parameters:
role- The role of the message sender (user, assistant, system)content- The text content of the message
-
addMessage
Description copied from interface:MemoryStoreAdds a structured message (e.g. with tool calls) to memory.- Specified by:
addMessagein interfaceMemoryStore- Parameters:
message- The full message object
-
getHistory
Description copied from interface:MemoryStoreRetrieves the full conversation history.- Specified by:
getHistoryin interfaceMemoryStore- Returns:
- List of message maps
-
getRecentHistory
Description copied from interface:MemoryStoreRetrieves the last N messages.- Specified by:
getRecentHistoryin interfaceMemoryStore- Parameters:
limit- Number of messages to retrieve- Returns:
- List of message maps
-
clear
public void clear()Description copied from interface:MemoryStoreClears the memory.- Specified by:
clearin interfaceMemoryStore
-
prune
public void prune(int maxTokens) Description copied from interface:MemoryStorePrunes the memory to keep it within a specific token limit. Removes oldest messages first, preserving system prompts if possible.- Specified by:
prunein interfaceMemoryStore- Parameters:
maxTokens- The maximum estimated tokens allowed
-
replaceHistory
Description copied from interface:MemoryStoreAtomically replaces the entire conversation history with the given list.Used by
MemoryConsolidationPipelineto 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 byMemoryStore.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 onAbstractMemoryStore) SHOULD override this to perform the swap under a single lock hold, making the rewrite atomic with respect to concurrent writers.- Specified by:
replaceHistoryin interfaceMemoryStore- Parameters:
newHistory- the complete new history, in order (must not be null)
-
search
Description copied from interface:MemoryStorePerforms a semantic search on the memory (Optional). Useful for RAG (Retrieval-Augmented Generation).- Specified by:
searchin interfaceMemoryStore- Parameters:
query- The search querylimit- Max results- Returns:
- List of relevant memory segments
-