The Jurchens were a Tungusic-speaking group of semi-agrarian tribes inhabiting areas of northeast Asia that are now part of Northeast China. Many of the Jurchen tribes were vassals of the Liao dynasty , an empire ruled by the nomadic Khitans that included most of modern Mongolia, a portion of North China, Northeast China, northern Korea, and parts of the Russian Far East. To the south of the Liao lay the Han Chinese Song Empire . The Song and Liao were at peace, but since a military defeat to the Liao in 1005, the Song paid its northern neighbor an annual indemnity of 200,000 bolts of silk and 100,000 ounces of silver. In 1114, the chieftain Wanyan Aguda  united the disparate Jurchen tribes and led a revolt against the Liao. In 1115 he named himself emperor of the Jin "golden" dynasty . Informed by a Liao defector of the success of the Jurchen uprising, the Song emperor Huizong  and his highest military commander the eunuch Tong Guan saw the Liao weakness as an opportunity to recover the Sixteen Prefectures, a line of fortified cities and passes that the Liao had annexed from the Shatuo Turk Later Jin in 938, and that the Song had repeatedly but unsuccessfully tried to reconquer. The Song thus sought an alliance with the Jin against their common enemy the Liao.
Question: Which happened first, a military defeat to the Liao or the chieftain Wanyan Aguda united the disparate Jurchen tribes
Answer: a military defeat