Either way, you need to define what it means for a chemical to be 'in' your database. Do you care about the 3D coordinates (given that you have XYZ) or just the atom types and connectivity?
Short answer. use a cheminformatics library that provides structure matching or can encode your molecules (query and targets) as canonical SMILES, InChI, etc.
See Is there a way to use free software to convert SMILES strings to structures?
Long answer. Use a series of filters (or questions):
- Are there any molecues in my database with the same number of atoms?
- Do any of these have the same atom types?
- Finally, are these atoms connected to the same neighbours?
The third one is a little trickier, but is still a quick way to determine isomorphism. If you need true structure matching, see the short answer! If you need 3D matching, then again it's going to be much quicker to use a library method.