From 311fca724c15d1f498c75f6f0552515b1c0e0322 Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Mon, 5 Feb 2024 13:15:22 +0100 Subject: [PATCH] add force refresh for topic clustering --- semantic_router/text.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/semantic_router/text.py b/semantic_router/text.py index 3d56e374..17fbc4a3 100644 --- a/semantic_router/text.py +++ b/semantic_router/text.py @@ -148,7 +148,7 @@ class Conversation(BaseModel): for message in topic.docs: self.topics.append((i, message)) - def split_by_topic(self) -> Tuple[List[Tuple[int, str]], List[DocumentSplit]]: + def split_by_topic(self, force: bool = False) -> Tuple[List[Tuple[int, str]], List[DocumentSplit]]: """ Splits the messages into topics based on their semantic similarity. @@ -166,6 +166,10 @@ class Conversation(BaseModel): ) new_topics: List[DocumentSplit] = [] + if self.topics: + # reset self.topics + self.topics = [] + # Get unclusteed messages. unclustered_messages = self.messages[len(self.topics) :] if not unclustered_messages: -- GitLab