Enforcing the law is their duty, protecting you is not. You're ultimately responsible for your own protection.
If the cops have a choice of stopping 2 crimes or the crime happening to you, they're going to choose the 2 crimes. Presumably you and definitely I would choose to prevent the crimes happening to ourselves. Thus, self defense.
No, that's not their duty, either.
They are a paramilitary force lacking the civilian supreme command that, in the US, the actual military has, empowered by but not obligated to act to enforce the law, an independent and centralized power center.