The level of my musical education leaves much to be desired, so I apologize in advance for maybe amateurish question. Several times I've encountered a situation when a composer repeats some piece in a song, keeping the overall shape of the melody but applying a small variation to it. It looks like an improvisation where some notes have remained unchanged, while the others have been shifted randomly or according to some rule unfamiliar to me.
Here's an example of what I mean. It is a music composed by Laurent Boutonnat to the Gourmandises (2000) album by Alizée, reissued as an instrumental album in 2019:
In this example, please pay attention to the following fragments:
2:13 - 2:29 (main phrase),
2:31 - 2:47 (the variation).
Is there a term for such a technique (I think improvisation is too broad for this)? Are there common rules for this? I've found a similar question here and also found the 'Variation' article on Wikipedia, but they are too broad and I cannot figure out which parts of them apply to the above example and whether they are relevant at all.