I've seen it repeatedly said that if you don't maintain rough military parity with other empires, the AI *will* take advantage and/or punish you for it. It also seems to happen somewhat often where the AI likes to ally with at least one other empire before going to war with someone -- which makes sense, when you think about it.
(So perhaps the lesson is find a "war buddy" of your own? Hmm.)