Guida introduttiva: Ricerca vettoriale con REST
Informazioni su come usare le API REST di ricerca per creare, caricare ed eseguire query sui vettori in Ricerca di intelligenza artificiale di Azure.
In Ricerca di intelligenza artificiale di Azure, un archivio vettoriale ha uno schema di indice che definisce i campi vettoriali e non di filtro, una configurazione vettoriale per gli algoritmi che creano lo spazio di incorporamento e le impostazioni sulle definizioni di campo vettoriale usate nelle richieste di query. L'API Crea indice crea l'archivio vettoriale.
Se non si ha una sottoscrizione di Azure, creare un account gratuito prima di iniziare.
Nota
La versione stabile dell'API REST 2023-11-01 dipende da soluzioni esterne per la suddivisione in blocchi dei dati e l'incorporamento. Se si desidera valutare le funzionalità predefinite di suddivisione in blocchi e vettorizzazione dei dati (anteprima pubblica), provare la procedura guidata Importare e vettorizzare i dati per una procedura dettagliata end-to-end.
Prerequisiti
Visual Studio Code con un client REST. Per informazioni introduttive, vedere Guida introduttiva: Ricerca di testo con REST.
Ricerca di intelligenza artificiale di Azure, in qualsiasi area e in qualsiasi livello. È possibile usare il livello gratuito per questa guida introduttiva, ma è consigliabile usare Basic o versione successiva per i file di dati di dimensioni maggiori. Creare o trovare una risorsa di Ricerca intelligenza artificiale di Azure esistente nella sottoscrizione corrente.
La maggior parte dei servizi esistenti supporta la ricerca vettoriale. Per un piccolo subset di servizi creato prima di gennaio 2019, un indice che contiene campi vettoriali non riesce alla creazione. In questo caso, è necessario creare un nuovo servizio.
Facoltativamente, per eseguire l'esempio di query che richiama il reranking semantico, il servizio di ricerca deve essere il livello Basic o superiore, con la classificazione semantica abilitata.
Facoltativamente, una risorsa OpenAI di Azure con una distribuzione di
text-embedding-ada-002
. Il file di origine.rest
include un passaggio facoltativo per la generazione di nuovi incorporamenti di testo, ma vengono forniti incorporamenti pregenerati in modo da omettere questa dipendenza.
Scaricare i file
Scaricare un esempio REST da GitHub per inviare le richieste in questa guida introduttiva. Per altre informazioni, vedere Download di file da GitHub.
È anche possibile avviare un nuovo file nel sistema locale e creare richieste manualmente seguendo le istruzioni riportate in questo articolo.
Copiare una chiave e un URL del servizio di ricerca
Le chiamate REST richiedono l'endpoint del servizio di ricerca e una chiave API per ogni richiesta. È possibile ottenere questi valori dalla portale di Azure.
Accedere al portale di Azure. Passare alla pagina Panoramica e copiare l'URL. Un endpoint di esempio potrebbe essere simile a
https://mydemo.search.windows.net
.Selezionare Impostazioni> Chiavi e copiare una chiave di amministratore. Amministrazione chiavi vengono usate per aggiungere, modificare ed eliminare oggetti. Sono disponibili due chiavi di amministrazione intercambiabili. Copiarne uno.
Creare un indice vettoriale
Creare un indice (REST) crea un indice vettoriale e configura le strutture di dati fisici nel servizio di ricerca.
Lo schema dell'indice è organizzato in base al contenuto dell'hotel. I dati di esempio sono costituiti da nomi vettoriali e non di tori e descrizioni di sette hotel fittizi. Questo schema include configurazioni per l'indicizzazione vettoriale e le query e per la classificazione semantica.
Aprire un nuovo file di testo in Visual Studio Code.
Impostare le variabili sull'endpoint di ricerca e sulla chiave API raccolte in precedenza.
@baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE @apiKey = PUT-YOUR-ADMIN-API-KEY-HERE
Salvare il file con un'estensione
.rest
di file.Incollare l'esempio seguente per creare l'indice
hotels-vector-quickstart
nel servizio di ricerca.### 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" } ] } } ] } }
Selezionare Invia richiesta. Tenere presente che è necessario il client REST per inviare richieste. Si dovrebbe avere una
HTTP/1.1 201 Created
risposta. Il corpo della risposta deve includere la rappresentazione JSON dello schema dell'indice.Punti chiave:
- La
fields
raccolta include un campo chiave obbligatorio e campi di testo e vettore (ad esempioDescription
eDescriptionVector
) per la ricerca di testo e vettore. Il colocating di campi vettoriali e non di operatore nello stesso indice consente query ibride. Ad esempio, è possibile combinare filtri, ricerca di testo con classificazione semantica e vettori in una singola operazione di query. - I campi vettoriali devono essere
type: Collection(Edm.Single)
condimensions
le proprietà evectorSearchProfile
. - La
vectorSearch
sezione è una matrice di configurazioni e profili approssimativi degli algoritmi vicini più vicini. Gli algoritmi supportati includono piccoli mondi navigabili gerarchici ed esaustivi vicini k-nearest. Per altre informazioni, vedere Assegnazione dei punteggi per pertinenza nella ricerca vettoriale. - [Facoltativo]: la
semantic
configurazione abilita il reranking dei risultati della ricerca. È possibile riesezionare i risultati nelle query di tiposemantic
per i campi stringa specificati nella configurazione. Per altre informazioni, vedere Panoramica della classificazione semantica.
- La
Carica documenti
La creazione e il caricamento dell'indice sono passaggi separati. In Ricerca di intelligenza artificiale di Azure l'indice contiene tutti i dati e le query ricercabili eseguiti nel servizio di ricerca. Per le chiamate REST, i dati vengono forniti come documenti JSON. Usare l'API REST Documents- Index per questa attività.
L'URI viene esteso per includere la docs
raccolta e l'operazione index
.
Importante
L'esempio seguente non è eseguibile. Per la leggibilità, sono stati esclusi i valori vettoriali perché ognuno contiene 1.536 incorporamenti, che è troppo lungo per questo articolo. Per provare questo passaggio, copiare il codice eseguibile dall'esempio in 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"
]
}
]
}
Punti chiave:
- I documenti nel payload sono costituiti da campi definiti nello schema dell'indice.
- I campi vettoriali contengono valori a virgola mobile. L'attributo dimensions ha un minimo di 2 e un massimo di 3.072 valori a virgola mobile ciascuno. Questo argomento di avvio rapido imposta l'attributo dimensions su 1.536 perché è la dimensione degli incorporamenti generati dal modello text-embedding-ada-002 di Open AI.
Esegui query
Ora che i documenti vengono caricati, è possibile eseguire query vettoriali su di esse usando Documenti - Post di ricerca (REST).
Esistono diverse query per illustrare vari modelli:
- Ricerca a vettore singolo
- Ricerca a vettore singolo con filtro
- Ricerca ibrida
- Ricerca ibrida semantica con filtro
Le query vettoriali in questa sezione si basano su due stringhe:
- Stringa di ricerca:
historic hotel walk to restaurants and shopping
- Stringa di query vettoriale (vettorializzata in una rappresentazione matematica):
classic lodging near running trails, eateries, retail
La stringa di query vettoriale è semanticamente simile alla stringa di ricerca, ma include termini che non esistono nell'indice di ricerca. Se si esegue una ricerca di parole chiave per classic lodging near running trails, eateries, retail
, i risultati sono zero. Questo esempio viene usato per mostrare come ottenere risultati pertinenti anche se non sono presenti termini corrispondenti.
Importante
Gli esempi seguenti non sono codice eseguibile. Per la leggibilità, sono stati esclusi i valori vettoriali perché ogni matrice contiene 1.536 incorporamenti, troppo lunghi per questo articolo. Per provare queste query, copiare il codice eseguibile dall'esempio in GitHub.
Ricerca a vettore singolo
Incollare una richiesta POST per eseguire una query sull'indice di ricerca. Selezionare quindi Invia richiesta. L'URI viene esteso per includere l'operatore
/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 } ] }
Questa query vettoriale viene abbreviata per brevità.
vectorQueries.vector
Contiene il testo vettorializzato dell'input della query,fields
determina quali campi vettoriali vengono cercati ek
specifica il numero di vicini più vicini da restituire.La stringa di query vettoriale è , che viene
classic lodging near running trails, eateries, retail
vettorializzata in 1.536 incorporamenti per questa query.Rivedere la risposta. La risposta per l'equivalente vettore di
classic lodging near running trails, eateries, retail
include sette risultati. Ogni risultato fornisce un punteggio di ricerca e i campi elencati inselect
. In una ricerca di somiglianza, la risposta includek
sempre i risultati ordinati in base al punteggio di somiglianza del valore.{ "@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." } ] }
Ricerca a vettore singolo con filtro
È possibile aggiungere filtri, ma i filtri vengono applicati al contenuto non di filtro nell'indice. In questo esempio, il filtro si applica al Tags
campo per filtrare tutti gli hotel che non forniscono wi-fi gratuito.
Incollare una richiesta POST per eseguire una query sull'indice di ricerca.
### 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 }, ] }
Rivedere la risposta. La query è la stessa dell'esempio precedente, ma include un filtro di esclusione post-elaborazione e restituisce solo i tre hotel che dispongono di Wi-Fi gratuito.
{ "@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" ] } ] }
Ricerca ibrida
La ricerca ibrida è costituita da query con parole chiave e query vettoriali in una singola richiesta di ricerca. Questo esempio esegue simultaneamente la query vettoriale e la ricerca full-text:
- Stringa di ricerca:
historic hotel walk to restaurants and shopping
- Stringa di query vettoriale (vettorializzata in una rappresentazione matematica):
classic lodging near running trails, eateries, retail
Incollare una richiesta POST per eseguire una query sull'indice di ricerca. Selezionare quindi Invia richiesta.
### 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 } ] }
Poiché si tratta di una query ibrida, i risultati vengono classificati in base al valore RRF (Reciprocal Rank Fusion). RRF valuta i punteggi di ricerca di più risultati di ricerca, accetta l'inverso e quindi unisce e ordina i risultati combinati. Viene restituito il
top
numero di risultati.Rivedere la risposta.
{ "@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." } ] }
Poiché RRF unisce i risultati, consente di esaminare gli input. I risultati seguenti provengono solo dalla query full-text. I primi due risultati sono Sublime Cliff Hotel e History Lion Resort. Il Sublime Cliff Hotel ha un punteggio di pertinenza BM25 più forte.
{ "@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" },
Nella query di solo vettore, che usa HNSW per trovare le corrispondenze, Sublime Cliff Hotel scende alla quarta posizione. Historic Lion, secondo nella ricerca full-text e terzo nella ricerca vettoriale, non riscontra lo stesso intervallo di fluttuazione, quindi appare come una corrispondenza principale in un set di risultati omogeneizzato.
"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" } ]
Ricerca ibrida semantica con un filtro
Ecco l'ultima query nella raccolta. Questa query ibrida con classificazione semantica viene filtrata per visualizzare solo gli hotel entro un raggio di 500 chilometri di Washington D.C. È possibile impostare su vectorFilterMode
null, che equivale all'impostazione predefinita (preFilter
per gli indici più recenti e postFilter
per quelli meno recenti).
Incollare una richiesta POST per eseguire una query sull'indice di ricerca. Selezionare quindi Invia richiesta.
### 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 } ] }
Rivedere la risposta. La risposta è costituita da tre hotel, filtrati in base alla posizione e in base a facet
StateProvince
e classificati in modo semantico per alzare di livello i risultati più vicini alla query della stringa di ricerca (historic hotel walk to restaurants and shopping
).Il Vecchio Carabelle Hotel ora si sposta nella parte superiore. Senza classificazione semantica, l'Hotel nordick è il numero uno. Con la classificazione semantica, i modelli di comprensione della macchina riconoscono che
historic
si applicano a "hotel, a pochi passi da ristoranti e negozi".{ "@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" } } ] }
Punti chiave:
- La ricerca vettoriale viene specificata tramite la
vectors.value
proprietà . La ricerca di parole chiave viene specificata tramite lasearch
proprietà . - In una ricerca ibrida è possibile integrare la ricerca vettoriale con la ricerca full-text sulle parole chiave. I filtri, il controllo ortografico e la classificazione semantica si applicano solo ai contenuti testuali e non ai vettori. In questa query finale non esiste una semantica
answer
perché il sistema non ha prodotto una query sufficientemente forte. - I risultati effettivi includono più dettagli, tra cui didascalia semantiche ed evidenziazioni. I risultati sono stati modificati per la leggibilità. Per ottenere la struttura completa della risposta, eseguire la richiesta nel client REST.
- La ricerca vettoriale viene specificata tramite la
Eseguire la pulizia
Quando si lavora nella propria sottoscrizione, al termine di un progetto è buona norma determinare se le risorse create sono ancora necessarie. Le risorse che rimangono in esecuzione hanno un costo. È possibile eliminare risorse singole oppure gruppi di risorse per eliminare l'intero set di risorse.
È possibile trovare e gestire le risorse nel portale usando il collegamento Tutte le risorse o Gruppi di risorse nel riquadro più a sinistra.
È anche possibile provare questo DELETE
comando:
### Delete an index
DELETE {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}
Passaggi successivi
Come passaggio successivo, è consigliabile esaminare il codice demo per Python, C# o JavaScript.