A facsimile of Data found on Kolarus III, B-4 was a key element of Shinzon's plot to lure Captain Picard and the Enterprise-E into his vengeful trap. Worf detected B-4's positronic signal from the planet, a planet conveniently near the Romulan Neutral Zone, and joined Picard and Data abaord the Argo to investigate.
When they arrived, they found B-4 scattered across the planet. B-4's head introduced himself to Data just before the Kolarans attacked. Data, Picard, Worf and B-4 managed to escape and return to the Enterprise, where Geordi La Forge re-assembled B-4. Geordi also concluded that the android has similar internal mechanics as Data, but is not as developed. La Forge deduced that B-4 is a prototype. Hoping to aid B-4's development, Data downloads his memory engrams into B-4's matrix. B-4 doesn't seem to be assimilating all of this new information, but La Forge suggests that Data merely give it some time.
When it is discovered that B-4 had been accessing the ship's computer and storing information in his extra memory port, Picard and Data deduce that Shinzon was using B-4 to gain access to Starfleet information that the Reman would use to destroy the Federation.
Impersonating B-4, Data beamed over to Shinzon's ship, the Scimitar, while Shinzon held Picard captive. Data later escapes with Captain Picard in time to stop the evil Shinzon from using his deadly thalaron weapon.
Following Data's death as a result of stopping the deployment of Shinzon's weapon, Picard shares with B-4 what made Data so unique. And B-4, still processing Data's engrams, proceeds to hum a tune that his "brother" once sang, which gives Picard a sense of hope in the wake of Data's death.