-
Notifications
You must be signed in to change notification settings - Fork 670
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
Comments
OMG, did I made a pull request in my local fork? One moment please... |
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. |
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:
Umm, not the best docstring, but that's the idea. |
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! |
Perfect! Thanks |
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 typeObject
. And I found out inMessageWindowChatMemory.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:
langchain4j
would generate unique ID's for the chats, so I can focus only on my app's logic.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 ownChatMemoryStore
object, andlangchain4j
will automatically generate it for the programmer, if he did not provide any. So, in the result for every chat there will be a separateChatMemoryStore
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 inMessageWindowChatMemory.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.
The text was updated successfully, but these errors were encountered: