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

[FEATURE] Generate new chat IDs automatically as a default parameter #1108

Closed
InAnYan opened this issue May 14, 2024 · 5 comments
Closed

[FEATURE] Generate new chat IDs automatically as a default parameter #1108

InAnYan opened this issue May 14, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@InAnYan
Copy link
Contributor

InAnYan commented May 14, 2024

Is your feature request related to a problem? Please describe.

I guess it is not a problem.

I was trying to investigate, why chatId has the type Object. And I found out in MessageWindowChatMemory.Builder that the default argument for chat ID is static and is always equal to string "default".

I though that whenever I instantiate a ChatMemory object (its children I mean), it automatically generates a new unique ID. But I guess it is not? I have not tested this, but I can see this from the code.

Describe the solution you'd like

Let MessageWindowChatMemory.Builder generate a random ID (for example, a UUID) if the programmer has not provided a value.

Describe alternatives you've considered
No, actually.

Of course, there is an alternative: just let the end programmer handle chat ID's.

I don't like this alternative for two reasons:

  • For example, I'm prototyping an AI app that has several chats. I initially expected that langchain4j would generate unique ID's for the chats, so I can focus only on my app's logic.
  • The documentation did not mention that the default argument for chat ID is static.

Additional context
Actually, I may understand why this approach was chosen initially.

I've provided an example of how a programmer would make a prototype app with langchain4j. And maybe the programmer does not use its own ChatMemoryStore object, and langchain4j will automatically generate it for the programmer, if he did not provide any. So, in the result for every chat there will be a separate ChatMemoryStore and so we it is appropriate to use a static ID.

In the application I am developing now, I have a class for storing a global AI state, and it contains a ChatMemoryStore object. So I explicitly specified it in MessageWindowChatMemory.Builder. But then, the chat ID is the same for any other chat objects.

Post Scriptum
TL;DR

I think you all will understand what I mean when I provide a pull request.

@InAnYan InAnYan added the enhancement New feature or request label May 14, 2024
@InAnYan
Copy link
Contributor Author

InAnYan commented May 14, 2024

OMG, did I made a pull request in my local fork?

One moment please...

@InAnYan InAnYan mentioned this issue May 14, 2024
6 tasks
@langchain4j
Copy link
Owner

Hi @InAnYan, there is indeed "default" memory id, in case user didn't specify one explicitly. This is also in sync with AiServices: if there is no parameter annotated with @memoryid in the AI Service method, "default" is used and it matches "default" from ChatMemory impl. This is handy for prototyping (when you have only one user), but in a real world you might want to have separate memories for separate users. This is where @memoryid comes into play and user should provide the id explicitly. Otherwise AI Services has no idea for which memory/user/conversation the call belongs to.

@InAnYan
Copy link
Contributor Author

InAnYan commented May 15, 2024

Okay, I see it's a bit complicated than I thought.

Then yes, maybe it's better for the programmer to maintain chat IDs explicitly.

What about adding a note to the documentation:

The default chat ID is static, so if you provide your own ChatMemoryStore, do not forget to pass a unique ID.

Umm, not the best docstring, but that's the idea.

@langchain4j
Copy link
Owner

Good point, I have added more content to this section https://docs.langchain4j.dev/tutorials/ai-services#chat-memory

And added a note about "default" memory id. Does it look good? Thanks!

@InAnYan
Copy link
Contributor Author

InAnYan commented May 15, 2024

Perfect! Thanks

@InAnYan InAnYan closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants