Every time I got a stack's hp low enough, they would cease to approach and instead pull distance. Against a ranged unit. All I had to do was keep focusing groups until they stopped advancing. No one even attacked me in melee. And no, there were no healers on the field, or any way for the enemy to recuperate. The *only* way for them to win would have been to mob me - which is what they should have done, but didn't.
The weird thing is, ok, I understand the idea behind wounded units retreating - if you pull them back and keep them out of the battle and then proceed to win, they will survive and be able to heal instead of dying and being lost forever. The problem with the AI doing this, however, is two-fold:
1) The AI retreats with its very last unit if it is wounded. This makes no sense. Running away in the battlefield only delays the inevitable, they may as well use their last attack to do a last desperate bit of damage.
2) As the OP pointed out, the AI retreats from battles where they have melee units pitted against a heavy ranged unit composition. In this situation, no matter the health of your units, you should push on because that way they have to spend a turn finishing off one of your units, or damaging another one, leaving you free to attack and perhaps win the day.
Further, the wounded units the AI have should really re-enter the fray once it becomes clear the battle is hopeless, because they may as well contribute something while there are still a few other units struggling for survival, rather than being useless cowards. This last one might be a bit much to ask for, though.