Here's an example of using an Automated Action to prevent duplicates (Odoo already blocks duplicate barcodes so this is the Internal Reference). If I understand your requirement you could change the Python code to ensure that there are no duplicates within the product identity group.
https://odootricks.tips/automated-action-to-prevent-duplicates/

Model: Product Template
Action To Do: Execute Python Code
Trigger Condition: On Creation & Update
Before Update Domain: Internal Reference is set
Apply on: Match all records
Python Code
if record.default_code:
existing_product = env['product.template'].search([('id','!=',record.id),('default_code','=',record.default_code)])
if existing_product:
raise Warning("You can't have the same Internal Reference Number in Odoo twice!")