Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo index creation #17748

Merged
merged 7 commits into from
Mar 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class MongoDBChatMessageHistory(BaseChatMessageHistory):
of a single chat session.
database_name: name of the database to use
collection_name: name of the collection to use
create_index: whether to create an index with name SessionId. Set to False if
such an index already exists.
"""

def __init__(
Expand All @@ -38,6 +40,7 @@ def __init__(
session_id: str,
database_name: str = DEFAULT_DBNAME,
collection_name: str = DEFAULT_COLLECTION_NAME,
create_index: bool = True,
):
from pymongo import MongoClient, errors

Expand All @@ -53,7 +56,8 @@ def __init__(

self.db = self.client[database_name]
self.collection = self.db[collection_name]
self.collection.create_index("SessionId")
if create_index:
self.collection.create_index("SessionId")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you ever want to specify index_name as well? if so could there be one paramter

index_name: Optional[str] = "SessionID"

and if index_name is None then you skip index creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the 'index_name' parameter is not necessary at the moment. However, we currently use 'SessionID' in three other places. If provided, users can modify the key name as they wish. If you wish add index_name parameter, I can do it.


@property
def messages(self) -> List[BaseMessage]: # type: ignore
Expand Down
Loading