Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.ai.chatting

public Class InMemoryChatHistoryCache

extends Object
Class Inheritance
Imports
java.util.Collections, .IdentityHashMap, .Map, .Optional, javafx.collections.FXCollections, .ObservableList, org.jabref.logic.ai.chatting.repositories.ChatHistoryRepository, org.jabref.model.ai.chatting.ChatIdentifier, .ChatMessage, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, org.jabref.model.groups.GroupTreeNode, org.slf4j.Logger, .LoggerFactory

An in-memory storage layer for chat history with BibEntry. This allows to have an AI chat even if the entry does not have a citation key or it is not unique.

At the close of JabRef the chats are flushed to the on-disk storage (ChatHistoryRepository).

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static record

Field Summary

Modifier and TypeField and Description
private final Map<BibEntry, InMemoryChatHistoryCache.CachedEntryChat>
private final Map<GroupTreeNode, InMemoryChatHistoryCache.CachedGroupChat>
private static final Logger
private final ChatHistoryRepository

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
private void
flushChat(boolean entityExists, ChatIdentifier currentIdentifier, String originalName, String currentName, ObservableList<ChatMessage> chatHistory, String entityType)

Generic flush logic for both entry and group chats

private void
private void
public synchronized ObservableList<ChatMessage>

Returns:

the live, mutable chat history
getForEntry
(BibDatabaseContext
the database context for the entry (needed for persistence)
databaseContext
,
BibEntry
the entry to get chat history for
entry
)

Returns the chat history for entry.

public synchronized ObservableList<ChatMessage>

Returns:

the live, mutable chat history
getForGroup
(BibDatabaseContext
the database context for the group (needed for persistence)
databaseContext
,
GroupTreeNode
the group to get chat history for
group
)

Returns the chat history for group.

public synchronized void
removeEntry(BibEntry entry)

Removes the cached chat history for an entry.

public synchronized void
removeGroup(GroupTreeNode group)

Removes the cached chat history for a group.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryChatsback to summary
private final Map<BibEntry, InMemoryChatHistoryCache.CachedEntryChat> entryChats
groupChatsback to summary
private final Map<GroupTreeNode, InMemoryChatHistoryCache.CachedGroupChat> groupChats
LOGGERback to summary
private static final Logger LOGGER
repositoryback to summary
private final ChatHistoryRepository repository

Constructor Detail

InMemoryChatHistoryCacheback to summary
public InMemoryChatHistoryCache(ChatHistoryRepository repository)

Method Detail

closeback to summary
public synchronized void close()
flushChatback to summary
private void flushChat(boolean entityExists, ChatIdentifier currentIdentifier, String originalName, String currentName, ObservableList<ChatMessage> chatHistory, String entityType)

Generic flush logic for both entry and group chats

flushEntryChatback to summary
private void flushEntryChat(BibEntry entry, InMemoryChatHistoryCache.CachedEntryChat cached)
flushGroupChatback to summary
private void flushGroupChat(GroupTreeNode group, InMemoryChatHistoryCache.CachedGroupChat cached)
getForEntryback to summary
public synchronized ObservableList<ChatMessage> getForEntry(BibDatabaseContext databaseContext, BibEntry entry)

Returns the chat history for entry. If none exists in RAM, loads from repository and caches it. The returned ObservableList is the primary working storage - mutations are NOT immediately persisted.

Parameters
databaseContext:BibDatabaseContext

the database context for the entry (needed for persistence)

entry:BibEntry

the entry to get chat history for

Returns:ObservableList<ChatMessage>

the live, mutable chat history

getForGroupback to summary
public synchronized ObservableList<ChatMessage> getForGroup(BibDatabaseContext databaseContext, GroupTreeNode group)

Returns the chat history for group. If none exists in RAM, loads from repository and caches it. The returned ObservableList is the primary working storage - mutations are NOT immediately persisted.

Parameters
databaseContext:BibDatabaseContext

the database context for the group (needed for persistence)

group:GroupTreeNode

the group to get chat history for

Returns:ObservableList<ChatMessage>

the live, mutable chat history

removeEntryback to summary
public synchronized void removeEntry(BibEntry entry)

Removes the cached chat history for an entry. The chat history is NOT persisted before removal - it's simply discarded from RAM.

removeGroupback to summary
public synchronized void removeGroup(GroupTreeNode group)

Removes the cached chat history for a group. The chat history is NOT persisted before removal - it's simply discarded from RAM.

org.jabref.logic.ai.chatting back to summary

private final Record InMemoryChatHistoryCache.CachedEntryChat

extends Record
Class Inheritance
Record Components
databaseContext:BibDatabaseContext 
originalCitationKey:Optional<String> 
chatHistory:ObservableList<ChatMessage> 

Field Summary

Modifier and TypeField and Description
private final ObservableList<ChatMessage>
chatHistory

Record Component accessed by chatHistory().

private final BibDatabaseContext
databaseContext

Record Component accessed by databaseContext().

private final Optional<String>
originalCitationKey

Record Component accessed by originalCitationKey().

Constructor Summary

AccessConstructor and Description
private
CachedEntryChat(BibDatabaseContext databaseContext, Optional<String> originalCitationKey, ObservableList<ChatMessage> chatHistory)

Method Summary

Modifier and TypeMethod and Description
public ObservableList<ChatMessage>
chatHistory()

Record Component getter of chatHistory.

public BibDatabaseContext
databaseContext()

Record Component getter of databaseContext.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Optional<String>
originalCitationKey()

Record Component getter of originalCitationKey.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

chatHistoryback to summary
private final ObservableList<ChatMessage> chatHistory

Record Component accessed by chatHistory().

databaseContextback to summary
private final BibDatabaseContext databaseContext

Record Component accessed by databaseContext().

originalCitationKeyback to summary
private final Optional<String> originalCitationKey

Record Component accessed by originalCitationKey().

Constructor Detail

CachedEntryChatback to summary
private CachedEntryChat(BibDatabaseContext databaseContext, Optional<String> originalCitationKey, ObservableList<ChatMessage> chatHistory)

Method Detail

chatHistoryback to summary
public ObservableList<ChatMessage> chatHistory()

Record Component getter of chatHistory.

databaseContextback to summary
public BibDatabaseContext databaseContext()

Record Component getter of databaseContext.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

originalCitationKeyback to summary
public Optional<String> originalCitationKey()

Record Component getter of originalCitationKey.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.logic.ai.chatting back to summary

private final Record InMemoryChatHistoryCache.CachedGroupChat

extends Record
Class Inheritance
Record Components
databaseContext:BibDatabaseContext 
originalGroupName:String 
group:GroupTreeNode 
chatHistory:ObservableList<ChatMessage> 

Field Summary

Modifier and TypeField and Description
private final ObservableList<ChatMessage>
chatHistory

Record Component accessed by chatHistory().

private final BibDatabaseContext
databaseContext

Record Component accessed by databaseContext().

private final GroupTreeNode
group

Record Component accessed by group().

private final String
originalGroupName

Record Component accessed by originalGroupName().

Constructor Summary

AccessConstructor and Description
private
CachedGroupChat(BibDatabaseContext databaseContext, String originalGroupName, GroupTreeNode group, ObservableList<ChatMessage> chatHistory)

Method Summary

Modifier and TypeMethod and Description
public ObservableList<ChatMessage>
chatHistory()

Record Component getter of chatHistory.

public BibDatabaseContext
databaseContext()

Record Component getter of databaseContext.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public GroupTreeNode
group()

Record Component getter of group.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
originalGroupName()

Record Component getter of originalGroupName.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

chatHistoryback to summary
private final ObservableList<ChatMessage> chatHistory

Record Component accessed by chatHistory().

databaseContextback to summary
private final BibDatabaseContext databaseContext

Record Component accessed by databaseContext().

groupback to summary
private final GroupTreeNode group

Record Component accessed by group().

originalGroupNameback to summary
private final String originalGroupName

Record Component accessed by originalGroupName().

Constructor Detail

CachedGroupChatback to summary
private CachedGroupChat(BibDatabaseContext databaseContext, String originalGroupName, GroupTreeNode group, ObservableList<ChatMessage> chatHistory)

Method Detail

chatHistoryback to summary
public ObservableList<ChatMessage> chatHistory()

Record Component getter of chatHistory.

databaseContextback to summary
public BibDatabaseContext databaseContext()

Record Component getter of databaseContext.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
groupback to summary
public GroupTreeNode group()

Record Component getter of group.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

originalGroupNameback to summary
public String originalGroupName()

Record Component getter of originalGroupName.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.