The contract sets the percentage, the cap and when it's released, commonly part at practical completion and the rest after the defects liability period.
What is retention?
Retention is a percentage of each progress payment held back as security until the work is complete and defects are fixed.