add function to get training labels. Refactor search db