Some items that have been crafted by the finest artisans have small sockets that can hold various gemstones. Once placed in the sockets of these items, these stones imbue them with additional mystical properties.
Items that have sockets are easily identified when you place your mouse cursor over them in your inventory. The total number of sockets varies based on random chance and the size of the weapon. Finding a weapon such as this Longstaff is quite fortuitous, indeed!
A gem that can be placed into a socketed item is clearly identified as such by placing your mouse cursor over them in your inventory.
Just pick up the gem by left-clicking and drop it into the item you want to imbue. The socketed item now has the additional properties granted by the gem!
Gems placed into socketed items are permanent, so choose wisely!