Package com.tnsai.context.snapshot
Interface SnapshotStore
public interface SnapshotStore
Interface for storing and retrieving context snapshots.
SnapshotStore provides persistence for context snapshots, enabling:
- Historical state retrieval
- Decision auditing
- Recovery and debugging
Usage Example
SnapshotStore store = new InMemorySnapshotStore();
// Store snapshot
ContextSnapshot snapshot = contextManager.createSnapshot(SnapshotTrigger.PRE_DECISION);
store.save(snapshot);
// Retrieve by ID
Optional<ContextSnapshot> retrieved = store.findById(snapshot.getSnapshotId());
// Query by time range
List<ContextSnapshot> recent = store.findByTimeRange(
Instant.now().minusHours(1),
Instant.now()
);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordStatistics about the snapshot store. -
Method Summary
Modifier and TypeMethodDescriptionintcount()Counts total snapshots in the store.intcountByAgent(String agentId) Counts snapshots for an agent.booleanDeletes a snapshot by ID.intdeleteByAgent(String agentId) Deletes all snapshots for an agent.intdeleteOlderThan(Instant before) Deletes snapshots older than a specified time.findByAgent(String agentId) Finds all snapshots for an agent.findByAgentAndTimeRange(String agentId, Instant start, Instant end) Finds snapshots for an agent within a time range.findByConversation(String conversationId) Finds snapshots for a conversation.Finds a snapshot by ID.findByTimeRange(Instant start, Instant end) Finds snapshots within a time range.findByTrigger(SnapshotTrigger trigger) Finds snapshots by trigger type.findLatestByAgent(String agentId) Finds the most recent snapshot for an agent.Gets store statistics.voidsave(ContextSnapshot snapshot) Saves a context snapshot.
-
Method Details
-
save
Saves a context snapshot.- Parameters:
snapshot- snapshot to save
-
findById
Finds a snapshot by ID.- Parameters:
snapshotId- snapshot identifier- Returns:
- Optional containing the snapshot if found
-
findLatestByAgent
Finds the most recent snapshot for an agent.- Parameters:
agentId- agent identifier- Returns:
- Optional containing the most recent snapshot if any exist
-
findByAgent
Finds all snapshots for an agent.- Parameters:
agentId- agent identifier- Returns:
- list of snapshots, ordered by timestamp descending
-
findByTrigger
Finds snapshots by trigger type.- Parameters:
trigger- snapshot trigger type- Returns:
- list of matching snapshots
-
findByTimeRange
Finds snapshots within a time range.- Parameters:
start- start of time range (inclusive)end- end of time range (inclusive)- Returns:
- list of snapshots in the time range
-
findByAgentAndTimeRange
Finds snapshots for an agent within a time range.- Parameters:
agentId- agent identifierstart- start of time range (inclusive)end- end of time range (inclusive)- Returns:
- list of snapshots
-
findByConversation
Finds snapshots for a conversation.- Parameters:
conversationId- conversation identifier- Returns:
- list of snapshots for the conversation
-
delete
Deletes a snapshot by ID.- Parameters:
snapshotId- snapshot identifier- Returns:
- true if snapshot was deleted
-
deleteByAgent
Deletes all snapshots for an agent.- Parameters:
agentId- agent identifier- Returns:
- number of deleted snapshots
-
deleteOlderThan
Deletes snapshots older than a specified time.- Parameters:
before- delete snapshots before this time- Returns:
- number of deleted snapshots
-
count
int count()Counts total snapshots in the store.- Returns:
- snapshot count
-
countByAgent
Counts snapshots for an agent.- Parameters:
agentId- agent identifier- Returns:
- snapshot count for the agent
-
getStatistics
SnapshotStore.SnapshotStoreStatistics getStatistics()Gets store statistics.- Returns:
- store statistics
-