How to perform keyword search with Azure AI search

JDR 90 Reputation points
2024-02-14T01:32:00.9833333+00:00

Hi, I am able to successfully run vector and hybrid search on Azure AI Search following this example:
https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/search/azure-search-documents/samples/sample_vector_search.py I would like to perform pure keyword search. For that I have added the following function to the code above:

def keyword_search():
    # [START single_vector_search]
    query = "n/a"

    search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))

    results = search_client.search(
        search_text=query,
        vector_queries=None,
        select=["hotelId", "hotelName"],
    )

    for result in results:
        print(result)
    # [END single_vector_search]

The code runs and returns the following result:
{'hotelId': '2', 'hotelName': 'Roach Motel', '@search.score': 1.242726, '@search.reranker_score': None, '@search.highlights': None, '@search.captions': None}

But the query 'n/a' doesn't appear in the data and shouldn't match any result. The results variable should be empty.

In other words, how can I ensure that search() does match at least one keyword when it search_text is not None and vector_queries is None.

Thanks for your help.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,339 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JDR 90 Reputation points
    2024-02-14T07:30:10.58+00:00

    It seems that "n/a" is tokenized internally into "n a" and therefore matching these letters


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.