pyrit.analytics.ConversationAnalytics#

class ConversationAnalytics(*, memory_interface: MemoryInterface)[source]#

Bases: object

Handles analytics operations on conversation data, such as finding similar chat messages based on conversation history or embedding similarity.

__init__(*, memory_interface: MemoryInterface)[source]#

Initializes the ConversationAnalytics with a memory interface for data access.

Parameters:

memory_interface (MemoryInterface) – An instance of MemoryInterface for accessing conversation data.

Methods

__init__(*, memory_interface)

Initializes the ConversationAnalytics with a memory interface for data access.

get_prompt_entries_with_same_converted_content(*, ...)

Retrieves chat messages that have the same converted content

get_similar_chat_messages_by_embedding(*, ...)

Retrieves chat messages that are similar to the given embedding based on cosine similarity.

get_prompt_entries_with_same_converted_content(*, chat_message_content: str) list[ConversationMessageWithSimilarity][source]#

Retrieves chat messages that have the same converted content

Parameters:

chat_message_content (str) – The content of the chat message to find similar messages for.

Returns:

A list of ConversationMessageWithSimilarity objects representing the similar chat messages based on content.

Return type:

list[ConversationMessageWithSimilarity]

get_similar_chat_messages_by_embedding(*, chat_message_embedding: list[float], threshold: float = 0.8) list[EmbeddingMessageWithSimilarity][source]#

Retrieves chat messages that are similar to the given embedding based on cosine similarity.

Parameters:
  • chat_message_embedding (List[float]) – The embedding of the chat message to find similar messages for.

  • threshold (float) – The similarity threshold for considering messages as similar. Defaults to 0.8.

Returns:

A list of ConversationMessageWithSimilarity objects representing the similar chat messages based on embedding similarity.

Return type:

List[ConversationMessageWithSimilarity]