Passing metadata to custom components NLU

Hey, Is it possible to pass metadata to a custom component real-time? like in the

def process(self, message: Message, **kwargs: Any) -> None:

I notice that there is a kwargs but how do it send it through this endpoint? https://rasa.com/docs/rasa/pages/http-api#operation/parseModelMessage

what implementation could capture it?

Thanks

1 Like

Hi @souvikg10

I have a suggestion, based on my assumption that you want to add message metadata, however not sure if it captures your goal, so I recommend testing the below:

You could use this endpoint instead to send a UserUttered event (value for the event name in the request body should be user) to the tracker.

In the request.body you could add a parse_data key with a dictionary as a value. The parse_data value dict can contain a key metadata that should be a dictionary too. Alternatively you can also pass the metadata dictionary directly in the request.body. The schema for this event is available here (we have an issue to update the docs too :smiley: )

Let us know how you get on :slight_smile:

Hi Anca,

Will the metadata be passed onto the NLU component as well?

i will try this

@souvikg10 What’s your use case / how do you want to use this? I don’t think this is currently possible.

Basically my custom nlu component needs some metadata that I use to connect to a backend and fetch data which I use to do entity extraction.

At this point, I pass it on while training my model and save it as a text file in the model tar. Kind of makes the value static during runtime which is fine for now. But if I need to dynamically pass it on to my nlu component then at this point I can’t.

Which makes me think about the difference between slot extraction v/s entity extraction. The way anca described above would mean I could do it via custom action and fill in a slot rather than using a custom entity extraction nlu component but since I use the tasks from the config like the tokeniser, I thought it was best to keep it in my nlu pipeline.

Mhm, for prediction time you could use metadata on UserMessages. I think the bigger problem is doing this during training :thinking:

will that metadata be passed onto the NLU components? I understand that it is for passing to the custom action only.

Regarding training, well i train rasa models in a pythonic way but i pass metadata with additional arguments of rasa nlu’s train_nlu API, so i suppose it is possible to pass metadata for training even from the cli. obviously needs a PR

trained_model_path = train_nlu(
                config=config,
                nlu_data=nlu_data,
                output=output_path,
                fixed_model_name="model",
                additional_arguments=meta,
            )