Janamejaya became the emperor of Hastinapur upon the death of his father Parikshitaand, the great grandson of Arjuna .It is said that Parikshita was the only descendant of the house of Pandu who had died of snakebite because the sage cursed him.
For this Janamejaya had a deep grudge against the snakes. He decided to conduct a sacrifice to wipe out all the serpents by performing the great Sarpahoma -a sacrifice that would kill all the serpents of earth.As he was going to begin the sacrifice Rishi Vaishampayana ,the disciple and son of Vyasa arrived with a host of rishis .The sages instructed Janamejaya that it was not right to kill the Nagas and to take revenge. But Janamejaya decided to continue with the sacrifice. It was then that the entire Mahabharata was recited by rishi Vaisampayana. The Hindus remember the day of the homa as the Nag Panchami ritual.