diff --git a/libs/community/langchain_community/chat_message_histories/mongodb.py b/libs/community/langchain_community/chat_message_histories/mongodb.py index 5865f86b13c00..f1cdfc4d9c0fb 100644 --- a/libs/community/langchain_community/chat_message_histories/mongodb.py +++ b/libs/community/langchain_community/chat_message_histories/mongodb.py @@ -24,6 +24,7 @@ class MongoDBChatMessageHistory(BaseChatMessageHistory): of a single chat session. database_name: name of the database to use collection_name: name of the collection to use + index_creation: bool for collection index-creation. By default index_creation is True """ def __init__( @@ -32,6 +33,7 @@ def __init__( session_id: str, database_name: str = DEFAULT_DBNAME, collection_name: str = DEFAULT_COLLECTION_NAME, + index_creation:bool =True ): from pymongo import MongoClient, errors @@ -47,7 +49,11 @@ def __init__( self.db = self.client[database_name] self.collection = self.db[collection_name] - self.collection.create_index("SessionId") + if index_creation: + """ + Conditional Index Creation for collection + """ + self.collection.create_index("SessionId") @property def messages(self) -> List[BaseMessage]: # type: ignore