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
Coroutine
Fetches a user by their identifier. Return type is optionally a
PersistedUser.Coroutine
Creates a new user based on the
User instance provided. Return type is optionally a PersistedUser.Coroutine
Inserts or updates feedback. Accepts a
Feedback instance and returns a string as an identifier of the persisted feedback.Coroutine
Deletes a feedback by
feedback_id. Return True if it was successful.Coroutine
Adds a new element to the data layer. Accepts
ElementDict as an argument.Coroutine
Retrieves an element by
thread_id and element_id. Return type is optionally an ElementDict.Coroutine
Deletes an element given its identifier
element_id.Coroutine
Creates a new step in the data layer. Accepts
StepDict as an argument.Coroutine
Updates an existing step. Accepts
StepDict as an argument.Coroutine
Deletes a step given its identifier
step_id.Coroutine
Fetches the author of a given thread by
thread_id. Returns a string representing the author identifier.Coroutine
Deletes a thread given its identifier
thread_id.Coroutine
Lists threads based on
pagination and filters arguments. Returns a PaginatedResponse[ThreadDict].Coroutine
Retrieves a thread by its identifier
thread_id. Return type is optionally a ThreadDict.Coroutine
Updates a thread’s details like name, user_id, metadata, and tags. Arguments are mostly optional.
Coroutine
Deletes a user session given its identifier
id. Returns a boolean value indicating success.Coroutine
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.
Coroutine
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
Decorator
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.