Sorei (or Mioyanomitama) is an ancestral soul. This term is used especially in the religious service of Shinto. In many cases, the word 'sorei' refers to a soul or collective of souls whose bodies died quite long time ago and individualities in life were lost. It is considered that this notion has been around since the Jomon period. During the mythical age of the Kojiki (Records of Ancient Matters) and the Nihonshoki (Chronicles of Japan), it is written of Susano's grief of loving her mother as a soul.
According to Kunio YANAGIDA, in Japanese folk beliefs, the spirit whose body died within a certain number of years needing services is called 'shiryo', and is distinguished from sorei. Shiryo gradually loses its individuality by services. It completely loses its individuality and becomes a part of sorei by 'Matsuriage' (enshrinement) which is held after a certain number of years from the body's death (50 years, 33 years, or 30 years, etc, depending on the region). While people after death transmigrate in Indian Buddhism, go to Hell or Buddhist paradise in Japanese Buddhism, or the faraway world for the departed in Christianity, in the Shinto view of life and death, they stay close to the world of living things (the next world in mountains or on the sea), and come back to their descendants during the Bon festival (a Festival of the Dead or Buddhist All Soul's Day) and New Year.
The shoshi (small shrine) built in graveyards or related places to enshrine ancestral souls is called reisha shrine, and the reisha shrine enshrining all the ancestors is called soreisha shrine. The worship in soreisha shrine is only for descendants, and tend to exclude other people. In old times, as a place to enshrine the sorei of Imperial Family, the Ise-jingu Shrine had a rule called Shihei kindan (nobody but the Emperor could go and pray there), which was an example of such exclusiveness.
There is also an idea that a sorei will become a deity (Shinto). Such sorei are enshrined as a soshin (an ancestor honored as god) or ujigami (a guardian god or spirit of a particular place in the Shinto religion) in a clan or rural community. In Okinawa Region it was believed that a soul would become a deity in seven generations.
Although this ancestor worship was general in uncivilized societies and ancient societies, it had declined because of world religion (Buddhism, Christianity) believing blood relationship only exists in the living world. However there is an example of syncretization with ancestor worship which was indigenized in Japanese Buddhism.