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

Update MongoDBChatMessageHistory to create an index on SessionId #5632

Merged
merged 1 commit into from
Jun 4, 2023
Merged

Update MongoDBChatMessageHistory to create an index on SessionId #5632

merged 1 commit into from
Jun 4, 2023

Conversation

ldesousa-stf
Copy link
Contributor

All the queries to the database are done based on the SessionId property, this will optimize how Mongo retrieves all messages from a session

Who can review?

Tag maintainers/contributors who might be interested:
@dev2049

All the queries to the database are done based on the SessionId property, this will optimize how Mongo retrieves all messages from a session
Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

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

what happens if SessionId index already exists?

@ldesousa-stf
Copy link
Contributor Author

what happens if SessionId index already exists?

According to the docs:

The db.collection.createIndex() method only creates an index if an index of the same specification does not already exist.

I already use this in other projects (including dotnet ones), this just garantees the index exists, if it's already there Mongo will do nothing.

From experience, the first times I used indexes in Mongo, I used to manually check from the application if that index already existed, but that just ends up being less optimal since there's more information going between Mongo and the application when it's just unecessary.

@ldesousa-stf ldesousa-stf requested a review from hwchase17 June 4, 2023 01:53
@hwchase17 hwchase17 merged commit c112d73 into langchain-ai:master Jun 4, 2023
@ldesousa-stf ldesousa-stf deleted the patch-1 branch June 4, 2023 23:46
Undertone0809 pushed a commit to Undertone0809/langchain that referenced this pull request Jun 19, 2023
…gchain-ai#5632)

All the queries to the database are done based on the SessionId
property, this will optimize how Mongo retrieves all messages from a
session

#### Who can review?

Tag maintainers/contributors who might be interested:
@dev2049
This was referenced Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants