Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add similarity to raw_lookup endpoint #1639

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this response shape, but just noting that it is technically a breaking change for clients of this API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, probably the right thing to do is version the api change

storage = get_storage()
signal_type = _validate_and_transform_signal_type(signal_type_name, storage)

Expand All @@ -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(
Expand Down