 Initially Northern Wei was a vassal of Later Yan, but by 395 had rebelled and defeated the Yan at the Battle of Canhebei.By 398 the Wei had conquered most of Later Yan territory north of the Yellow River.In 399, Tuoba Gui declared himself Emperor Daowu, and that title was used by Northern Wei's rulers for the rest of the empire's history.