Ideally, you should contact an attorney as soon after your accident as possible. That does not mean that you need to contact an attorney from the ambulance, but you will certainly want to contact one before you finish your recovery. The sooner you contact an attorney, the sooner the attorney could start working to collect evidence on your behalf.
Often, that evidence can become more difficult to collect as time passes. Memories can fade, making it more difficult for witnesses to accurately report what happened. The liable party may even attempt to cover up some of the evidence in an effort to shift liability to you. By contacting an attorney soon after your injuries, you increase the odds that your attorney could collect the full evidence you need to prove liability in your accident.