There are some hadiths explained the sources of Imams knowledge in Basair al Darajat book as follow:
مبلغ علمنا على ثلاثة وجوه: ماض و غابر و حادث. فاما الماض فمفسر و اما
الغابر فمزبور و اما الحادث فقذف فى القلوب و نقر فى الاسماع و هو افضل
علمنا و لا نبى بعد نبينا
our knowlegde sources are three faces: first,what occurred.second,what
is ocurring and third,what will occur. first, [what ocurred] are
teachings of the prophet which give us down from [Ali Ibn
Abi-talab].second [what is ocurring ]which are wriiten in[ fatima
book(sahifeh)]. third [what will occur] throwing in our heart [elham
]or whispering in our ears and this is our best knowlegde and there
is no messenger after our holy prophet mohammad peace be upon him.
First: the prophet taught Imam Ali his knowledge and called him as the Gate of his knowledge as [following hadiths].this knowledge transferred to next Imams :
علمني رسول الله الف باب من العلم ، يفتح من كل باب الف باب
Imam Ali (s) said: “The Prophet, in his deathbed, whispered to me and
taught me one thousand chapters of knowledge; each one of them
contained one thousand chapters.”
قال رسول الله صلّى الله عليه وآله وسلّم: «أنا مدينة العلم وعلي بابها
فمن أراد العلم فليأت الباب
"I am the city of knowledge and Ali is its gate..."
This knowledge transferred to next Imams also the Quran which collected by Imam Ali.
Second, interpretates to moshaf of Fatima (which sent down by Gabriel about some matters and facts written by Imam Ali ) or community or Jafar books.
Third, imams know about everything when ask him by throwing or whispering at the end stated that these [throwing or whispering] are not only for messengers.