Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

what is the distinction between DetectIntent and MatchIntent

Hello, 

I am working with the Dialogflow CX Python API and specifically the SessionsClient. I am working with both the DetectIntent and MatchIntent APIs to better understand how they work.

When I construct the DetectIntentRequest and MatchIntentRequest objects respectively, I am using the exact same values for the session, query_input, and query_params.

However, when I then execute those requests, I do get back results from the DetectIntent API that are what I expect, but the MatchIntent API always return no matches (see below example). The one somewhat weird thing is that the current_page value returned is not the current_page I sent in the request. The DetectIntent API does return the same current_page that I sent in the request FWIW. 

The API documentation is not overly helpful for me to troubleshoot this so I am hoping someone here understands better than me if I should be expecting the same intents to be returned from these 2 APIs or if there is a fundamental difference between them that would explain why I get results with one but not the other.

 

matches {
  match_type: NO_MATCH
  confidence: 0.3
}
current_page {
  name: "projects/blahblah/locations/us-central1/agents/dfe4ebab-b825-47ad-8630-302e85c83cfd/flows/00000000-0000-0000-0000-000000000000/pages/START_PAGE"
  display_name: "Start Page"
}

 

 

0 9 634
9 REPLIES 9

Hi,

The match intent is kind of a test, it tests what a detectIntent should detect (intents and entities) but it does not change anything in the user's sessions. Here you have the docs: https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.sessions/mat...

Best

Thanks for the response and I get that part of it, but I guess I am still then back to my original question which is why then does MatchIntent not return the same intents as DetectIntent given that all aspects about the 2 requests are the same?

can you try to use a random session id? or create a new session id and test with that?

that is precisely what I am doing, here is the full code below. Please let me know if you see anything I might be doing wrong.

import uuid

from google.cloud.dialogflowcx_v3.services.sessions import SessionsClient
from google.cloud.dialogflowcx_v3.types import session

# static variables
location = "us-central1"
agent_id = "dfe4ebab-b825-47ad-8630-302e85c83cfd"
language_code = "en-us"

def detect_intent(customer_input, client_type, source, project):
    client_options = None
    if location != "global":
        api_endpoint = f"{location}-dialogflow.googleapis.com:443"
        client_options = {"api_endpoint": api_endpoint}
    session_client = SessionsClient(client_options=client_options)
    session_id = str(uuid.uuid4())
    session_path = session_client.session_path(
        project=project,
        location=location,
        agent=agent_id,
        session=session_id,
    )

    text_input = session.TextInput(text=customer_input)
    query_input = session.QueryInput(text=text_input, language_code=language_code)
    params = {
        "client_type": client_type,
        "source": source,
    }
    query_params = session.QueryParameters(
        parameters=params,
        current_page=f"projects/{project}/locations/{location}/agents/dfe4ebab-b825-47ad-8630-302e85c83cfd/flows/00000000-0000-0000-0000-000000000000/pages/37ca186c-3aeb-4842-a7dd-65667701e50e",
    )
    request = session.DetectIntentRequest(
        session=session_path,
        query_input=query_input,
        query_params=query_params,
    )

    response = session_client.detect_intent(request=request)
    print(f"Response: {response}")
    return response


def match_intent(customer_input, client_type, source, project):
    client_options = None
    if location != "global":
        api_endpoint = f"{location}-dialogflow.googleapis.com:443"
        client_options = {"api_endpoint": api_endpoint}
    session_client = SessionsClient(client_options=client_options)
    session_id = str(uuid.uuid4())
    session_path = session_client.session_path(
        project=project,
        location=location,
        agent=agent_id,
        session=session_id,
    )

    text_input = session.TextInput(text=customer_input)
    query_input = session.QueryInput(text=text_input, language_code=language_code)
    params = {
        "client_type": client_type,
        "source": source,
    }
    query_params = session.QueryParameters(
        parameters=params,
        current_page=f"projects/{project}/locations/{location}/agents/dfe4ebab-b825-47ad-8630-302e85c83cfd/flows/00000000-0000-0000-0000-000000000000/pages/37ca186c-3aeb-4842-a7dd-65667701e50e",
    )
    request = session.MatchIntentRequest(
        session=session_path,
        query_input=query_input,
        query_params=query_params,
    )

    response = session_client.match_intent(request=request)
    print(f"Response: {response}")
    return response

#detect_intent("I need to reschedule my appointment.", "Web", "Chatbot", "myproject-12345")
match_intent("I need to reschedule my appointment.", "Web", "Chatbot", "myproject-12345")

can try to remove the current_page?

same result (see below). The interesting thing with the MatchIntent API is that it seems to ignore the passed in current page altogether and it just always returns the default flow's start page, regardless if you send in a current page or not.

matches {
  match_type: NO_MATCH
  confidence: 0.3
}
current_page {
  name: "projects/myproject-12345/locations/us-central1/agents/dfe4ebab-b825-47ad-8630-302e85c83cfd/flows/00000000-0000-0000-0000-000000000000/pages/START_PAGE"
  display_name: "Start Page"
}

I have no clue... that is weird

@my3sons  what is the sdk you are using? Can you share the docs?

Hello @Mizar ,

I am using the Python (google-cloud-dialogflow-cx) SDK and specifically the SessionsClient (from google.cloud.dialogflowcx_v3.services.sessions). The docs related to this SDK can be found here: https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.sessions/mat...