langchain-ai / langchain-postgres

LangChain abstractions backed by Postgres Backend
MIT License
120 stars 45 forks source link

Why should session_id be a valid UUID? #121

Open lgabs opened 3 weeks ago

lgabs commented 3 weeks ago

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 2 days ago

Hey @lgabs,

Great question about the session_id needing 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!