mirror of
https://github.com/langchain-ai/langchain-postgres.git
synced 2026-07-16 01:33:18 -04:00
Why should session_id be a valid UUID? #47
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lgabs on GitHub (Sep 27, 2024).
Why should session_id be a valid UUID? The session_id is used as a unique identifier for the chat session, but why must clients enforce it to be a valid UUID? Is there a specific reason for this? Couldn't it simply be a unique identifier that makes sense to the client?
For example, I'm using LangChain in production, and the customer support platform uses a different type of unique identifier. I would like to use that identifier without the need to create a mapping to a UUID instance. I assume many LangChain users could encounter the same issue when working with systems where they cannot change the session_id creation method.
https://github.com/langchain-ai/langchain-postgres/blob/b72b86a23513f7c9deaebba3a6ab316725585f55/langchain_postgres/chat_message_histories.py#L191-L196
@shamspias commented on GitHub (Oct 16, 2024):
Hey @lgabs,
Great question about the
session_idneeding to be a UUID. The reason we use UUIDs is mainly for ensuring that each session ID is unique and doesn't clash with others, especially when data is spread across different systems or databases. UUIDs are pretty good at preventing these kinds of conflicts without needing any central setup to keep track of IDs.For systems like yours that use a different type of ID, this might feel a bit restrictive. Technically, as long as the IDs are unique within your application, it shouldn’t be a problem. The current setup is more about playing it safe on the side of universal uniqueness.
Hope that clears things up!
Cheers!
@lgabs commented on GitHub (Nov 1, 2024):
Thanks for the clarification @shamspias ! I do understand why UUIDs are so useful, but why should this implementation enforce them? As you said, "Technically, as long as the IDs are unique within your application, it shouldn’t be a problem", that's also my point: if you have a system with unique IDs (but not UUIDs) and want to use langchain-postgres for chat_history, it will raise the referenced error. IMHO, the client using the library is responsible for enforcing IDs uniqueness.
@shamspias commented on GitHub (Nov 2, 2024):
Well, they have to follow standards somehow. If you do it differently, you can override the class—it’s actually easy to do!