Skip to content

search_faces async

search_faces(
    collection_id: CollectionId,
    face_id: FaceId,
    *,
    config_overrides: Optional[AsyncRekognitionClientConfig] = None,
    max_faces: Optional[MaxFaces] = None,
    face_match_threshold: Optional[Percent] = None,
) -> SearchFacesResponse

For a given input face ID, searches for matching faces in the collection the face belongs to. You get a face ID when you add a face to the collection using the IndexFaces operation. The operation compares the features of the input face with faces in the specified collection.

You can also search faces without indexing faces by using the SearchFacesByImage operation.

The operation response returns an array of faces that match, ordered by similarity score with the highest similarity first. More specifically, it is an array of metadata for each face match that is found. Along with the metadata, the response also includes a confidence value for each face match, indicating the confidence that the specific face matches the input face.

For an example, see Searching for a face using its face ID in the Amazon Rekognition Developer Guide.

This operation requires permissions to perform the rekognition:SearchFaces action.

Parameters:

  • collection_id (CollectionId) –

    ID of the collection the face belongs to.

  • face_id (FaceId) –

    ID of a face to find matches for in the collection.

  • max_faces (Optional[MaxFaces], default: None ) –

    Maximum number of faces to return. The operation returns the maximum number of faces with the highest confidence in the match.

  • face_match_threshold (Optional[Percent], default: None ) –

    Optional value specifying the minimum confidence in the face match to return. For example, don't return any matches where confidence in matches is less than 70%. The default value is 80%.

Raises:

Examples:

To delete a face This operation searches for matching faces in the collection the supplied face belongs to.

>>> await client.search_faces(collection_id='myphotos', face_id='70008e50-75e4-55d0-8e80-363fb73b3a14', max_faces=10, face_match_threshold=90)
Source code in docs_src/capo_rekognition/_services/async_rekognition.py
async def search_faces(
    self,
    collection_id: "capo_rekognition.types.collection_id.CollectionId",
    face_id: "capo_rekognition.types.face_id.FaceId",
    *,
    config_overrides: Optional[AsyncRekognitionClientConfig] = None,
    max_faces: Optional["capo_rekognition.types.max_faces.MaxFaces"] = None,
    face_match_threshold: Optional["capo_rekognition.types.percent.Percent"] = None,
) -> "capo_rekognition.types.search_faces_response.SearchFacesResponse":
    """<p>For a given input face ID, searches for matching faces in the collection the face belongs to. You get a face ID when you add a face to the collection using the <a>IndexFaces</a> operation. The operation compares the features of the input face with faces in the specified collection. </p> <note> <p>You can also search faces without indexing faces by using the <code>SearchFacesByImage</code> operation.</p> </note> <p> The operation response returns an array of faces that match, ordered by similarity score with the highest similarity first. More specifically, it is an array of metadata for each face match that is found. Along with the metadata, the response also includes a <code>confidence</code> value for each face match, indicating the confidence that the specific face matches the input face. </p> <p>For an example, see Searching for a face using its face ID in the Amazon Rekognition Developer Guide.</p> <p>This operation requires permissions to perform the <code>rekognition:SearchFaces</code> action.</p>

    Args:
        collection_id: <p>ID of the collection the face belongs to.</p>
        face_id: <p>ID of a face to find matches for in the collection.</p>
        max_faces: <p>Maximum number of faces to return. The operation returns the maximum number of faces with the highest confidence in the match.</p>
        face_match_threshold: <p>Optional value specifying the minimum confidence in the face match to return. For example, don't return any matches where confidence in matches is less than 70%. The default value is 80%. </p>

    Raises:
        capo_rekognition.errors.access_denied_exception.AccessDeniedException: <p>You are not authorized to perform the action.</p>
        capo_rekognition.errors.internal_server_error.InternalServerError: <p>Amazon Rekognition experienced a service issue. Try your call again.</p>
        capo_rekognition.errors.invalid_parameter_exception.InvalidParameterException: <p>Input parameter violated a constraint. Validate your parameter before calling the API operation again.</p>
        capo_rekognition.errors.provisioned_throughput_exceeded_exception.ProvisionedThroughputExceededException: <p>The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Rekognition.</p>
        capo_rekognition.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource specified in the request cannot be found.</p>
        capo_rekognition.errors.throttling_exception.ThrottlingException: <p>Amazon Rekognition is temporarily unable to process the request. Try your call again.</p>
        capo_rekognition.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a face
        This operation searches for matching faces in the collection the supplied face belongs to.

        >>> await client.search_faces(collection_id='myphotos', face_id='70008e50-75e4-55d0-8e80-363fb73b3a14', max_faces=10, face_match_threshold=90)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_rekognition.types.search_faces_request.SearchFacesRequest]",
    ) -> AsyncOperationResponse[
        "capo_rekognition.types.search_faces_response.SearchFacesResponse"
    ]:
        import capo_rekognition._operations.rekognition_service.search_faces

        (
            output,
            http_response,
        ) = await capo_rekognition._operations.rekognition_service.search_faces.async_search_faces(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SearchFaces")
    )
    input_: capo_rekognition.types.search_faces_request.SearchFacesRequest = {
        "collection_id": collection_id,
        "face_id": face_id,
    }
    if max_faces is not None:
        input_["max_faces"] = max_faces
    if face_match_threshold is not None:
        input_["face_match_threshold"] = face_match_threshold

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output