Skip to content

Commit

Permalink
Mondodb connection improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
nvenkat94 committed Feb 19, 2024
1 parent f61b857 commit 064aa9d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 27 in libs/community/langchain_community/chat_message_histories/mongodb.py

View workflow job for this annotation

GitHub Actions / cd libs/community / - / make lint #3.8

Ruff (E501)

langchain_community/chat_message_histories/mongodb.py:27:89: E501 Line too long (93 > 88)

Check failure on line 27 in libs/community/langchain_community/chat_message_histories/mongodb.py

View workflow job for this annotation

GitHub Actions / cd libs/community / - / make lint #3.11

Ruff (E501)

langchain_community/chat_message_histories/mongodb.py:27:89: E501 Line too long (93 > 88)
"""

def __init__(
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 064aa9d

Please sign in to comment.