Esempio n. 1
0
 def test_search_index_for_matches(self):
     entry_hash = test_entries[1][0]
     result = self.index.query(entry_hash)
     self.assertEqualPDQIndexMatchResults(
         result,
         [IndexMatch(0, test_entries[1][1]), IndexMatch(16, test_entries[0][1])],
     )
 def _inactive_bank_match(self):
     return IndexMatch(
         0,
         [
             BankedSignalIndexMetadata(
                 "signal", "signal_value", self.inactive_bank_member.bank_member_id
             )
         ],
     )
Esempio n. 3
0
    def test_supports_pickling(self):
        pickled_data = pickle.dumps(self.index)
        assert pickled_data != None, "index does not support pickling to a data stream"

        reconstructed_index = pickle.loads(pickled_data)
        assert (
            reconstructed_index != None
        ), "index does not support unpickling from data stream"
        assert (
            reconstructed_index.index.faiss_index != self.index.index.faiss_index
        ), "unpickling should create it's own faiss index in memory"

        query = test_entries[0][0]
        result = reconstructed_index.query(query)
        self.assertEqualPDQIndexMatchResults(
            result,
            [IndexMatch(0, test_entries[1][1]), IndexMatch(16, test_entries[0][1])],
        )
 def _active_pg_match(self):
     return IndexMatch(
         0,
         [
             ThreatExchangeIndicatorIndexMetadata(
                 "indicator_id",
                 "hash_value",
                 self.active_pg.privacy_group_id,
             )
         ],
     )
Esempio n. 5
0
    def query(self, hash: str) -> t.List[IndexMatch[IndexT]]:
        """
        Look up entries against the index, up to the max supported distance.
        """

        # query takes a signal hash but index supports batch queries hence [hash]
        results = self.index.search_with_distance_in_result(
            [hash], self.get_match_threshold())

        matches = []
        for id, _, distance in results[hash]:
            matches.append(IndexMatch(distance, self.local_id_to_entry[id][1]))
        return matches
Esempio n. 6
0
    def query(self, hash: str) -> t.List[IndexMatch[T]]:
        """
        Look up entries against the index, up to the max supported distance.
        """

        # query takes a signal hash but index supports banch quries hence [hash]
        results = self.index.search([hash],
                                    self.PDQ_CONFIDENT_MATCH_THRESHOLD,
                                    return_as_ids=True)
        matches = []
        for result_ids in results:
            for id in result_ids:
                # distance = -1 (index does not currently support distance)
                matches.append(IndexMatch(-1, self.local_id_to_entry[id][1]))
        return matches