From 43a705b9396c30414c8aceb68f5e2e76abc32467 Mon Sep 17 00:00:00 2001 From: Patrick Renner Date: Wed, 2 Oct 2024 10:23:33 -0500 Subject: [PATCH] add similarity to raw_lookup endpoint --- .../src/OpenMediaMatch/blueprints/matching.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py b/hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py index a68c82044..d2b4c384e 100644 --- a/hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py +++ b/hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py @@ -95,14 +95,14 @@ def raw_lookup(): * Signal value (the hash) * Optional list of banks to restrict search to Output: - * List of matching content items + * List of matching with content_id and distance values """ signal = require_request_param("signal") signal_type_name = require_request_param("signal_type") return lookup_signal(signal, signal_type_name) -def lookup_signal(signal: str, signal_type_name: str) -> dict[str, list[int]]: +def lookup_signal(signal: str, signal_type_name: str) -> dict[str, dict[str, str]]: storage = get_storage() signal_type = _validate_and_transform_signal_type(signal_type_name, storage) @@ -118,7 +118,15 @@ def lookup_signal(signal: str, signal_type_name: str) -> dict[str, list[int]]: current_app.logger.debug("[lookup_signal] querying index") results = index.query(signal) current_app.logger.debug("[lookup_signal] query complete") - return {"matches": [m.metadata for m in results]} + return { + "matches": [ + { + "content_id": m.metadata, + "distance": m.similarity_info.pretty_str(), + } + for m in results + ] + } def _validate_and_transform_signal_type(