From 30ebd1d61026f068699b93a344c32af386a892f3 Mon Sep 17 00:00:00 2001
From: Siraj R Aizlewood <siraj@aurelio.ai>
Date: Thu, 1 Feb 2024 00:34:09 +0400
Subject: [PATCH] Simplified If Statement in Conversation Class

---
 semantic_router/schema.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/semantic_router/schema.py b/semantic_router/schema.py
index 1f4bc5f0..129d154a 100644
--- a/semantic_router/schema.py
+++ b/semantic_router/schema.py
@@ -121,8 +121,9 @@ class Conversation(BaseModel):
         # Use the splitter to split the documents
         new_topics = self.splitter(docs)
         
-        # Check if the first new topic includes any of the new messages
-        if any(message in new_topics[0].docs for message in docs[-len(unclustered_messages):]):
+        # Check if the first new topic includes the first new message.
+        # This means that the first new message shares the same topic as the last old message to have been assigned a topic.
+        if docs[-len(unclustered_messages)] in new_topics[0].docs:
             start = self.topics[-1][0]
         else:
             start = len(self.topics) + 1
-- 
GitLab