BaseDataLayer class serves as an abstract foundation for data persistence operations within the Chainlit framework.
This class outlines methods for managing users, feedback, elements, steps, and threads in a chatbot application.
Methods
Creates a new user based on the
User instance provided. Return type is optionally a PersistedUser.Inserts or updates feedback. Accepts a
Feedback instance and returns a string as an identifier of the persisted feedback.Retrieves an element by
thread_id and element_id. Return type is optionally an ElementDict.Fetches the author of a given thread by
thread_id. Returns a string representing the author identifier.Lists threads based on
pagination and filters arguments. Returns a PaginatedResponse[ThreadDict].Updates a thread’s details like name, user_id, metadata, and tags. Arguments are mostly optional.
Deletes a user session given its identifier
id. Returns a boolean value indicating success.Returns the list of steps that the user has marked as favorites. Used to populate the favorite messages (prompt templates) feature in the composer. Returns a
List[StepDict].Since version 2.9.5.
Called when the Chainlit server shuts down. Use this to close database connections, HTTP sessions, or other resources held by the data layer. Must be implemented by all subclasses.
Decorators
Queues certain methods to execute only after the first user message is received, especially useful for
WebsocketSessions.Example
Due to the abstract nature ofBaseDataLayer, direct instantiation and usage are not practical without subclassing and implementing the abstract methods.
You can refer to the guide for custom data layer implementation.