skip to Main Content

I am using Azure cognitive search for a RAG based solution. On giving the search keywords like " vendors with apple, oranges and lemons". It is returning vendors who supply either of the three and not the vendors who supplies all three.

Basically how to change the search logic from OR to AND.

Current result : Vendors who supply Apples OR Oranges OR Lemons.
I need : Vendors who supply Apples AND Oranges AND Lemons.

I am skimming through the documentation for changing this approach. changed the search_mode to all
"searchMode=all"

Also tried search=Apple+oranges

I am skimming through the documentation for changing this approach. changed the search_mode to all
"searchMode=all"

Also tried search=Apple+oranges

2

Answers


  1. The searchMode=all setting should resolve this as it changes the default behavior from an ‘OR’ to an ‘AND’ logic between search terms.

    If you’re looking for exact phrases or specific combinations of words, you can also use quotation marks around the phrases. For example, search="apple" AND "oranges" AND "lemons”.

    Login or Signup to reply.
  2. I have created an index and used below sample data:

    documents = {
        "value": [
            {"@search.action": "upload", "VendorId": "1", "VendorName": "Vendor 1", "Fruits": ["Apple", "Orange", "Lemon"]},
            {"@search.action": "upload", "VendorId": "2", "VendorName": "Vendor 2", "Fruits": ["Apple", "Banana"]},
            {"@search.action": "upload", "VendorId": "3", "VendorName": "Vendor 3", "Fruits": ["Orange", "Lemon"]},
        ]
    }
    

    For your specific case, you can use the AND operator to ensure that all your conditions must be met and remember to set searchMode=all if you’re using the simple query syntax and want to optimize searches for precision instead of recall.

    With Below search query I was able to get required results:

    query = {
        "search": "Apple AND Banana",
        "searchMode": "all",
        "count": True,
        "top": 5,
        "queryType":"full"
    }
    

    Output:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search