Rychlý start: Vektorové vyhledávání pomocí REST

Naučte se používat rozhraní REST API služby Search k vytváření, načítání a dotazování vektorů ve službě Azure AI Search.

Ve službě Azure AI Search má úložiště vektorů schéma indexu, které definuje vektorová a nevectorová pole, vektorovou konfiguraci pro algoritmy, které vytvářejí vložený prostor a nastavení definic vektorových polí, které se používají v požadavcích dotazů. Rozhraní API pro vytvoření indexu vytvoří vektorové úložiště.

Pokud ještě nemáte předplatné Azure, vytvořte si napřed bezplatný účet.

Poznámka:

Stabilní verze rozhraní REST API z 11. 11 . 2023 závisí na externích řešeních pro vytváření bloků dat a vkládání. Pokud chcete vyhodnotit předdefinované funkce bloků a vektorizace dat (Public Preview), vyzkoušejte průvodce importem a vektorizací dat pro kompletní návod.

Požadavky

  • Visual Studio Code s klientem REST Pokud potřebujete pomoc se zahájením práce, přečtěte si článek Rychlý start: Vyhledávání textu pomocí REST.

  • Azure AI Search, v libovolné oblasti a na libovolné úrovni. Pro účely tohoto rychlého startu můžete použít úroveň Free, ale pro větší datové soubory se doporučuje Basic nebo vyšší. Vytvořte nebo najděte existující prostředek služby Azure AI Search v rámci vašeho aktuálního předplatného.

    Většina existujících služeb podporuje vektorové vyhledávání. U malé podmnožina služeb vytvořených před lednem 2019 se při vytváření nezdaří index obsahující vektorová pole. V takovém případě se musí vytvořit nová služba.

  • Volitelně můžete spustit příklad dotazu, který vyvolá sémantické reranking, vaše vyhledávací služba musí být úroveň Basic nebo vyšší s povoleným sémantickým řazením.

  • Volitelně můžete prostředek Azure OpenAI s nasazením text-embedding-ada-002. Zdrojový .rest soubor obsahuje volitelný krok pro generování nových vkládání textu, ale poskytujeme předgenerované vkládání, abyste tuto závislost mohli vynechat.

Stažení souborů

Stáhněte si ukázku REST z GitHubu pro odeslání požadavků v tomto rychlém startu. Další informace najdete v tématu Stahování souborů z GitHubu.

Můžete také spustit nový soubor v místním systému a ručně vytvořit požadavky pomocí pokynů v tomto článku.

Zkopírování klíče a adresy URL vyhledávací služby

Volání REST vyžadují koncový bod vyhledávací služby a klíč rozhraní API pro každý požadavek. Tyto hodnoty můžete získat z webu Azure Portal.

  1. Přihlaste se k portálu Azure. Přejděte na stránku Přehled a zkopírujte adresu URL. Příkladem koncového bodu může být https://mydemo.search.windows.net.

  2. Vyberte Nastavení> Klíče a zkopírujte klíč správce. Správa klíče slouží k přidávání, úpravám a odstraňování objektů. Existují dva zaměnitelné klíče správce. Zkopírujte jeden z nich.

    Snímek obrazovky znázorňující adresu URL a klíče rozhraní API na webu Azure Portal

Vytvoření vektorového indexu

Vytvoření indexu (REST) vytvoří vektorový index a nastaví fyzické datové struktury ve vyhledávací službě.

Schéma indexu je uspořádané kolem obsahu hotelu. Ukázková data se skládají z vektorových a nevectorových názvů a popisů sedmi fiktivních hotelů. Toto schéma zahrnuje konfigurace pro indexování vektorů a dotazy a sémantické řazení.

  1. Otevřete nový textový soubor v editoru Visual Studio Code.

  2. Nastavte proměnné na koncový bod vyhledávání a klíč rozhraní API, který jste shromáždili dříve.

    @baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE
    @apiKey = PUT-YOUR-ADMIN-API-KEY-HERE
    
  3. Uložte soubor s příponou .rest souboru.

  4. Vložte následující příklad a vytvořte index ve hotels-vector-quickstart vyhledávací službě.

    ### 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. Vyberte Odeslat žádost. Vzpomeňte si, že k odesílání požadavků potřebujete klienta REST. Měli byste mít HTTP/1.1 201 Created odpověď. Text odpovědi by měl obsahovat reprezentaci schématu indexu JSON.

    Klíčové body:

    • Kolekce fields obsahuje povinné klíčové pole a textová a vektorová pole (například Description a DescriptionVector) pro textové a vektorové vyhledávání. Společné přidělení vektorových a nevectorových polí ve stejném indexu umožňuje hybridní dotazy. Můžete například zkombinovat filtry, vyhledávání textu pomocí sémantického řazení a vektorů do jedné operace dotazu.
    • Vektorová pole musí obsahovat type: Collection(Edm.Single)dimensions vlastnosti a vectorSearchProfile vlastnosti.
    • Oddíl vectorSearch je pole přibližných konfigurací a profilů algoritmů nejbližšího souseda. Mezi podporované algoritmy patří hierarchická navigace v malém světě a vyčerpávající k-nejbližší soused. Další informace najdete v tématu Bodování relevance při hledání vektorů.
    • [Volitelné]: Konfigurace semantic umožňuje změnit pořadí výsledků hledání. Výsledky můžete přeřadit v dotazech typu semantic pro pole řetězců, která jsou zadaná v konfiguraci. Další informace najdete v přehledu sémantického řazení.

Nahrát dokumenty

Vytvoření a načtení indexu jsou samostatné kroky. Index ve službě Azure AI Search obsahuje všechna prohledávatelná data a dotazy spuštěné ve vyhledávací službě. Pro volání REST jsou data poskytována jako dokumenty JSON. Pro tuto úlohu použijte rozhraní REST API indexu dokumentů.

Identifikátor URI je rozšířen tak, aby zahrnoval kolekci docsindex a operaci.

Důležité

Následující příklad není spustitelný kód. Pro čitelnost jsme vyloučili hodnoty vektoru, protože každý z nich obsahuje 1 536 vkládání, což je pro tento článek příliš dlouhé. Pokud chcete tento krok vyzkoušet, zkopírujte spustitelný kód z ukázky na GitHubu.

### 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"
            ]
        }
    ]
}

Klíčové body:

  • Dokumenty v datové části se skládají z polí definovaných ve schématu indexu.
  • Vektorová pole obsahují hodnoty s plovoucí desetinou čárkou. Atribut dimenzí má minimálně 2 a maximálně 3 072 hodnot s plovoucí desetinou čárkou. Tento rychlý start nastaví atribut dimenzí na 1 536, protože to je velikost vkládání vygenerovaných modelem Open AI pro vložení textu-ada-002 .

Spouštění dotazů

Teď, když jsou dokumenty načtené, můžete vůči nim vydávat vektorové dotazy pomocí funkce Documents – Search Post (REST).

Existuje několik dotazů, které demonstrují různé vzory:

Vektorové dotazy v této části jsou založené na dvou řetězcích:

  • Hledaný řetězec: historic hotel walk to restaurants and shopping
  • Vektorový řetězec dotazu (vektorizovaný do matematické reprezentace): classic lodging near running trails, eateries, retail

Řetězec vektorového dotazu je sémanticky podobný hledanému řetězci, ale obsahuje výrazy, které v indexu vyhledávání neexistují. Pokud hledáte classic lodging near running trails, eateries, retailklíčové slovo, výsledky jsou nulové. Tento příklad používáme k zobrazení toho, jak můžete získat relevantní výsledky, i když neexistují žádné odpovídající termíny.

Důležité

Následující příklady nejsou spustitelné kódy. Pro čitelnost jsme vyloučili vektorové hodnoty, protože každé pole obsahuje 1 536 vkládání, což je pro tento článek příliš dlouhé. Pokud chcete tyto dotazy vyzkoušet, zkopírujte spustitelný kód z ukázky na GitHubu.

  1. Vložte požadavek POST pro dotazování indexu vyhledávání. Pak vyberte Odeslat požadavek. Identifikátor URI je rozšířen tak, aby zahrnoval /docs/search operátor.

    ### 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
                }
            ]
        }
    

    Tento vektorový dotaz je zkrácen pro stručnost. Obsahuje vectorQueries.vector vektorizovaný text vstupu dotazu, určuje, fields která vektorová pole se prohledávají, a k určuje počet nejbližších sousedů, které se mají vrátit.

    Řetězec vektorového dotazu je classic lodging near running trails, eateries, retail, který je vektorizován do 1 536 vkládání pro tento dotaz.

  2. Prohlédněte si odpověď. Odpověď pro vektorový classic lodging near running trails, eateries, retail ekvivalent zahrnuje sedm výsledků. Každý výsledek poskytuje skóre hledání a pole uvedená v selectseznamu . Ve vyhledávání podobnosti odpověď vždy obsahuje k výsledky seřazené podle skóre podobnosti hodnoty.

    {
        "@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."
            }
        ]
    }
    

Jednoduché vektorové vyhledávání s filtrem

Můžete přidat filtry, ale filtry se použijí na obsah nevectoru ve vašem indexu. V tomto příkladu Tags se filtr vztahuje na pole a vyfiltruje všechny hotely, které neposkytují bezplatné Wi-Fi.

  1. Vložte požadavek POST pro dotazování indexu vyhledávání.

    ### 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. Prohlédněte si odpověď. Dotaz je stejný jako v předchozím příkladu, ale obsahuje filtr vyloučení po zpracování a vrátí pouze tři hotely, které mají bezplatné 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"
                ]
            }
        ]
    }
    

Hybridní vyhledávání se skládá z dotazů klíčových slov a vektorových dotazů v jediné žádosti o vyhledávání. Tento příklad spustí vektorový dotaz a fulltextové vyhledávání souběžně:

  • Hledaný řetězec: historic hotel walk to restaurants and shopping
  • Vektorový řetězec dotazu (vektorizovaný do matematické reprezentace): classic lodging near running trails, eateries, retail
  1. Vložte požadavek POST pro dotazování indexu vyhledávání. Pak vyberte Odeslat požadavek.

    ### 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
            }
        ]
    }
    

    Vzhledem k tomu, že se jedná o hybridní dotaz, výsledky jsou seřazené podle reciproční Rank Fusion (RRF). RRF vyhodnocuje skóre hledání více výsledků hledání, vezme inverzní funkci a pak sloučí a seřadí kombinované výsledky. Vrátí top se počet výsledků.

  2. Prohlédněte si odpověď.

    {
        "@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."
            }
        ]
    }
    

    Vzhledem k tomu, že RRF sloučí výsledky, pomáhá kontrolovat vstupy. Následující výsledky pocházejí pouze z fulltextového dotazu. Nejlepší dva výsledky jsou Sublime Cliff Hotel a History Lion Resort. Sublime Cliff Hotel má silnější skóre relevance BM25.

            {
                "@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"
                },
    

    Ve vektorovém dotazu, který používá HNSW pro hledání shod, Sublime Cliff Hotel klesne na čtvrtou pozici. Historický Lion, který byl druhý v fulltextovém vyhledávání a třetí ve vektorovém vyhledávání, nemá stejný rozsah kolísání, takže se zobrazuje jako nejlepší shoda v homogenizované sadě výsledků.

        "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"
            }
        ]
    

Sémantické hybridní vyhledávání s filtrem

Tady je poslední dotaz v kolekci. Tento hybridní dotaz s sémantickým řazením je filtrovaný tak, aby zobrazoval pouze hotely v okruhu 500 kilometrů od WashingtonU D.C. Můžete nastavit vectorFilterMode hodnotu null, která je ekvivalentní výchozímu nastavení (preFilter pro novější indexy a postFilter pro starší indexy).

  1. Vložte požadavek POST pro dotazování indexu vyhledávání. Pak vyberte Odeslat požadavek.

    ### 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. Prohlédněte si odpověď. Odpověď je tři hotely, které jsou filtrované podle umístění a omezující StateProvince vlastnosti a sémanticky se přeřadí tak, aby podporovaly výsledky, které jsou nejblíže dotazu vyhledávacího řetězce (historic hotel walk to restaurants and shopping).

    Old Carabelle Hotel se nyní přesune do horního místa. Bez sémantického hodnocení je Nordick's Hotel číslo jedna. Díky sémantickému řazení modely strojového porozumění rozpoznávají, že historic se vztahuje na "hotel, v pěší vzdálenosti od restaurace a nakupování".

    {
        "@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"
                }
            }
        ]
    }
    

    Klíčové body:

    • Vektorové vyhledávání je určeno prostřednictvím vectors.value vlastnosti. Vyhledávání klíčových slov je určeno prostřednictvím search vlastnosti.
    • V hybridním vyhledávání můžete integrovat vektorové vyhledávání s fulltextovým vyhledáváním pomocí klíčových slov. Filtry, kontrola pravopisu a sémantické řazení se vztahují pouze na textový obsah, nikoli na vektory. V tomto posledním dotazu není žádný sémantický answer , protože systém nevytvořil takový, který by byl dostatečně silný.
    • Skutečné výsledky obsahují více podrobností, včetně sémantických popis a zvýraznění. Výsledky byly upraveny tak, aby byly čitelné. Pokud chcete získat úplnou strukturu odpovědi, spusťte požadavek v klientovi REST.

Vyčištění

Pokud pracujete s vlastním předplatným, je vhodné vždy na konci projektu zkontrolovat, jestli budete vytvořené prostředky ještě potřebovat. Prostředky, které necháte spuštěné, vás stojí peníze. Prostředky můžete odstraňovat jednotlivě nebo můžete odstranit skupinu prostředků, a odstranit tak celou sadu prostředků najednou.

Prostředky můžete najít a spravovat na portálu pomocí odkazu Všechny prostředky nebo skupiny prostředků v levém podokně.

Můžete také vyzkoušet tento DELETE příkaz:

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

Další kroky

Jako další krok doporučujeme zkontrolovat ukázkový kód pro Python, C# nebo JavaScript.