Snabbstart: Vektorsökning med hjälp av REST

Lär dig hur du använder REST API:er för sökning för att skapa, läsa in och fråga vektorer i Azure AI Search.

I Azure AI Search har ett vektorlager ett indexschema som definierar vektor- och icke-vektorfält, en vektorkonfiguration för algoritmer som skapar inbäddningsutrymmet och inställningar för vektorfältdefinitioner som används i frågebegäranden. Api: et Skapa index skapar vektorarkivet.

Om du inte har någon Azure-prenumeration skapar du ett kostnadsfritt konto innan du börjar.

Kommentar

Den stabila REST API-versionen 2023-11-01 är beroende av externa lösningar för datasegmentering och inbäddning. Om du vill utvärdera de inbyggda funktionerna för datasegmentering och vektorisering (offentlig förhandsversion) kan du prova guiden Importera och vektorisera data för en genomgång från slutpunkt till slutpunkt.

Förutsättningar

  • Visual Studio Code med en REST-klient. Om du behöver hjälp med att komma igång kan du läsa Snabbstart: Textsökning med HJÄLP av REST.

  • Azure AI Search, i valfri region och på valfri nivå. Du kan använda den kostnadsfria nivån för den här snabbstarten, men Basic eller senare rekommenderas för större datafiler. Skapa eller hitta en befintlig Azure AI Search-resurs under din aktuella prenumeration.

    De flesta befintliga tjänster stöder vektorsökning. För en liten delmängd av tjänster som skapades före januari 2019 misslyckas ett index som innehåller vektorfält vid skapandet. I det här fallet måste en ny tjänst skapas.

  • Om du vill köra frågeexemplet som anropar semantisk omrankning måste söktjänsten vara basic-nivån eller högre, med semantisk rangordning aktiverad.

  • Du kan också använda en Azure OpenAI-resurs med en distribution av text-embedding-ada-002. Källfilen .rest innehåller ett valfritt steg för att generera nya textinbäddningar, men vi tillhandahåller förgenererade inbäddningar så att du kan utelämna det här beroendet.

Ladda ned filer

Ladda ned ett REST-exempel från GitHub för att skicka begäranden i den här snabbstarten. Mer information finns i Ladda ned filer från GitHub.

Du kan också starta en ny fil i det lokala systemet och skapa begäranden manuellt med hjälp av anvisningarna i den här artikeln.

Kopiera en söktjänstnyckel och URL

REST-anrop kräver slutpunkten för söktjänsten och en API-nyckel för varje begäran. Du kan hämta dessa värden från Azure-portalen.

  1. Logga in på Azure-portalen. Gå till sidan Översikt och kopiera URL:en. Här följer ett exempel på hur en slutpunkt kan se ut: https://mydemo.search.windows.net.

  2. Välj Inställningar> Nycklar och kopiera en administratörsnyckel. Administratörsnycklar används för att lägga till, ändra och ta bort objekt. Det finns två utbytbara administratörsnycklar. Kopiera någon av dem.

    Skärmbild som visar URL:en och API-nycklarna i Azure-portalen.

Skapa ett vektorindex

Skapa index (REST) skapar ett vektorindex och konfigurerar de fysiska datastrukturerna i söktjänsten.

Indexschemat är organiserat kring hotellinnehåll. Exempeldata består av vektor- och icke-bevektornamn och beskrivningar av sju fiktiva hotell. Det här schemat innehåller konfigurationer för vektorindexering och frågor samt för semantisk rangordning.

  1. Öppna en ny textfil i Visual Studio Code.

  2. Ange variabler till sökslutpunkten och API-nyckeln som du samlade in tidigare.

    @baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE
    @apiKey = PUT-YOUR-ADMIN-API-KEY-HERE
    
  3. Spara filen med ett .rest filnamnstillägg.

  4. Klistra in följande exempel för att skapa indexet för hotels-vector-quickstart söktjänsten.

    ### Create a new index
    POST {{baseUrl}}/indexes?api-version=2023-11-01  HTTP/1.1
        Content-Type: application/json
        api-key: {{apiKey}}
    
    {
        "name": "hotels-vector-quickstart",
        "fields": [
            {
                "name": "HotelId", 
                "type": "Edm.String",
                "searchable": false, 
                "filterable": true, 
                "retrievable": true, 
                "sortable": false, 
                "facetable": false,
                "key": true
            },
            {
                "name": "HotelName", 
                "type": "Edm.String",
                "searchable": true, 
                "filterable": false, 
                "retrievable": true, 
                "sortable": true, 
                "facetable": false
            },
            {
                "name": "HotelNameVector",
                "type": "Collection(Edm.Single)",
                "searchable": true,
                "retrievable": true,
                "dimensions": 1536,
                "vectorSearchProfile": "my-vector-profile"
            },
            {
                "name": "Description", 
                "type": "Edm.String",
                "searchable": true, 
                "filterable": false, 
                "retrievable": true, 
                "sortable": false, 
                "facetable": false
            },
            {
                "name": "DescriptionVector",
                "type": "Collection(Edm.Single)",
                "searchable": true,
                "retrievable": true,
                "dimensions": 1536,
                "vectorSearchProfile": "my-vector-profile"
            },
            {
                "name": "Category", 
                "type": "Edm.String",
                "searchable": true, 
                "filterable": true, 
                "retrievable": true, 
                "sortable": true, 
                "facetable": true
            },
            {
                "name": "Tags",
                "type": "Collection(Edm.String)",
                "searchable": true,
                "filterable": true,
                "retrievable": true,
                "sortable": false,
                "facetable": true
            },
            {
                "name": "Address", 
                "type": "Edm.ComplexType",
                "fields": [
                    {
                        "name": "City", "type": "Edm.String",
                        "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true
                    },
                    {
                        "name": "StateProvince", "type": "Edm.String",
                        "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true
                    }
                ]
            },
            {
                "name": "Location",
                "type": "Edm.GeographyPoint",
                "searchable": false, 
                "filterable": true, 
                "retrievable": true, 
                "sortable": true, 
                "facetable": false
            }
        ],
        "vectorSearch": {
            "algorithms": [
                {
                    "name": "my-hnsw-vector-config-1",
                    "kind": "hnsw",
                    "hnswParameters": 
                    {
                        "m": 4,
                        "efConstruction": 400,
                        "efSearch": 500,
                        "metric": "cosine"
                    }
                },
                {
                    "name": "my-hnsw-vector-config-2",
                    "kind": "hnsw",
                    "hnswParameters": 
                    {
                        "m": 4,
                        "metric": "euclidean"
                    }
                },
                {
                    "name": "my-eknn-vector-config",
                    "kind": "exhaustiveKnn",
                    "exhaustiveKnnParameters": 
                    {
                        "metric": "cosine"
                    }
                }
            ],
            "profiles": [      
                {
                    "name": "my-vector-profile",
                    "algorithm": "my-hnsw-vector-config-1"
                }
          ]
        },
        "semantic": {
            "configurations": [
                {
                    "name": "my-semantic-config",
                    "prioritizedFields": {
                        "titleField": {
                            "fieldName": "HotelName"
                        },
                        "prioritizedContentFields": [
                            { "fieldName": "Description" }
                        ],
                        "prioritizedKeywordsFields": [
                            { "fieldName": "Tags" }
                        ]
                    }
                }
            ]
        }
    }
    
  5. Välj Skicka begäran. Kom ihåg att du behöver REST-klienten för att skicka begäranden. Du bör ha ett HTTP/1.1 201 Created svar. Svarstexten bör innehålla JSON-representationen av indexschemat.

    Viktiga punkter:

    • Samlingen fields innehåller ett obligatoriskt nyckelfält och text- och vektorfält (till exempel Description och DescriptionVector) för text- och vektorsökning. Genom att samlokalisera vektor- och icke-bevektorfält i samma index kan du använda hybridfrågor. Du kan till exempel kombinera filter, textsökning med semantisk rangordning och vektorer i en enda frågeåtgärd.
    • Vektorfält måste vara type: Collection(Edm.Single) med dimensions och vectorSearchProfile egenskaper.
    • Avsnittet vectorSearch är en matris med ungefärliga konfigurationer och profiler för närliggande algoritmer. Algoritmer som stöds är hierarkisk navigeringsbar liten värld och fullständig k-närmaste granne. Mer information finns i Relevansbedömning i vektorsökning.
    • [Valfritt]: Konfigurationen semantic gör det möjligt att ändra rangordning av sökresultat. Du kan ändra rangordningen av resultat i frågor av typen semantic för strängfält som anges i konfigurationen. Mer information finns i Översikt över semantisk rangordning.

Ladda upp dokument

Att skapa och läsa in indexet är separata steg. I Azure AI Search innehåller indexet alla sökbara data och frågor som körs i söktjänsten. För REST-anrop tillhandahålls data som JSON-dokument. Använd Documents – Index REST API för den här uppgiften.

URI:n utökas till att omfatta docs samlingen och åtgärden index .

Viktigt!

Följande exempel är inte körbar kod. För läsbarhet exkluderade vi vektorvärden eftersom var och en innehåller 1 536 inbäddningar, vilket är för långt för den här artikeln. Om du vill prova det här steget kopierar du körbar kod från exemplet på GitHub.

### Upload documents
POST {{baseUrl}}/indexes/hotels-quickstart-vectors/docs/index?api-version=2023-11-01  HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}

{
    "value": [
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "1",
            "HotelName": "Secret Point Motel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "The hotel is ideally located on the main commercial artery of the city 
                in the heart of New York.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Boutique",
            "Tags": [
                "pool",
                "air conditioning",
                "concierge"
            ],
        },
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "2",
            "HotelName": "Twin Dome Hotel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "The hotel is situated in a  nineteenth century plaza, which has been 
                expanded and renovated to the highest architectural standards to create a modern, 
                functional and first-class hotel in which art and unique historical elements 
                coexist with the most modern comforts.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Boutique",
            "Tags": [
                "pool",
                "air conditioning",
                "free wifi",
                "concierge"
            ]
        },
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "3",
            "HotelName": "Triple Landscape Hotel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "The Hotel stands out for its gastronomic excellence under the management of 
                William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Resort and Spa",
            "Tags": [
                "air conditioning",
                "bar",
                "continental breakfast"
            ]
        }
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "4",
            "HotelName": "Sublime Cliff Hotel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "Sublime Cliff Hotel is located in the heart of the historic center of 
                Sublime in an extremely vibrant and lively area within short walking distance to 
                the sites and landmarks of the city and is surrounded by the extraordinary beauty 
                of churches, buildings, shops and monuments. 
                Sublime Cliff is part of a lovingly restored 1800 palace.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Boutique",
            "Tags": [
                "concierge",
                "view",
                "24-hour front desk service"
            ]
        },
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "13",
            "HotelName": "Historic Lion Resort",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury 
                accommodations. Moments from the stadium, we feature the best in comfort",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Resort and Spa",
            "Tags": [
                "view",
                "free wifi",
                "pool"
            ]
        },
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "48",
            "HotelName": "Nordicks Hotel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "Only 90 miles (about 2 hours) from the nation's capital and nearby 
                most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring 
                the caverns?  It's all nearby and we have specially priced packages to help make 
                our B&B your home base for fun while visiting the valley.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Boutique",
            "Tags": [
                "continental breakfast",
                "air conditioning",
                "free wifi"
            ],
        },
        {
            "@search.action": "mergeOrUpload",
            "HotelId": "49",
            "HotelName": "Old Carrabelle Hotel",
            "HotelNameVector": [VECTOR ARRAY OMITTED],
            "Description": 
                "Spacious rooms, glamorous suites and residences, rooftop pool, walking 
                access to shopping, dining, entertainment and the city center.",
            "DescriptionVector": [VECTOR ARRAY OMITTED],
            "Category": "Luxury",
            "Tags": [
                "air conditioning",
                "laundry service",
                "24-hour front desk service"
            ]
        }
    ]
}

Viktiga punkter:

  • Dokument i nyttolasten består av fält som definierats i indexschemat.
  • Vektorfält innehåller flyttalsvärden. Dimensionsattributet har minst 2 och högst 3 072 flyttalsvärden vardera. Den här snabbstarten anger dimensionsattributet till 1 536 eftersom det är storleken på inbäddningar som genereras av Open AI:s textinbäddnings-ada-002-modell .

Köra frågor

Nu när dokument har lästs in kan du skicka vektorfrågor mot dem med hjälp av Dokument – Sök efter (REST).

Det finns flera frågor för att demonstrera olika mönster:

Vektorfrågorna i det här avsnittet baseras på två strängar:

  • Söksträng: historic hotel walk to restaurants and shopping
  • Vektorfrågesträng (vektoriserad i en matematisk representation): classic lodging near running trails, eateries, retail

Vektorfrågesträngen liknar söksträngen semantiskt, men den innehåller termer som inte finns i sökindexet. Om du gör en nyckelordssökning för classic lodging near running trails, eateries, retailär resultatet noll. Vi använder det här exemplet för att visa hur du kan få relevanta resultat även om det inte finns några matchande termer.

Viktigt!

Följande exempel är inte körbar kod. För läsbarhet exkluderade vi vektorvärden eftersom varje matris innehåller 1 536 inbäddningar, vilket är för långt för den här artikeln. Om du vill prova dessa frågor kopierar du körbar kod från exemplet på GitHub.

  1. Klistra in en POST-begäran för att fråga sökindexet. Välj sedan Skicka begäran. URI:n utökas till att omfatta operatorn /docs/search .

    ### Run a query
    POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01  HTTP/1.1
        Content-Type: application/json
        api-key: {{apiKey}}
    
        {
            "count": true,
            "select": "HotelId, HotelName, Description, Category",
            "vectorQueries": [
                {
                    "vector"": [0.01944167, 0.0040178085
                        . . .  TRIMMED FOR BREVITY
                        010858015, -0.017496133],
                    "k": 7,
                    "fields": "DescriptionVector",
                    "kind": "vector",
                    "exhaustive": true
                }
            ]
        }
    

    Den här vektorfrågan förkortas för korthet. Innehåller vectorQueries.vector den vektoriserade texten i frågeindata, fields avgör vilka vektorfält som söks och k anger antalet närmaste grannar som ska returneras.

    Vektorfrågesträngen är classic lodging near running trails, eateries, retail, som är vektoriserad i 1 536 inbäddningar för den här frågan.

  2. Läs svaret. Svaret för vektorekvivalenten för classic lodging near running trails, eateries, retail innehåller sju resultat. Varje resultat ger en sökpoäng och fälten som anges i select. I en likhetssökning innehåller k svaret alltid resultat ordnade efter värdets likhetspoäng.

    {
        "@odata.context": "https://my-demo-search.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
        "@odata.count": 7,
        "value": [
            {
                "@search.score": 0.857736,
                "HotelName": "Nordick's Motel",
                "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring the caverns?  It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley."
            },
            {
                "@search.score": 0.8399129,
                "HotelName": "Old Carrabelle Hotel",
                "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center."
            },
            {
                "@search.score": 0.8383954,
                "HotelName": "Historic Lion Resort",
                "Description": "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort"
            },
            {
                "@search.score": 0.8254346,
                "HotelName": "Sublime Cliff Hotel",
                "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace."
            },
            {
                "@search.score": 0.82380056,
                "HotelName": "Secret Point Hotel",
                "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York."
            },
            {
                "@search.score": 0.81514084,
                "HotelName": "Twin Dome Hotel",
                "Description": "The hotel is situated in a  nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts."
            },
            {
                "@search.score": 0.8133763,
                "HotelName": "Triple Landscape Hotel",
                "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services."
            }
        ]
    }
    

Enkel vektorsökning med filter

Du kan lägga till filter, men filtren tillämpas på icke-bevektorinnehållet i ditt index. I det här exemplet gäller filtret för fältet Tags för att filtrera bort alla hotell som inte tillhandahåller kostnadsfritt Wi-Fi.

  1. Klistra in en POST-begäran för att fråga sökindexet.

    ### Run a vector query with a filter
    POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01  HTTP/1.1
        Content-Type: application/json
        api-key: {{apiKey}}
    
        {
            "count": true,
            "select": "HotelId, HotelName, Category, Tags, Description",
            "filter": "Tags/any(tag: tag eq 'free wifi')",
            "vectorFilterMode": "postFilter",
            "vectorQueries": [
            {
                "vector": [ VECTOR OMITTED ],
                "k": 7,
                "fields": "DescriptionVector",
                "kind": "vector",
                "exhaustive": true
            },
        ]
    }
    
  2. Läs svaret. Frågan är densamma som i föregående exempel, men den innehåller ett exkluderingsfilter efter bearbetning och returnerar endast de tre hotell som har kostnadsfritt Wi-Fi.

    {
    
        "@odata.count": 3,
        "value": [
            {
                "@search.score": 0.857736,
                "HotelName": "Nordick's Motel",
                "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring the caverns?  It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.",
                "Tags": [
                    "continental breakfast",
                    "air conditioning",
                    "free wifi"
                ]
            },
            {
                "@search.score": 0.8383954,
                "HotelName": "Historic Lion Resort",
                "Description": "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort",
                "Tags": [
                    "view",
                    "free wifi",
                    "pool"
                ]
            },
            {
                "@search.score": 0.81514084,
                "HotelName": "Twin Dome Hotel",
                "Description": "The hotel is situated in a  nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.",
                "Tags": [
                    "pool",
                    "free wifi",
                    "concierge"
                ]
            }
        ]
    }
    

Hybridsökning består av nyckelordsfrågor och vektorfrågor i en enda sökbegäran. I det här exemplet körs vektorfrågan och fulltextsökning samtidigt:

  • Söksträng: historic hotel walk to restaurants and shopping
  • Vektorfrågesträng (vektoriserad i en matematisk representation): classic lodging near running trails, eateries, retail
  1. Klistra in en POST-begäran för att fråga sökindexet. Välj sedan Skicka begäran.

    ### Run a hybrid query
    POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01  HTTP/1.1
        Content-Type: application/json
        api-key: {{apiKey}}
    
    {
        "count": true,
        "search": "historic hotel walk to restaurants and shopping",
        "select": "HotelName, Description",
        "top": 7,
        "vectorQueries": [
            {
                "vector": [ VECTOR OMITTED],
                "k": 7,
                "fields": "DescriptionVector",
                "kind": "vector",
                "exhaustive": true
            }
        ]
    }
    

    Eftersom det här är en hybridfråga rangordnas resultaten efter Reciprocal Rank Fusion (RRF). RRF utvärderar sökpoäng för flera sökresultat, tar inversen och sammanfogar och sorterar sedan de kombinerade resultaten. Antalet top resultat returneras.

  2. Läs svaret.

    {
        "@odata.count": 7,
        "value": [
            {
                "@search.score": 0.03279569745063782,
                "HotelName": "Historic Lion Resort",
                "Description": "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort"
            },
            {
                "@search.score": 0.03226646035909653,
                "HotelName": "Sublime Cliff Hotel",
                "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace."
            },
            {
                "@search.score": 0.03226646035909653,
                "HotelName": "Old Carrabelle Hotel",
                "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center."
            },
            {
                "@search.score": 0.03205128386616707,
                "HotelName": "Nordick's Motel",
                "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring the caverns?  It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley."
            },
            {
                "@search.score": 0.03128054738044739,
                "HotelName": "Triple Landscape Hotel",
                "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services."
            },
            {
                "@search.score": 0.03100961446762085,
                "HotelName": "Twin Dome Hotel",
                "Description": "The hotel is situated in a  nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts."
            },
            {
                "@search.score": 0.03077651560306549,
                "HotelName": "Secret Point Hotel",
                "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York."
            }
        ]
    }
    

    Eftersom RRF sammanfogar resultat hjälper det att granska indata. Följande resultat kommer endast från fulltextfrågan. De två bästa resultaten är Sublime Cliff Hotel och History Lion Resort. Sublime Cliff Hotel har en starkare BM25 relevanspoäng.

            {
                "@search.score": 2.2626662,
                "HotelName": "Sublime Cliff Hotel",
                "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace."
            },
            {
                "@search.score": 0.86421645,
                "HotelName": "Historic Lion Resort",
                "Description": "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort"
                },
    

    I frågan med endast vektor, som använder HNSW för att hitta matchningar, sjunker Sublime Cliff Hotel till fjärde plats. Historic Lion, som var tvåa i fulltextsökningen och tredje i vektorsökningen, upplever inte samma fluktuationsintervall, så det visas som en toppmatchning i en homogeniserad resultatuppsättning.

        "value": [
            {
                "@search.score": 0.857736,
                "HotelId": "48",
                "HotelName": "Nordick's Motel",
                "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring the caverns?  It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.",
                "Category": "Boutique"
            },
            {
                "@search.score": 0.8399129,
                "HotelId": "49",
                "HotelName": "Old Carrabelle Hotel",
                "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center.",
                "Category": "Luxury"
            },
            {
                "@search.score": 0.8383954,
                "HotelId": "13",
                "HotelName": "Historic Lion Resort",
                "Description": "Unmatched Luxury.  Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort",
                "Category": "Resort and Spa"
            },
            {
                "@search.score": 0.8254346,
                "HotelId": "4",
                "HotelName": "Sublime Cliff Hotel",
                "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace.",
                "Category": "Boutique"
            },
            {
                "@search.score": 0.82380056,
                "HotelId": "1",
                "HotelName": "Secret Point Hotel",
                "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York.",
                "Category": "Boutique"
            },
            {
                "@search.score": 0.81514084,
                "HotelId": "2",
                "HotelName": "Twin Dome Hotel",
                "Description": "The hotel is situated in a  nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.",
                "Category": "Boutique"
            },
            {
                "@search.score": 0.8133763,
                "HotelId": "3",
                "HotelName": "Triple Landscape Hotel",
                "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
                "Category": "Resort and Spa"
            }
        ]
    

Semantisk hybridsökning med ett filter

Här är den sista frågan i samlingen. Den här hybridfrågan med semantisk rangordning filtreras för att endast visa hotellen inom en radie på 500 kilometer från Washington D.C. Du kan ange vectorFilterMode null, vilket motsvarar standardvärdet (preFilter för nyare index och postFilter för äldre index).

  1. Klistra in en POST-begäran för att fråga sökindexet. Välj sedan Skicka begäran.

    ### Run a hybrid query
    POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01  HTTP/1.1
        Content-Type: application/json
        api-key: {{apiKey}}
    
    {
        "count": true,
        "search": "historic hotel walk to restaurants and shopping",
        "select": "HotelId, HotelName, Category, Description,Address/City, Address/StateProvince",
        "filter": "geo.distance(Location, geography'POINT(-77.03241 38.90166)') le 500",
        "vectorFilterMode": null,
        "facets": [ "Address/StateProvince"],
        "top": 7,
        "queryType": "semantic",
        "answers": "extractive|count-3",
        "captions": "extractive|highlight-true",
        "semanticConfiguration": "my-semantic-config",
        "vectorQueries": [
            {
                "vector": [ VECTOR OMITTED ],
                "k": 7,
                "fields": "DescriptionVector",
                "kind": "vector",
                "exhaustive": true
            }
        ]
    }
    
  2. Läs svaret. Svaret är tre hotell, som filtreras efter plats och fasetteras av StateProvince och semantiskt rangordnas om för att höja upp resultat som är närmast söksträngsfrågan (historic hotel walk to restaurants and shopping).

    Old Carabelle Hotel flyttar nu till topplaceringen. Utan semantisk rankning är Nordick's Hotel nummer ett. Med semantisk rankning känner maskinförståelsemodellerna igen som historic gäller för "hotell, inom gångavstånd till restauranger och shopping.".

    {
        "@odata.count": 3,
        "@search.facets": {
            "Address/StateProvince": [
                {
                    "count": 1,
                    "value": "NY"
                },
                {
                    "count": 1,
                    "value": "VA"
                }
            ]
        },
        "@search.answers": [],
        "value": [
            {
                "@search.score": 0.03306011110544205,
                "@search.rerankerScore": 2.5094974040985107,
                "HotelId": "49",
                "HotelName": "Old Carrabelle Hotel",
                "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center.",
                "Category": "Luxury",
                "Address": {
                    "City": "Arlington",
                    "StateProvince": "VA"
                }
            },
            {
                "@search.score": 0.03306011110544205,
                "@search.rerankerScore": 2.0370211601257324,
                "HotelId": "48",
                "HotelName": "Nordick's Motel",
                "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer.  Hiking? Wine Tasting? Exploring the caverns?  It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.",
                "Category": "Boutique",
                "Address": {
                    "City": "Washington D.C.",
                    "StateProvince": null
                }
            },
            {
                "@search.score": 0.032258063554763794,
                "@search.rerankerScore": 1.6706111431121826,
                "HotelId": "1",
                "HotelName": "Secret Point Hotel",
                "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York.",
                "Category": "Boutique",
                "Address": {
                    "City": "New York",
                    "StateProvince": "NY"
                }
            }
        ]
    }
    

    Viktiga punkter:

    • Vektorsökning anges via egenskapen vectors.value . Nyckelordssökning anges via egenskapen search .
    • I en hybridsökning kan du integrera vektorsökning med fulltextsökning över nyckelord. Filter, stavningskontroll och semantisk rangordning gäller endast för textinnehåll och inte vektorer. I den här sista frågan finns det ingen semantisk answer eftersom systemet inte har skapat en som var tillräckligt stark.
    • Faktiska resultat innehåller mer information, inklusive semantiska bildtext och markeringar. Resultaten ändrades för läsbarhet. Kör begäran i REST-klienten för att få hela strukturen för svaret.

Rensa

När du arbetar i din egen prenumeration kan det dock vara klokt att i slutet av ett projekt kontrollera om du fortfarande behöver de resurser som du skapade. Resurser som fortsätter att köras kostar pengar. Du kan ta bort enstaka resurser eller hela resursgruppen om du vill ta bort alla resurser.

Du kan hitta och hantera resurser i portalen med hjälp av länken Alla resurser eller Resursgrupper i det vänstra fönstret.

Du kan också prova det här DELETE kommandot:

### Delete an index
DELETE  {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
    Content-Type: application/json
    api-key: {{apiKey}}

Nästa steg

Som ett nästa steg rekommenderar vi att du granskar demokoden för Python, C#eller JavaScript.