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

feat(azure-cosmosdb): add session context for a user mongodb #7436

Merged
merged 10 commits into from
Jan 18, 2025

Conversation

crisjy
Copy link
Contributor

@crisjy crisjy commented Dec 27, 2024

Fixes # (issue)

Copy link

vercel bot commented Dec 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jan 18, 2025 8:12am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jan 18, 2025 8:12am

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 27, 2024
@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Dec 27, 2024
Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me!

@sinedied do you mind giving this a look?

@jacoblee93 jacoblee93 added question Further information is requested lgtm PRs that are ready to be merged as-is labels Jan 2, 2025
Copy link
Contributor

@sinedied sinedied left a comment

Choose a reason for hiding this comment

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

Thanks @crisjy !
The context handling looks fine here, but you're missing user handling, which is needed to list/delete sessions otherwise you have no distinction of users.

What we did in the other CosmosDB implementation is make userId parameter optional in the DB options and set it to anonymous by default to keep compatibility with other implementation (or when user handling is not needed).

async clearAllSessions() {
await this.initialize();
try {
await this.collection.deleteMany({});
Copy link
Contributor

Choose a reason for hiding this comment

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

This would delete all sessions for all users, which might not be the intended behavior... I think you missed the user handling here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, add user id as handle for sessions, thank you for your comment!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you forgot to update this call to filter it for the current user only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add user id as handler to clear sessions

@jacoblee93
Copy link
Collaborator

@crisjy let me know when this is ready for another look!

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 12, 2025
@crisjy
Copy link
Contributor Author

crisjy commented Jan 12, 2025

@crisjy let me know when this is ready for another look!

@jacoblee93 @sinedied resolve comments for this pr, sorry for delay, could you help me to have a look? thank you!

Copy link
Contributor

@sinedied sinedied left a comment

Choose a reason for hiding this comment

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

Thanks, the update with userId support looks great!

Though you forgot to add the filter for the current userId on the getAllSessions() and clearAllSessions() methods, as it should apply only to the current users. Should be a quick fix :)


async getAllSessions(): Promise<ChatSessionMongo[]> {
await this.initialize();
const documents = await this.collection.find().toArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing user filter here

async clearAllSessions() {
await this.initialize();
try {
await this.collection.deleteMany({});
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you forgot to update this call to filter it for the current user only

@crisjy
Copy link
Contributor Author

crisjy commented Jan 14, 2025

@sinedied @jacoblee93 comments resolved, could you help me have another look? Thank you!

@sinedied
Copy link
Contributor

LGTM, thanks!

@crisjy
Copy link
Contributor Author

crisjy commented Jan 15, 2025

@jacoblee93 Hi jacob, could you help me have another look at this PR, thanks!


try {
await this.collection.updateOne(
{ [ID_KEY]: this.sessionId },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need [ID_USER]: this.userId, here too?

I assume this is sufficient in this case to just pass id?

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

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

Thank you!

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Jan 18, 2025
@jacoblee93 jacoblee93 changed the title add session context for a user mongodb feat(azure-cosmosdb): add session context for a user mongodb Jan 18, 2025
@jacoblee93 jacoblee93 removed the question Further information is requested label Jan 18, 2025
@jacoblee93 jacoblee93 merged commit 3a1131a into langchain-ai:main Jan 18, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants