|
| 1 | +# Azure AI Search Semantic Ranking Quickstart - JavaScript |
| 2 | + |
| 3 | +This JavaScript sample demonstrates how to use semantic ranking in Azure AI Search to improve search relevance using machine reading comprehension. This is a JavaScript version of the [quickstart](https://learn.microsoft.com/azure/search/search-get-started-semantic). |
| 4 | + |
| 5 | +The sample has been factored into a modular structure, with separate files for different operations. |
| 6 | + |
| 7 | +## What is Semantic Ranking? |
| 8 | + |
| 9 | +Semantic ranking uses machine reading comprehension from Microsoft to rescore search results, promoting the most semantically relevant matches to the top of the list. Unlike traditional keyword-based BM25 scoring, semantic ranking understands context and meaning. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- An Azure account with an active subscription |
| 14 | +- An Azure AI Search service (Basic tier or higher) with semantic ranker enabled |
| 15 | +- Node.js 18+ and npm |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +1. **Clone or navigate to this directory** |
| 20 | + |
| 21 | +2. **Install dependencies** |
| 22 | + ```bash |
| 23 | + npm install |
| 24 | + ``` |
| 25 | + |
| 26 | +3. **Configure your search service** |
| 27 | + - Copy `sample.env` to `.env` |
| 28 | + - Update the values with your Azure AI Search service details: |
| 29 | + ``` |
| 30 | + SEARCH_ENDPOINT=https://your-service-name.search.windows.net |
| 31 | + INDEX_NAME=hotels-sample-index |
| 32 | + ``` |
| 33 | +
|
| 34 | +4. **Get your search service endpoint and API key** |
| 35 | + - Sign in to the [Azure portal](https://portal.azure.com/) |
| 36 | + - Find your search service |
| 37 | + - Copy the URL from the Overview page |
| 38 | + - Copy an admin key from the Keys page |
| 39 | +
|
| 40 | +## Run the Sample |
| 41 | +
|
| 42 | +### Getting Index Settings |
| 43 | +```bash |
| 44 | +npm run get-index-settings |
| 45 | +``` |
| 46 | + |
| 47 | +### Updating Index Settings for Semantic Search |
| 48 | +```bash |
| 49 | +npm run update-index-settings |
| 50 | +``` |
| 51 | + |
| 52 | +### Run Semantic Queries |
| 53 | +```bash |
| 54 | +npm run get-semantic-query |
| 55 | +``` |
| 56 | + |
| 57 | +### Get Captions with Results |
| 58 | +```bash |
| 59 | +npm run get-captions |
| 60 | +``` |
| 61 | + |
| 62 | +### Get Semantic Answers |
| 63 | +```bash |
| 64 | +npm run get-answers |
| 65 | +``` |
0 commit comments