notice
This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).
rasa.core.tracker_store
check_if_tracker_store_async
Evaluates if a tracker store object is async based on implementation of methods.
Arguments:
tracker_store
: tracker store object we're evaluating
Returns:
if the tracker store correctly implements all async methods
TrackerDeserialisationException Objects
Raised when an error is encountered while deserialising a tracker.
SerializedTrackerRepresentation Objects
Mixin class for specifying different serialization methods per tracker store.
serialise_tracker
Requires implementation to return representation of tracker.
SerializedTrackerAsText Objects
Mixin class that returns the serialized tracker as string.
serialise_tracker
Serializes the tracker, returns representation of the tracker.
SerializedTrackerAsDict Objects
Mixin class that returns the serialized tracker as dictionary.
serialise_tracker
Serializes the tracker, returns representation of the tracker.
TrackerStore Objects
Represents common behavior and interface for all TrackerStore
s.
__init__
Create a TrackerStore.
Arguments:
domain
- TheDomain
to initialize theDialogueStateTracker
.event_broker
- An event broker to publish any new events to another destination.kwargs
- Additional kwargs.
create
Factory to create a tracker store.
get_or_create_tracker
Returns tracker or creates one if the retrieval returns None.
Arguments:
sender_id
- Conversation ID associated with the requested tracker.max_event_history
- Value to update the tracker store's max event history to.append_action_listen
- Whether or not to append an initialaction_listen
.
init_tracker
Returns a Dialogue State Tracker.
create_tracker
Creates a new tracker for sender_id
.
The tracker begins with a SessionStarted
event and is initially listening.
Arguments:
sender_id
- Conversation ID associated with the tracker.append_action_listen
- Whether or not to append an initialaction_listen
.
Returns:
The newly created tracker for sender_id
.
save
Save method that will be overridden by specific tracker.
exists
Checks if tracker exists for the specified ID.
This method may be overridden by the specific tracker store for faster implementations.
Arguments:
conversation_id
- Conversation ID to check if the tracker exists.
Returns:
True
if the tracker exists, False
otherwise.
retrieve
Retrieves tracker for the latest conversation session.
This method will be overridden by the specific tracker store.
Arguments:
sender_id
- Conversation ID to fetch the tracker for.
Returns:
Tracker containing events from the latest conversation sessions.
retrieve_full_tracker
Retrieve method for fetching all tracker events across conversation sessions\ that may be overridden by specific tracker.
The default implementation uses self.retrieve()
.
Arguments:
conversation_id
- The conversation ID to retrieve the tracker for.
Returns:
The fetch tracker containing all events across session starts.
get_or_create_full_tracker
Returns tracker or creates one if the retrieval returns None.
Arguments:
sender_id
- Conversation ID associated with the requested tracker.append_action_listen
- Whether to append an initialaction_listen
.
Returns:
The tracker for the conversation ID.
stream_events
Streams events to a message broker.
keys
Returns the set of values for the tracker store's primary key.
deserialise_tracker
Deserializes the tracker and returns it.
domain
Returns the domain of the tracker store.
InMemoryTrackerStore Objects
Stores conversation history in memory.
__init__
Initializes the tracker store.
save
Updates and saves the current conversation state.
retrieve
Returns tracker matching sender_id.
keys
Returns sender_ids of the Tracker Store in memory.
retrieve_full_tracker
Returns tracker matching sender_id.
Arguments:
sender_id
- Conversation ID to fetch the tracker for.
RedisTrackerStore Objects
Stores conversation history in Redis.
__init__
Initializes the tracker store.
save
Saves the current conversation state.
retrieve
Retrieves tracker for the latest conversation session.
The Redis key is formed by appending a prefix to sender_id.
Arguments:
sender_id
- Conversation ID to fetch the tracker for.
Returns:
Tracker containing events from the latest conversation sessions.
retrieve_full_tracker
Retrieves tracker for all conversation sessions.
The Redis key is formed by appending a prefix to sender_id.
Arguments:
sender_id
- Conversation ID to fetch the tracker for.
Returns:
Tracker containing events from all conversation sessions.
keys
Returns keys of the Redis Tracker Store.
DynamoTrackerStore Objects
Stores conversation history in DynamoDB.
__init__
Initialize DynamoTrackerStore
.
Arguments:
domain
- Domain associated with this tracker store.table_name
- The name of the DynamoDB table, does not need to be present a priori.region
- The name of the region associated with the client. A client is associated with a single region.event_broker
- An event broker used to publish events.kwargs
- Additional kwargs.
get_or_create_table
Returns table or creates one if the table name is not in the table list.
save
Saves the current conversation state.
serialise_tracker
Serializes the tracker, returns object with decimal types.
DynamoDB cannot store float
s, so we'll convert them to Decimal
s.
retrieve
Retrieve dialogues for a sender_id in reverse-chronological order.
Based on the session_date sort key.
retrieve_full_tracker
Retrieves tracker for all conversation sessions.
Arguments:
sender_id
- Conversation ID to fetch the tracker for.
keys
Returns sender_ids of the DynamoTrackerStore
.
MongoTrackerStore Objects
Stores conversation history in Mongo.
Property methods: conversations: returns the current conversation
conversations
Returns the current conversation.
save
Saves the current conversation state.
retrieve
Retrieves tracker for the latest conversation session.
retrieve_full_tracker
Fetching all tracker events across conversation sessions.
keys
Returns sender_ids of the Mongo Tracker Store.
is_postgresql_url
Determine whether url
configures a PostgreSQL connection.
Arguments:
url
- SQL connection URL.
Returns:
True
if url
is a PostgreSQL connection URL.
create_engine_kwargs
Get sqlalchemy.create_engine()
kwargs.
Arguments:
url
- SQL connection URL.
Returns:
kwargs to be passed into sqlalchemy.create_engine()
.
ensure_schema_exists
Ensure that the requested PostgreSQL schema exists in the database.
Arguments:
session
- Session used to inspect the database.
Raises:
ValueError
if the requested schema does not exist.
validate_port
Ensure that port can be converted to integer.
Raises:
RasaException if port cannot be cast to integer.
SQLTrackerStore Objects
Store which can save and retrieve trackers from an SQL database.
SQLEvent Objects
Represents an event in the SQL Tracker Store.
get_db_url
Build an SQLAlchemy URL
object representing the parameters needed
to connect to an SQL database.
Arguments:
dialect
- SQL database type.host
- Database network host.port
- Database network port.db
- Database name.username
- User name to use when connecting to the database.password
- Password for database user.login_db
- Alternative database name to which initially connect, and create the database specified bydb
(PostgreSQL only).query
- Dictionary of options to be passed to the dialect and/or the DBAPI upon connect.
Returns:
URL ready to be used with an SQLAlchemy dialect
0 object.
session_scope
Provide a transactional scope around a series of operations.
keys
Returns sender_ids of the SQLTrackerStore.
retrieve
Retrieves tracker for the latest conversation session.
retrieve_full_tracker
Fetching all tracker events across conversation sessions.
save
Update database with events from the current conversation.
FailSafeTrackerStore Objects
Tracker store wrapper.
Allows a fallback to a different tracker store in case of errors.
__init__
Create a FailSafeTrackerStore
.
Arguments:
tracker_store
- Primary tracker store.on_tracker_store_error
- Callback which is called when there is an error in the primary tracker store.fallback_tracker_store
- Fallback tracker store.
domain
Returns the domain of the primary tracker store.
fallback_tracker_store
Returns the fallback tracker store.
on_tracker_store_error
Calls the callback when there is an error in the primary tracker store.
retrieve
Calls retrieve
method of primary tracker store.
keys
Calls keys
method of primary tracker store.
save
Calls save
method of primary tracker store.
retrieve_full_tracker
Calls retrieve_full_tracker
method of primary tracker store.
Arguments:
sender_id
- The sender id of the tracker to retrieve.
on_tracker_store_retrieve_error
Calls _on_tracker_store_error
callable attribute if set.
Otherwise, logs the error.
Arguments:
error
- The error that occurred.
create_tracker_store
Creates a tracker store based on the current configuration.
AwaitableTrackerStore Objects
Wraps a tracker store so it can be implemented with async overrides.
__init__
Create a AwaitableTrackerStore
.
Arguments:
tracker_store
- the wrapped tracker store.
domain
Returns the domain of the primary tracker store.
domain
Setter method to modify the wrapped tracker store's domain field.
create
Wrapper to call create
method of primary tracker store.
retrieve
Wrapper to call retrieve
method of primary tracker store.
keys
Wrapper to call keys
method of primary tracker store.
save
Wrapper to call save
method of primary tracker store.
retrieve_full_tracker
Wrapper to call retrieve_full_tracker
method of primary tracker store.