A search for “driver” could concern a taxi or software. Intent classification assigns an incoming query to one or more known categories so the search engine can interpret it in context. Categories might come from a field on indexed documents, such as travel or devops. section 6.1
One implementation uses a semantic knowledge graph (SKG). Start a traversal at the query, then find the categories most related to it. The traversal performs a k-nearest-neighbor search, returning categories with relatedness scores rather than requiring an exact category-word match. In the Python example, body supplies query terms, category supplies classifications, classification_limit caps the returned categories, and min_occurrences filters infrequent matches. section 6.1
Listing 6.1 Query classification using the SKG
def print_query_classification(query, classification_field="category",
classification_limit=5, keywords_field="body", min_occurrences=5):
nodes_to_traverse = [{"field": keywords_field, #1
"values": [query]}, #1
{"field": classification_field, #2
"min_occurrences": min_occurrences, #3
"limit": classification_limit}] #4
traversal = skg.traverse(*nodes_to_traverse) #5
print_classifications(query, traversal) #6
skg = get_skg(get_engine().get_collection("stackexchange"))
print_query_classification("docker", classification_limit=3)
print_query_classification("airplane", classification_limit=1)
print_query_classification("airplane AND crash", classification_limit=2)
print_query_classification("vitamins", classification_limit=2)
print_query_classification("alien", classification_limit=1)
print_query_classification("passport", classification_limit=1)
print_query_classification("driver", classification_limit=2)
print_query_classification("driver AND taxi", classification_limit=2)
print_query_classification("driver AND install", classification_limit=2)
The Python listing builds the query-to-category traversal and runs it against an indexed collection. section 6.1
Context changes the classification
“Driver” favors travel but also returns devops. Adding “taxi” favors travel; adding “install” favors devops. Likewise, “airplane” favors travel, while “airplane AND crash” favors scifi in this collection. The full query and the available documents both affect the result. section 6.1
Classification can be the first step in query-sense disambiguation. Traverse from the query to a category, then to related terms within that category. For “driver,” the travel context yields terms such as taxi and car, while the devops context yields terms such as docker and compose. section 6.2
Document-based classifications depend on how well indexed content represents what users mean. If search behavior points toward clothing but the inventory mostly describes films, a query such as “shorts” may be interpreted in the wrong context. User-generated signals can provide additional context; classification then becomes one component of a broader query-interpretation and rewriting pipeline. section 6.0 section 6.6



