Rasa Custom Tracker Store

I need persist in the base when the InMemoryTrackerStore’s save method is called, how can I do this?

I created a “CustomTrackerStore”, but I do not need to pass the URL of the database, which causes an error: “got an unexpected keyword argument ‘url’”. I just need persist in the base, when InMemoryTrackerStore’s save method is called. Anyone can help me?

This is my code:

class TrackerSolr(TrackerStore):

    def __init__(
            self, domain: Domain, event_broker: Optional[EventChannel] = None
    ) -> None:
        self.store = {}
        super(TrackerSolr, self).__init__(domain, event_broker)

    def save(self, tracker: DialogueStateTracker) -> None:
        if self.event_broker:
            self.stream_events(tracker)
        serialised = self.serialise_tracker(tracker)
        # to persist in db here

        self.store[tracker.sender_id] = serialised

    def retrieve(self, sender_id: Text) -> Optional[DialogueStateTracker]:
        if sender_id in self.store:
            logger.debug("Recreating tracker for id '{}'".format(sender_id))
            return self.deserialise_tracker(sender_id, self.store[sender_id])
        else:
            logger.debug("Creating a new tracker for id '{}'.".format(sender_id))
            return None

    def keys(self) -> Iterable[Text]:
        return self.store.keys()

The error occur here:

@staticmethod
    def load_tracker_from_module_string(domain, store):
        custom_tracker = None
        try:
            custom_tracker = class_from_module_path(store.type)
        except (AttributeError, ImportError):
            logger.warning(
                "Store type '{}' not found. "
                "Using InMemoryTrackerStore instead".format(store.type)
            )

        if custom_tracker:
            return custom_tracker(domain=domain, url=store.url, **store.kwargs)
        else:
            return InMemoryTrackerStore(domain)

He cant to instance the custom, because not has url param.

Solved!

def __init__(
            self,
            domain: Domain,
            url: Optional[str] = None,
            event_broker: Optional[EventChannel] = None
    ) -> None:

Add param optional url.

1 Like

Hi @DiegoProtec. Great to hear you found a solution and thank you so much for sharing it with the community! :heart:

1 Like