demo-python/code/semantic-ranker/semantic-ranker.ipynb (1,576 lines of code) (raw):

{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Semantic Ranker Explained\n", "\n", "The following notebook describes how to:\n", "\n", "1. Create a sample index consisting of fictitious hotel data\n", "1. Configure semantic ranker on this index\n", "1. Compare hybrid query with and without semantic ranker\n", "1. Debug how semantic ranker interprets the top 50 results\n", "1. Rerank specific documents given a query\n", "\n", "## Prerequisites\n", "* An Azure subscription, with access to Azure OpenAI.\n", "* Azure AI Search basic or higher for this workload with [semantic ranker enabled](https://learn.microsoft.com/azure/search/semantic-how-to-enable-disable?tabs=enable-portal)\n", "* A deployment of the text-embedding-3-large model on Azure OpenAI.\n", "\n", "## Set up a Python virtual environment in Visual Studio Code\n", "* Open the Command Palette (Ctrl+Shift+P).\n", "* Search for Python: Create Environment.\n", "* Select Venv.\n", "* Select a Python interpreter. Choose 3.10 or later.\n", "\n", "It can take a minute to set up. If you run into problems, see Python environments in VS Code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Install packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "! pip install -r requirements.txt --quiet" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Load .env file (Copy .env-sample to .env and update accordingly)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from dotenv import load_dotenv\n", "from azure.identity import DefaultAzureCredential\n", "from azure.core.credentials import AzureKeyCredential\n", "import os\n", "\n", "load_dotenv(override=True) # take environment variables from .env.\n", "\n", "# Variables not used here do not need to be updated in your .env file\n", "endpoint = os.environ[\"AZURE_SEARCH_SERVICE_ENDPOINT\"]\n", "# You do not need a key if you are using keyless authentication\n", "# To learn more, please visit https://learn.microsoft.com/azure/search/search-security-rbac\n", "credential = AzureKeyCredential(os.getenv(\"AZURE_SEARCH_ADMIN_KEY\")) if len(os.getenv(\"AZURE_SEARCH_ADMIN_KEY\", \"\")) > 0 else DefaultAzureCredential()\n", "index_name = os.environ[\"AZURE_SEARCH_INDEX\"]\n", "aoai_endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n", "# Data is pre-vectorized using text-embedding-3-large\n", "model_name = \"text-embedding-3-large\"\n", "aoai_embedding_deployment = os.getenv(\"AZURE_OPENAI_DEPLOYMENT_NAME\", \"text-embedding-3-large\")\n", "# You do not need a key if you are using keyless authentication\n", "# To learn more, please visit https://learn.microsoft.com/azure/search/search-howto-managed-identities-data-sources and https://learn.microsoft.com/azure/developer/ai/keyless-connections\n", "aoai_key = os.getenv(\"AZURE_OPENAI_KEY\", None)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Create Search Index\n", "\n", "Creates a search index in Azure AI Search to host the sample documents. The index name is specified through an environment variable. If an index already exists with that name, either delete it from your search service or provide a unique name." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created sample index\n" ] } ], "source": [ "from azure.search.documents.indexes.models import (\n", " SearchIndex,\n", " SearchField,\n", " ComplexField,\n", " VectorSearch,\n", " HnswAlgorithmConfiguration,\n", " VectorSearchProfile,\n", " AzureOpenAIVectorizer,\n", " AzureOpenAIVectorizerParameters\n", ")\n", "from azure.search.documents.indexes import SearchIndexClient\n", "\n", "\n", "index = SearchIndex(\n", " name=index_name,\n", " fields=[\n", " SearchField(name=\"HotelId\", type=\"Edm.String\", key=True, hidden=False, filterable=True, sortable=False, facetable=False, searchable=True),\n", " SearchField(name=\"HotelName\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True),\n", " SearchField(name=\"Description\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True),\n", " SearchField(name=\"DescriptionEmbedding\", type=\"Collection(Edm.Single)\", hidden=False, searchable=True, vector_search_dimensions=3072, vector_search_profile_name=\"hnsw\"),\n", " SearchField(name=\"Description_fr\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True, analyzer_name=\"fr.microsoft\"),\n", " SearchField(name=\"Description_fr_Embedding\", type=\"Collection(Edm.Single)\", hidden=False, searchable=True, vector_search_dimensions=3072, vector_search_profile_name=\"hnsw\"),\n", " SearchField(name=\"Category\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"Tags\", type=\"Collection(Edm.String)\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"ParkingIncluded\", type=\"Edm.Boolean\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=False),\n", " SearchField(name=\"LastRenovationDate\", type=\"Edm.DateTimeOffset\", hidden=False, filterable=False, sortable=True, facetable=False, searchable=False),\n", " SearchField(name=\"Rating\", type=\"Edm.Double\", hidden=False, filterable=True, sortable=True, facetable=True, searchable=False),\n", " ComplexField(name=\"Address\", collection=False, fields=[\n", " SearchField(name=\"StreetAddress\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True),\n", " SearchField(name=\"City\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"StateProvince\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"PostalCode\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"Country\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True)\n", " ]),\n", " SearchField(name=\"Location\", type=\"Edm.GeographyPoint\", hidden=False, filterable=True, sortable=True, facetable=False, searchable=False),\n", " ComplexField(name=\"Rooms\", collection=True, fields=[\n", " SearchField(name=\"Description\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True),\n", " SearchField(name=\"Description_fr\", type=\"Edm.String\", hidden=False, filterable=False, sortable=False, facetable=False, searchable=True, analyzer_name=\"fr.microsoft\"),\n", " SearchField(name=\"Type\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"BaseRate\", type=\"Edm.Double\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=False),\n", " SearchField(name=\"BedOptions\", type=\"Edm.String\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " SearchField(name=\"SleepsCount\", type=\"Edm.Int64\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=False),\n", " SearchField(name=\"SmokingAllowed\", type=\"Edm.Boolean\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=False),\n", " SearchField(name=\"Tags\", type=\"Collection(Edm.String)\", hidden=False, filterable=True, sortable=False, facetable=True, searchable=True),\n", " ])\n", " ],\n", " vector_search=VectorSearch(\n", " profiles=[VectorSearchProfile(name=\"hnsw\", vectorizer_name=\"openai\", algorithm_configuration_name=\"hnsw\")],\n", " algorithms=[HnswAlgorithmConfiguration(name=\"hnsw\")],\n", " vectorizers=[\n", " AzureOpenAIVectorizer(\n", " vectorizer_name=\"openai\",\n", " parameters=AzureOpenAIVectorizerParameters(\n", " resource_url=aoai_endpoint,\n", " deployment_name=aoai_embedding_deployment,\n", " model_name=model_name,\n", " api_key=aoai_key,\n", " )\n", " )\n", " ]\n", " )\n", ")\n", "\n", "index_client = SearchIndexClient(endpoint, credential)\n", "result = index_client.create_or_update_index(index)\n", "print(\"Created sample index\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Upload sample documents\n", "\n", "Upload the sample hotel documents to the index\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Uploaded sample documents\n" ] } ], "source": [ "from azure.search.documents import SearchClient\n", "import json\n", "\n", "client = SearchClient(endpoint, index_name, credential)\n", "with open(\"../../../data/hotels.json\", encoding=\"utf-8\", mode=\"r\") as f:\n", " documents = json.load(f)\n", " client.upload_documents(documents)\n", " print(\"Uploaded sample documents\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. Setup Semantic Ranker Configuration\n", "\n", "Usage of semantic ranker requires a [configuration](https://learn.microsoft.com/en-us/azure/search/semantic-how-to-configure?tabs=portal). A configuration\n", "\n", "+ Lists the fields semantic ranker uses to rerank documents\n", "+ You can create many semantic configurations\n", "+ Semantic configurations may have a single title field, multiple content fields, and multiple keyword fields\n", "+ You can also set a default semantic configuration to be used on queries that have semantic ranker enabled\n", "+ Semantic configurations can always be set on individual queries" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Updated index with semantic configuration\n" ] } ], "source": [ "from azure.search.documents.indexes.models import SemanticSearch, SemanticConfiguration, SemanticField, SemanticPrioritizedFields\n", "\n", "index.semantic_search = SemanticSearch(\n", " default_configuration_name=\"semantic-config\",\n", " configurations=[\n", " SemanticConfiguration(\n", " name=\"semantic-config\",\n", " prioritized_fields=SemanticPrioritizedFields(\n", " content_fields=[SemanticField(field_name=\"Description\")]\n", " )\n", " ),\n", " SemanticConfiguration(\n", " name=\"semantic-config-with-title\",\n", " prioritized_fields=SemanticPrioritizedFields(\n", " title_field=SemanticField(field_name=\"HotelName\"),\n", " content_fields=[SemanticField(field_name=\"Description\")]\n", " )\n", " ),\n", " SemanticConfiguration(\n", " name=\"semantic-config-with-title-and-keywords\",\n", " prioritized_fields=SemanticPrioritizedFields(\n", " title_field=SemanticField(field_name=\"HotelName\"),\n", " content_fields=[SemanticField(field_name=\"Description\")],\n", " keywords_fields=[SemanticField(field_name=\"Tags\")]\n", " )\n", " ),\n", " SemanticConfiguration(\n", " name=\"semantic-config-with-title-and-keywords-extended\",\n", " prioritized_fields=SemanticPrioritizedFields(\n", " title_field=SemanticField(field_name=\"HotelName\"),\n", " content_fields=[SemanticField(field_name=\"Description\")],\n", " keywords_fields=[SemanticField(field_name=\"Tags\"), SemanticField(field_name=\"Address/City\"), SemanticField(field_name=\"Address/Country\")]\n", " )\n", " )\n", " ]\n", ")\n", "\n", "result = index_client.create_or_update_index(index)\n", "\n", "print(\"Updated index with semantic configuration\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6. Run Semantic Ranker Queries\n", "\n", "The following function allows you to run semantic ranker queries and compare results. In the remaining cells we'll see how to use the various semantic ranker options" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from azure.search.documents.models import VectorizableTextQuery\n", "from IPython.display import display, Markdown\n", "from typing import List,Optional\n", "\n", "import pandas as pd\n", "\n", "\n", "def run_query(query: str, semantic_config: Optional[str] = None, include_debug: bool = False, include_captions: bool = False, include_answers: bool = False, document_ids: Optional[List[str]] = None, should_display: Optional[bool] = True) -> pd.DataFrame:\n", " \"\"\"\n", " Executes a query and returns the results as a pandas DataFrame.\n", "\n", " Args:\n", " query (str): The search query to execute.\n", " semantic_config (Optional[str], optional): Configuration for semantic search. Defaults to None.\n", " include_debug (bool, optional): Whether to include debug information in the results. Defaults to False.\n", " include_captions (bool, optional): Whether to include captions in the results. Defaults to False.\n", " include_answers (bool, optional): Whether to include extracted answers in the results. Defaults to False.\n", " document_ids (Optional[List[str]], optional): A list of document IDs to filter results. Defaults to None.\n", "\n", " Displays the output results for comparison in the notebook\n", " \"\"\"\n", " \n", " document_id_filter = None\n", " if document_ids:\n", " document_id_filter = \" or \".join(f\"HotelId eq '{document_id}'\" for document_id in document_ids)\n", " results = client.search(\n", " search_text=query,\n", " vector_queries=[VectorizableTextQuery(text=query, k_nearest_neighbors=50, fields=\"DescriptionEmbedding\")],\n", " select=\"HotelId,HotelName,Description\",\n", " top=50,\n", " query_type=\"semantic\",\n", " filter=document_id_filter,\n", " semantic_configuration_name=semantic_config,\n", " debug=\"semantic\",\n", " query_answer=\"extractive|count-3\",\n", " query_caption=\"extractive|highlight-true\"\n", " )\n", " answers = [answer.as_dict() for answer in results.get_answers()]\n", " results_with_debug_info = []\n", " for result in list(results):\n", " debug_info = result[\"@search.document_debug_info\"].as_dict()\n", " captions = result[\"@search.captions\"]\n", " if len(captions) > 0:\n", " first_caption = captions[0].as_dict()\n", " result[\"Caption Highlights\"] = first_caption['highlights']\n", " results_with_debug_info.append({\n", " \"@search.score\": result[\"@search.score\"],\n", " \"@search.reranker_score\": result[\"@search.reranker_score\"],\n", " \"HotelId\": result[\"HotelId\"],\n", " \"HotelName\": result[\"HotelName\"],\n", " \"Description\": result[\"Description\"],\n", " \"Caption Highlights\": result[\"Caption Highlights\"],\n", " \"Title\": debug_info[\"semantic\"][\"reranker_input\"].get(\"title\"),\n", " \"Content\": debug_info[\"semantic\"][\"reranker_input\"].get(\"content\"),\n", " \"Keywords\": debug_info[\"semantic\"][\"reranker_input\"].get(\"keywords\")\n", " })\n", " \n", " columns = [\"@search.score\", \"@search.reranker_score\", \"HotelId\", \"HotelName\", \"Description\"]\n", " if include_captions:\n", " columns.extend([\"Caption Highlights\"])\n", " debug_columns = [\"Title\", \"Content\", \"Keywords\"]\n", " if include_debug:\n", " columns.extend(debug_columns)\n", " df = pd.DataFrame(results_with_debug_info, columns=columns)\n", " df_no_reranker = df.sort_values(by=\"@search.score\", ascending=False)\n", " if include_debug:\n", " df_no_reranker = df_no_reranker.drop(columns=debug_columns)\n", " df = pd.DataFrame({\n", " \"Reranked Index\": df.index.map({reranked_idx: i for i, reranked_idx in enumerate(df.index)}),\n", " \"Original Index\": df.index.map({original_idx: i for i, original_idx in enumerate(df_no_reranker.index)}),\n", " **df.to_dict('list')\n", " })\n", "\n", " def highlight_rerank_row_changes(row: pd.Series):\n", " reranked_index = row.iloc[0]\n", " original_index = row.iloc[1]\n", " first_column_style = ''\n", " if original_index > reranked_index:\n", " first_column_style = 'background-color: green'\n", " elif original_index < reranked_index:\n", " first_column_style = 'background-color: red'\n", "\n", " return [first_column_style, first_column_style] + ['' for i in range(len(row) - 2)]\n", " df_style = {\n", " 'max-width': '500px',\n", " 'text-align': 'left',\n", " 'white-space': 'normal',\n", " 'word-wrap': 'break-word'\n", " }\n", "\n", " df.columns.name = \"Reranked Index\"\n", " reranked_df_display = df.head(5)\n", " reranked_df_display = reranked_df_display.style.apply(highlight_rerank_row_changes, axis=1).set_properties(**df_style).hide(axis=\"index\")\n", " if should_display:\n", " display(Markdown(\"### Reranked Results\"))\n", " display(reranked_df_display)\n", "\n", " no_rerank_df = pd.DataFrame({\n", " \"Reranked Index\": df_no_reranker.index.map({reranked_idx: i for i, reranked_idx in enumerate(df.index)}),\n", " \"Original Index\": df_no_reranker.index.map({original_idx: i for i, original_idx in enumerate(df_no_reranker.index)}),\n", " **df_no_reranker.to_dict('list')\n", " })\n", " no_rerank_df = no_rerank_df.reset_index(drop=True)\n", " no_rerank_df.columns.name = \"Original Index\"\n", " no_rerank_df = no_rerank_df.head(5).style.apply(highlight_rerank_row_changes, axis=1).set_properties(**df_style).hide(axis=\"index\")\n", "\n", " if should_display:\n", " if not document_ids:\n", " display(Markdown(\"### Original Results\"))\n", " display(no_rerank_df)\n", "\n", " if include_answers:\n", " display(Markdown(\"### Answers\"))\n", " display(pd.DataFrame(answers, columns=[\"key\", \"score\", \"text\"]).style.set_properties(**df_style).hide(axis=\"index\"))\n", "\n", " return df\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6.1 Running a semantic query\n", "\n", "Semantic ranker takes results output from a plain text, vector, or hybrid search and re-ranks them\n", "\n", "+ Only the top 50 documents are reranked\n", "+ Reranking comparisons are made on the basis of how well the given document matches the query. The following criteria is used:\n", "\n", "| Score | Meaning |\n", "| -- | --\n", "| 4.0 | The document is highly relevant and answers the question completely, though the passage might contain extra text unrelated to the question. |\n", "| 3.0 | The document is relevant but lacks details that would make it complete. |\n", "| 2.0 | The document is somewhat relevant; it answers the question either partially or only addresses some aspects of the question. |\n", "| 1.0 | The document is related to the question, and it answers a small part of it. |\n", "| 0.0 | The document is irrelevant. |\n", "\n", "\n", "The `run_query` function in this example outputs 2 tables:\n", "\n", "1. Reranked results, showcasing what is returned by a hybrid search (text + vector merged using [Reciprocal Rank Fusion](https://learn.microsoft.com/azure/search/hybrid-search-ranking)) and then re-ranked using semantic ranker\n", " 1. Green rows represent documents that semantic ranker thinks are a better fit for the query than the original hybrid search\n", " 1. Red rows represent documents that semantic ranker thinks are a worse fit for the query than the original hybrid search\n", "1. Original results, showcasing what is returnd by the original hybrid search without semantic ranker input.\n", " 1. The same coloring scheme is used, but you can now see what the original results from the top 50 were." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Reranked Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_91861_row0_col0, #T_91861_row0_col1, #T_91861_row1_col0, #T_91861_row1_col1, #T_91861_row3_col0, #T_91861_row3_col1, #T_91861_row4_col0, #T_91861_row4_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_91861_row0_col2, #T_91861_row0_col3, #T_91861_row0_col4, #T_91861_row0_col5, #T_91861_row0_col6, #T_91861_row1_col2, #T_91861_row1_col3, #T_91861_row1_col4, #T_91861_row1_col5, #T_91861_row1_col6, #T_91861_row2_col2, #T_91861_row2_col3, #T_91861_row2_col4, #T_91861_row2_col5, #T_91861_row2_col6, #T_91861_row3_col2, #T_91861_row3_col3, #T_91861_row3_col4, #T_91861_row3_col5, #T_91861_row3_col6, #T_91861_row4_col2, #T_91861_row4_col3, #T_91861_row4_col4, #T_91861_row4_col5, #T_91861_row4_col6 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_91861_row2_col0, #T_91861_row2_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_91861\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_91861_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_91861_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_91861_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_91861_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_91861_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_91861_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_91861_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_91861_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_91861_row0_col1\" class=\"data row0 col1\" >2</td>\n", " <td id=\"T_91861_row0_col2\" class=\"data row0 col2\" >0.032002</td>\n", " <td id=\"T_91861_row0_col3\" class=\"data row0 col3\" >2.750766</td>\n", " <td id=\"T_91861_row0_col4\" class=\"data row0 col4\" >6</td>\n", " <td id=\"T_91861_row0_col5\" class=\"data row0 col5\" >King's Cellar Hotel</td>\n", " <td id=\"T_91861_row0_col6\" class=\"data row0 col6\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_91861_row1_col0\" class=\"data row1 col0\" >1</td>\n", " <td id=\"T_91861_row1_col1\" class=\"data row1 col1\" >4</td>\n", " <td id=\"T_91861_row1_col2\" class=\"data row1 col2\" >0.031498</td>\n", " <td id=\"T_91861_row1_col3\" class=\"data row1 col3\" >2.648679</td>\n", " <td id=\"T_91861_row1_col4\" class=\"data row1 col4\" >16</td>\n", " <td id=\"T_91861_row1_col5\" class=\"data row1 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_91861_row1_col6\" class=\"data row1 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_91861_row2_col0\" class=\"data row2 col0\" >2</td>\n", " <td id=\"T_91861_row2_col1\" class=\"data row2 col1\" >0</td>\n", " <td id=\"T_91861_row2_col2\" class=\"data row2 col2\" >0.032796</td>\n", " <td id=\"T_91861_row2_col3\" class=\"data row2 col3\" >2.589837</td>\n", " <td id=\"T_91861_row2_col4\" class=\"data row2 col4\" >36</td>\n", " <td id=\"T_91861_row2_col5\" class=\"data row2 col5\" >Hotel on the Harbor</td>\n", " <td id=\"T_91861_row2_col6\" class=\"data row2 col6\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_91861_row3_col0\" class=\"data row3 col0\" >3</td>\n", " <td id=\"T_91861_row3_col1\" class=\"data row3 col1\" >11</td>\n", " <td id=\"T_91861_row3_col2\" class=\"data row3 col2\" >0.027106</td>\n", " <td id=\"T_91861_row3_col3\" class=\"data row3 col3\" >2.479951</td>\n", " <td id=\"T_91861_row3_col4\" class=\"data row3 col4\" >28</td>\n", " <td id=\"T_91861_row3_col5\" class=\"data row3 col5\" >City Center Summer Wind Resort</td>\n", " <td id=\"T_91861_row3_col6\" class=\"data row3 col6\" >Eco-friendly from our gardens to table, with a rooftop serenity pool and outdoor seating to take in the sunset. Just steps away from the Convention Center. Located in the heart of downtown with modern rooms with stunning city views, 24-7 dining options, free WiFi and easy valet parking.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_91861_row4_col0\" class=\"data row4 col0\" >4</td>\n", " <td id=\"T_91861_row4_col1\" class=\"data row4 col1\" >8</td>\n", " <td id=\"T_91861_row4_col2\" class=\"data row4 col2\" >0.029052</td>\n", " <td id=\"T_91861_row4_col3\" class=\"data row4 col3\" >2.462759</td>\n", " <td id=\"T_91861_row4_col4\" class=\"data row4 col4\" >49</td>\n", " <td id=\"T_91861_row4_col5\" class=\"data row4 col5\" >Swirling Currents Hotel</td>\n", " <td id=\"T_91861_row4_col6\" class=\"data row4 col6\" >Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center. Each room comes equipped with a microwave, a coffee maker and a minifridge. In-room entertainment includes complimentary W-Fi and flat-screen TVs. </td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260df098a90>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "### Original Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_c0940_row0_col0, #T_c0940_row0_col1, #T_c0940_row1_col0, #T_c0940_row1_col1, #T_c0940_row3_col0, #T_c0940_row3_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_c0940_row0_col2, #T_c0940_row0_col3, #T_c0940_row0_col4, #T_c0940_row0_col5, #T_c0940_row0_col6, #T_c0940_row1_col2, #T_c0940_row1_col3, #T_c0940_row1_col4, #T_c0940_row1_col5, #T_c0940_row1_col6, #T_c0940_row2_col2, #T_c0940_row2_col3, #T_c0940_row2_col4, #T_c0940_row2_col5, #T_c0940_row2_col6, #T_c0940_row3_col2, #T_c0940_row3_col3, #T_c0940_row3_col4, #T_c0940_row3_col5, #T_c0940_row3_col6, #T_c0940_row4_col2, #T_c0940_row4_col3, #T_c0940_row4_col4, #T_c0940_row4_col5, #T_c0940_row4_col6 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_c0940_row2_col0, #T_c0940_row2_col1, #T_c0940_row4_col0, #T_c0940_row4_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_c0940\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_c0940_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_c0940_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_c0940_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_c0940_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_c0940_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_c0940_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_c0940_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_c0940_row0_col0\" class=\"data row0 col0\" >2</td>\n", " <td id=\"T_c0940_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_c0940_row0_col2\" class=\"data row0 col2\" >0.032796</td>\n", " <td id=\"T_c0940_row0_col3\" class=\"data row0 col3\" >2.589837</td>\n", " <td id=\"T_c0940_row0_col4\" class=\"data row0 col4\" >36</td>\n", " <td id=\"T_c0940_row0_col5\" class=\"data row0 col5\" >Hotel on the Harbor</td>\n", " <td id=\"T_c0940_row0_col6\" class=\"data row0 col6\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c0940_row1_col0\" class=\"data row1 col0\" >12</td>\n", " <td id=\"T_c0940_row1_col1\" class=\"data row1 col1\" >1</td>\n", " <td id=\"T_c0940_row1_col2\" class=\"data row1 col2\" >0.032292</td>\n", " <td id=\"T_c0940_row1_col3\" class=\"data row1 col3\" >2.316807</td>\n", " <td id=\"T_c0940_row1_col4\" class=\"data row1 col4\" >1</td>\n", " <td id=\"T_c0940_row1_col5\" class=\"data row1 col5\" >Stay-Kay City Hotel</td>\n", " <td id=\"T_c0940_row1_col6\" class=\"data row1 col6\" >This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c0940_row2_col0\" class=\"data row2 col0\" >0</td>\n", " <td id=\"T_c0940_row2_col1\" class=\"data row2 col1\" >2</td>\n", " <td id=\"T_c0940_row2_col2\" class=\"data row2 col2\" >0.032002</td>\n", " <td id=\"T_c0940_row2_col3\" class=\"data row2 col3\" >2.750766</td>\n", " <td id=\"T_c0940_row2_col4\" class=\"data row2 col4\" >6</td>\n", " <td id=\"T_c0940_row2_col5\" class=\"data row2 col5\" >King's Cellar Hotel</td>\n", " <td id=\"T_c0940_row2_col6\" class=\"data row2 col6\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c0940_row3_col0\" class=\"data row3 col0\" >21</td>\n", " <td id=\"T_c0940_row3_col1\" class=\"data row3 col1\" >3</td>\n", " <td id=\"T_c0940_row3_col2\" class=\"data row3 col2\" >0.031545</td>\n", " <td id=\"T_c0940_row3_col3\" class=\"data row3 col3\" >2.110063</td>\n", " <td id=\"T_c0940_row3_col4\" class=\"data row3 col4\" >17</td>\n", " <td id=\"T_c0940_row3_col5\" class=\"data row3 col5\" >City Skyline Antiquity Hotel</td>\n", " <td id=\"T_c0940_row3_col6\" class=\"data row3 col6\" >In vogue since 1888, the Antiquity Hotel takes you back to bygone era. From the crystal chandeliers that adorn the Green Room, to the arched ceilings of the Grand Hall, the elegance of old New York beckons. Elevate Your Experience. Upgrade to a premiere city skyline view for less, where old world charm combines with dramatic views of the city, local cathedral and midtown.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c0940_row4_col0\" class=\"data row4 col0\" >1</td>\n", " <td id=\"T_c0940_row4_col1\" class=\"data row4 col1\" >4</td>\n", " <td id=\"T_c0940_row4_col2\" class=\"data row4 col2\" >0.031498</td>\n", " <td id=\"T_c0940_row4_col3\" class=\"data row4 col3\" >2.648679</td>\n", " <td id=\"T_c0940_row4_col4\" class=\"data row4 col4\" >16</td>\n", " <td id=\"T_c0940_row4_col5\" class=\"data row4 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_c0940_row4_col6\" class=\"data row4 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff902b50>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = run_query(\"new york hotel with pool or gym\", semantic_config=\"semantic-config-with-title-and-keywords\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6.2 - Debugging Semantic Ranker\n", "\n", "Semantic ranker has a limited amount of content from every document that it can accept. This content are split across the title, content, and keywords fields defined in the semantic configuration. When dealing with unexpected results from semantic ranker, it can be useful to see the actual input. Adding `include_debug=True` to the `run_query` function adds the `Title`, `Content`, and `Keywords` columns to the output tables, allowing examination of what input was actually sent to semantic ranker." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Reranked Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_c79c1_row0_col0, #T_c79c1_row0_col1, #T_c79c1_row1_col0, #T_c79c1_row1_col1, #T_c79c1_row3_col0, #T_c79c1_row3_col1, #T_c79c1_row4_col0, #T_c79c1_row4_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_c79c1_row0_col2, #T_c79c1_row0_col3, #T_c79c1_row0_col4, #T_c79c1_row0_col5, #T_c79c1_row0_col6, #T_c79c1_row0_col7, #T_c79c1_row0_col8, #T_c79c1_row0_col9, #T_c79c1_row1_col2, #T_c79c1_row1_col3, #T_c79c1_row1_col4, #T_c79c1_row1_col5, #T_c79c1_row1_col6, #T_c79c1_row1_col7, #T_c79c1_row1_col8, #T_c79c1_row1_col9, #T_c79c1_row2_col2, #T_c79c1_row2_col3, #T_c79c1_row2_col4, #T_c79c1_row2_col5, #T_c79c1_row2_col6, #T_c79c1_row2_col7, #T_c79c1_row2_col8, #T_c79c1_row2_col9, #T_c79c1_row3_col2, #T_c79c1_row3_col3, #T_c79c1_row3_col4, #T_c79c1_row3_col5, #T_c79c1_row3_col6, #T_c79c1_row3_col7, #T_c79c1_row3_col8, #T_c79c1_row3_col9, #T_c79c1_row4_col2, #T_c79c1_row4_col3, #T_c79c1_row4_col4, #T_c79c1_row4_col5, #T_c79c1_row4_col6, #T_c79c1_row4_col7, #T_c79c1_row4_col8, #T_c79c1_row4_col9 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_c79c1_row2_col0, #T_c79c1_row2_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_c79c1\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_c79c1_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_c79c1_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_c79c1_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_c79c1_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_c79c1_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_c79c1_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_c79c1_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " <th id=\"T_c79c1_level0_col7\" class=\"col_heading level0 col7\" >Title</th>\n", " <th id=\"T_c79c1_level0_col8\" class=\"col_heading level0 col8\" >Content</th>\n", " <th id=\"T_c79c1_level0_col9\" class=\"col_heading level0 col9\" >Keywords</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_c79c1_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_c79c1_row0_col1\" class=\"data row0 col1\" >2</td>\n", " <td id=\"T_c79c1_row0_col2\" class=\"data row0 col2\" >0.032002</td>\n", " <td id=\"T_c79c1_row0_col3\" class=\"data row0 col3\" >2.750766</td>\n", " <td id=\"T_c79c1_row0_col4\" class=\"data row0 col4\" >6</td>\n", " <td id=\"T_c79c1_row0_col5\" class=\"data row0 col5\" >King's Cellar Hotel</td>\n", " <td id=\"T_c79c1_row0_col6\" class=\"data row0 col6\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " <td id=\"T_c79c1_row0_col7\" class=\"data row0 col7\" >King's Cellar Hotel</td>\n", " <td id=\"T_c79c1_row0_col8\" class=\"data row0 col8\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " <td id=\"T_c79c1_row0_col9\" class=\"data row0 col9\" >free wifi\r\n", "pool\r\n", "bar</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c79c1_row1_col0\" class=\"data row1 col0\" >1</td>\n", " <td id=\"T_c79c1_row1_col1\" class=\"data row1 col1\" >4</td>\n", " <td id=\"T_c79c1_row1_col2\" class=\"data row1 col2\" >0.031498</td>\n", " <td id=\"T_c79c1_row1_col3\" class=\"data row1 col3\" >2.648679</td>\n", " <td id=\"T_c79c1_row1_col4\" class=\"data row1 col4\" >16</td>\n", " <td id=\"T_c79c1_row1_col5\" class=\"data row1 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_c79c1_row1_col6\" class=\"data row1 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " <td id=\"T_c79c1_row1_col7\" class=\"data row1 col7\" >Double Sanctuary Resort</td>\n", " <td id=\"T_c79c1_row1_col8\" class=\"data row1 col8\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " <td id=\"T_c79c1_row1_col9\" class=\"data row1 col9\" >view\r\n", "pool\r\n", "restaurant\r\n", "bar\r\n", "continental breakfast</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c79c1_row2_col0\" class=\"data row2 col0\" >2</td>\n", " <td id=\"T_c79c1_row2_col1\" class=\"data row2 col1\" >0</td>\n", " <td id=\"T_c79c1_row2_col2\" class=\"data row2 col2\" >0.032796</td>\n", " <td id=\"T_c79c1_row2_col3\" class=\"data row2 col3\" >2.589837</td>\n", " <td id=\"T_c79c1_row2_col4\" class=\"data row2 col4\" >36</td>\n", " <td id=\"T_c79c1_row2_col5\" class=\"data row2 col5\" >Hotel on the Harbor</td>\n", " <td id=\"T_c79c1_row2_col6\" class=\"data row2 col6\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " <td id=\"T_c79c1_row2_col7\" class=\"data row2 col7\" >Hotel on the Harbor</td>\n", " <td id=\"T_c79c1_row2_col8\" class=\"data row2 col8\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " <td id=\"T_c79c1_row2_col9\" class=\"data row2 col9\" >bar\r\n", "pool\r\n", "24-hour front desk service</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c79c1_row3_col0\" class=\"data row3 col0\" >3</td>\n", " <td id=\"T_c79c1_row3_col1\" class=\"data row3 col1\" >11</td>\n", " <td id=\"T_c79c1_row3_col2\" class=\"data row3 col2\" >0.027106</td>\n", " <td id=\"T_c79c1_row3_col3\" class=\"data row3 col3\" >2.479951</td>\n", " <td id=\"T_c79c1_row3_col4\" class=\"data row3 col4\" >28</td>\n", " <td id=\"T_c79c1_row3_col5\" class=\"data row3 col5\" >City Center Summer Wind Resort</td>\n", " <td id=\"T_c79c1_row3_col6\" class=\"data row3 col6\" >Eco-friendly from our gardens to table, with a rooftop serenity pool and outdoor seating to take in the sunset. Just steps away from the Convention Center. Located in the heart of downtown with modern rooms with stunning city views, 24-7 dining options, free WiFi and easy valet parking.</td>\n", " <td id=\"T_c79c1_row3_col7\" class=\"data row3 col7\" >City Center Summer Wind Resort</td>\n", " <td id=\"T_c79c1_row3_col8\" class=\"data row3 col8\" >Eco-friendly from our gardens to table, with a rooftop serenity pool and outdoor seating to take in the sunset. Just steps away from the Convention Center. Located in the heart of downtown with modern rooms with stunning city views, 24-7 dining options, free WiFi and easy valet parking.</td>\n", " <td id=\"T_c79c1_row3_col9\" class=\"data row3 col9\" >restaurant\r\n", "view\r\n", "concierge</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_c79c1_row4_col0\" class=\"data row4 col0\" >4</td>\n", " <td id=\"T_c79c1_row4_col1\" class=\"data row4 col1\" >8</td>\n", " <td id=\"T_c79c1_row4_col2\" class=\"data row4 col2\" >0.029052</td>\n", " <td id=\"T_c79c1_row4_col3\" class=\"data row4 col3\" >2.462759</td>\n", " <td id=\"T_c79c1_row4_col4\" class=\"data row4 col4\" >49</td>\n", " <td id=\"T_c79c1_row4_col5\" class=\"data row4 col5\" >Swirling Currents Hotel</td>\n", " <td id=\"T_c79c1_row4_col6\" class=\"data row4 col6\" >Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center. Each room comes equipped with a microwave, a coffee maker and a minifridge. In-room entertainment includes complimentary W-Fi and flat-screen TVs. </td>\n", " <td id=\"T_c79c1_row4_col7\" class=\"data row4 col7\" >Swirling Currents Hotel</td>\n", " <td id=\"T_c79c1_row4_col8\" class=\"data row4 col8\" >Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center. Each room comes equipped with a microwave, a coffee maker and a minifridge. In-room entertainment includes complimentary W-Fi and flat-screen TVs. </td>\n", " <td id=\"T_c79c1_row4_col9\" class=\"data row4 col9\" >air conditioning\r\n", "laundry service\r\n", "24-hour front desk service</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff89c610>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "### Original Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_0e032_row0_col0, #T_0e032_row0_col1, #T_0e032_row1_col0, #T_0e032_row1_col1, #T_0e032_row3_col0, #T_0e032_row3_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_0e032_row0_col2, #T_0e032_row0_col3, #T_0e032_row0_col4, #T_0e032_row0_col5, #T_0e032_row0_col6, #T_0e032_row1_col2, #T_0e032_row1_col3, #T_0e032_row1_col4, #T_0e032_row1_col5, #T_0e032_row1_col6, #T_0e032_row2_col2, #T_0e032_row2_col3, #T_0e032_row2_col4, #T_0e032_row2_col5, #T_0e032_row2_col6, #T_0e032_row3_col2, #T_0e032_row3_col3, #T_0e032_row3_col4, #T_0e032_row3_col5, #T_0e032_row3_col6, #T_0e032_row4_col2, #T_0e032_row4_col3, #T_0e032_row4_col4, #T_0e032_row4_col5, #T_0e032_row4_col6 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_0e032_row2_col0, #T_0e032_row2_col1, #T_0e032_row4_col0, #T_0e032_row4_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_0e032\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_0e032_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_0e032_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_0e032_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_0e032_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_0e032_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_0e032_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_0e032_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_0e032_row0_col0\" class=\"data row0 col0\" >2</td>\n", " <td id=\"T_0e032_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_0e032_row0_col2\" class=\"data row0 col2\" >0.032796</td>\n", " <td id=\"T_0e032_row0_col3\" class=\"data row0 col3\" >2.589837</td>\n", " <td id=\"T_0e032_row0_col4\" class=\"data row0 col4\" >36</td>\n", " <td id=\"T_0e032_row0_col5\" class=\"data row0 col5\" >Hotel on the Harbor</td>\n", " <td id=\"T_0e032_row0_col6\" class=\"data row0 col6\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0e032_row1_col0\" class=\"data row1 col0\" >12</td>\n", " <td id=\"T_0e032_row1_col1\" class=\"data row1 col1\" >1</td>\n", " <td id=\"T_0e032_row1_col2\" class=\"data row1 col2\" >0.032292</td>\n", " <td id=\"T_0e032_row1_col3\" class=\"data row1 col3\" >2.316807</td>\n", " <td id=\"T_0e032_row1_col4\" class=\"data row1 col4\" >1</td>\n", " <td id=\"T_0e032_row1_col5\" class=\"data row1 col5\" >Stay-Kay City Hotel</td>\n", " <td id=\"T_0e032_row1_col6\" class=\"data row1 col6\" >This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0e032_row2_col0\" class=\"data row2 col0\" >0</td>\n", " <td id=\"T_0e032_row2_col1\" class=\"data row2 col1\" >2</td>\n", " <td id=\"T_0e032_row2_col2\" class=\"data row2 col2\" >0.032002</td>\n", " <td id=\"T_0e032_row2_col3\" class=\"data row2 col3\" >2.750766</td>\n", " <td id=\"T_0e032_row2_col4\" class=\"data row2 col4\" >6</td>\n", " <td id=\"T_0e032_row2_col5\" class=\"data row2 col5\" >King's Cellar Hotel</td>\n", " <td id=\"T_0e032_row2_col6\" class=\"data row2 col6\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0e032_row3_col0\" class=\"data row3 col0\" >21</td>\n", " <td id=\"T_0e032_row3_col1\" class=\"data row3 col1\" >3</td>\n", " <td id=\"T_0e032_row3_col2\" class=\"data row3 col2\" >0.031545</td>\n", " <td id=\"T_0e032_row3_col3\" class=\"data row3 col3\" >2.110063</td>\n", " <td id=\"T_0e032_row3_col4\" class=\"data row3 col4\" >17</td>\n", " <td id=\"T_0e032_row3_col5\" class=\"data row3 col5\" >City Skyline Antiquity Hotel</td>\n", " <td id=\"T_0e032_row3_col6\" class=\"data row3 col6\" >In vogue since 1888, the Antiquity Hotel takes you back to bygone era. From the crystal chandeliers that adorn the Green Room, to the arched ceilings of the Grand Hall, the elegance of old New York beckons. Elevate Your Experience. Upgrade to a premiere city skyline view for less, where old world charm combines with dramatic views of the city, local cathedral and midtown.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0e032_row4_col0\" class=\"data row4 col0\" >1</td>\n", " <td id=\"T_0e032_row4_col1\" class=\"data row4 col1\" >4</td>\n", " <td id=\"T_0e032_row4_col2\" class=\"data row4 col2\" >0.031498</td>\n", " <td id=\"T_0e032_row4_col3\" class=\"data row4 col3\" >2.648679</td>\n", " <td id=\"T_0e032_row4_col4\" class=\"data row4 col4\" >16</td>\n", " <td id=\"T_0e032_row4_col5\" class=\"data row4 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_0e032_row4_col6\" class=\"data row4 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff897a10>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = run_query(\"new york hotel with pool or gym\", semantic_config=\"semantic-config-with-title-and-keywords\", include_debug=True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6.3 - Semantic Answers And Captions\n", "\n", "Semantic ranker also supports automatically returning [answers and captions](https://learn.microsoft.com/azure/search/semantic-answers) from documents returned for a query.\n", "\n", "1. Semantic ranker attempts to interpret the query as a natural language question and find the best answer from the top 50 documents that fits it. Unlike [Retrieval Augmented Generation (RAG)](https://learn.microsoft.com/azure/search/retrieval-augmented-generation-overview), this answer is extractive only\n", "1. Semantic ranker attempts to extract a representative caption, or snippet of text, from the document that is relevant to the query. This caption also has highlights that can be displayed in a search UI to help guide users to the most relevant results.\n", "\n", "Adding `include_captions=True`, `include_answers=True` to the query adds a `Caption Highlights` column to the `Reranked Results` table and an additonal `Answers` table to review the semantic answers" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Reranked Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_55093_row0_col0, #T_55093_row0_col1, #T_55093_row0_col2, #T_55093_row0_col3, #T_55093_row0_col4, #T_55093_row0_col5, #T_55093_row0_col6, #T_55093_row0_col7, #T_55093_row1_col2, #T_55093_row1_col3, #T_55093_row1_col4, #T_55093_row1_col5, #T_55093_row1_col6, #T_55093_row1_col7, #T_55093_row2_col2, #T_55093_row2_col3, #T_55093_row2_col4, #T_55093_row2_col5, #T_55093_row2_col6, #T_55093_row2_col7, #T_55093_row3_col0, #T_55093_row3_col1, #T_55093_row3_col2, #T_55093_row3_col3, #T_55093_row3_col4, #T_55093_row3_col5, #T_55093_row3_col6, #T_55093_row3_col7, #T_55093_row4_col2, #T_55093_row4_col3, #T_55093_row4_col4, #T_55093_row4_col5, #T_55093_row4_col6, #T_55093_row4_col7 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_55093_row1_col0, #T_55093_row1_col1, #T_55093_row2_col0, #T_55093_row2_col1, #T_55093_row4_col0, #T_55093_row4_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_55093\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_55093_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_55093_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_55093_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_55093_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_55093_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_55093_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_55093_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " <th id=\"T_55093_level0_col7\" class=\"col_heading level0 col7\" >Caption Highlights</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_55093_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_55093_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_55093_row0_col2\" class=\"data row0 col2\" >0.033333</td>\n", " <td id=\"T_55093_row0_col3\" class=\"data row0 col3\" >2.694051</td>\n", " <td id=\"T_55093_row0_col4\" class=\"data row0 col4\" >16</td>\n", " <td id=\"T_55093_row0_col5\" class=\"data row0 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_55093_row0_col6\" class=\"data row0 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " <td id=\"T_55093_row0_col7\" class=\"data row0 col7\" ><em>5 star Luxury Hotel </em>-<em> Biggest </em>Rooms in the city.<em> #1 </em>Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_55093_row1_col0\" class=\"data row1 col0\" >1</td>\n", " <td id=\"T_55093_row1_col1\" class=\"data row1 col1\" >2</td>\n", " <td id=\"T_55093_row1_col2\" class=\"data row1 col2\" >0.028898</td>\n", " <td id=\"T_55093_row1_col3\" class=\"data row1 col3\" >2.531881</td>\n", " <td id=\"T_55093_row1_col4\" class=\"data row1 col4\" >50</td>\n", " <td id=\"T_55093_row1_col5\" class=\"data row1 col5\" >Head Wind Resort</td>\n", " <td id=\"T_55093_row1_col6\" class=\"data row1 col6\" >The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the hotel.</td>\n", " <td id=\"T_55093_row1_col7\" class=\"data row1 col7\" ><em>The best of old town hospitality combined </em>with<em> views of the river and cool breezes off the prairie.</em> Our<em> penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the </em>hotel.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_55093_row2_col0\" class=\"data row2 col0\" >2</td>\n", " <td id=\"T_55093_row2_col1\" class=\"data row2 col1\" >12</td>\n", " <td id=\"T_55093_row2_col2\" class=\"data row2 col2\" >0.027584</td>\n", " <td id=\"T_55093_row2_col3\" class=\"data row2 col3\" >2.459392</td>\n", " <td id=\"T_55093_row2_col4\" class=\"data row2 col4\" >36</td>\n", " <td id=\"T_55093_row2_col5\" class=\"data row2 col5\" >Hotel on the Harbor</td>\n", " <td id=\"T_55093_row2_col6\" class=\"data row2 col6\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant</td>\n", " <td id=\"T_55093_row2_col7\" class=\"data row2 col7\" ><em>Stunning Downtown Hotel with indoor Pool.</em> Ideally located close to theatres, museums and the convention center. <em>Indoor Pool and Sauna and fitness centre.</em> Popular Bar & Restaurant.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_55093_row3_col0\" class=\"data row3 col0\" >3</td>\n", " <td id=\"T_55093_row3_col1\" class=\"data row3 col1\" >3</td>\n", " <td id=\"T_55093_row3_col2\" class=\"data row3 col2\" >0.028298</td>\n", " <td id=\"T_55093_row3_col3\" class=\"data row3 col3\" >2.446100</td>\n", " <td id=\"T_55093_row3_col4\" class=\"data row3 col4\" >18</td>\n", " <td id=\"T_55093_row3_col5\" class=\"data row3 col5\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_55093_row3_col6\" class=\"data row3 col6\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_55093_row3_col7\" class=\"data row3 col7\" ><em>New Luxury Hotel </em>for the vacation of a<em> lifetime.</em> <em>Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</em></td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_55093_row4_col0\" class=\"data row4 col0\" >4</td>\n", " <td id=\"T_55093_row4_col1\" class=\"data row4 col1\" >25</td>\n", " <td id=\"T_55093_row4_col2\" class=\"data row4 col2\" >0.023037</td>\n", " <td id=\"T_55093_row4_col3\" class=\"data row4 col3\" >2.417387</td>\n", " <td id=\"T_55093_row4_col4\" class=\"data row4 col4\" >15</td>\n", " <td id=\"T_55093_row4_col5\" class=\"data row4 col5\" >By the Market Hotel</td>\n", " <td id=\"T_55093_row4_col6\" class=\"data row4 col6\" >Book now and Save up to 30%. Central location. Walking distance from the Empire State Building & Times Square, in the Chelsea neighborhood. Brand new rooms. Impeccable service.</td>\n", " <td id=\"T_55093_row4_col7\" class=\"data row4 col7\" ><em>Book now and Save up to 30%.</em> Central location. <em>Walking distance from the Empire State Building & Times Square, in the Chelsea neighborhood.</em> <em>Brand new rooms. Impeccable service.</em></td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260df09cb10>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "### Original Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_4ab75_row0_col0, #T_4ab75_row0_col1, #T_4ab75_row0_col2, #T_4ab75_row0_col3, #T_4ab75_row0_col4, #T_4ab75_row0_col5, #T_4ab75_row0_col6, #T_4ab75_row0_col7, #T_4ab75_row1_col2, #T_4ab75_row1_col3, #T_4ab75_row1_col4, #T_4ab75_row1_col5, #T_4ab75_row1_col6, #T_4ab75_row1_col7, #T_4ab75_row2_col2, #T_4ab75_row2_col3, #T_4ab75_row2_col4, #T_4ab75_row2_col5, #T_4ab75_row2_col6, #T_4ab75_row2_col7, #T_4ab75_row3_col0, #T_4ab75_row3_col1, #T_4ab75_row3_col2, #T_4ab75_row3_col3, #T_4ab75_row3_col4, #T_4ab75_row3_col5, #T_4ab75_row3_col6, #T_4ab75_row3_col7, #T_4ab75_row4_col2, #T_4ab75_row4_col3, #T_4ab75_row4_col4, #T_4ab75_row4_col5, #T_4ab75_row4_col6, #T_4ab75_row4_col7 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_4ab75_row1_col0, #T_4ab75_row1_col1, #T_4ab75_row4_col0, #T_4ab75_row4_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_4ab75_row2_col0, #T_4ab75_row2_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_4ab75\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_4ab75_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_4ab75_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_4ab75_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_4ab75_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_4ab75_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_4ab75_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_4ab75_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " <th id=\"T_4ab75_level0_col7\" class=\"col_heading level0 col7\" >Caption Highlights</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_4ab75_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_4ab75_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_4ab75_row0_col2\" class=\"data row0 col2\" >0.033333</td>\n", " <td id=\"T_4ab75_row0_col3\" class=\"data row0 col3\" >2.694051</td>\n", " <td id=\"T_4ab75_row0_col4\" class=\"data row0 col4\" >16</td>\n", " <td id=\"T_4ab75_row0_col5\" class=\"data row0 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_4ab75_row0_col6\" class=\"data row0 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " <td id=\"T_4ab75_row0_col7\" class=\"data row0 col7\" ><em>5 star Luxury Hotel </em>-<em> Biggest </em>Rooms in the city.<em> #1 </em>Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_4ab75_row1_col0\" class=\"data row1 col0\" >5</td>\n", " <td id=\"T_4ab75_row1_col1\" class=\"data row1 col1\" >1</td>\n", " <td id=\"T_4ab75_row1_col2\" class=\"data row1 col2\" >0.032522</td>\n", " <td id=\"T_4ab75_row1_col3\" class=\"data row1 col3\" >2.415261</td>\n", " <td id=\"T_4ab75_row1_col4\" class=\"data row1 col4\" >13</td>\n", " <td id=\"T_4ab75_row1_col5\" class=\"data row1 col5\" >Luxury Lion Resort</td>\n", " <td id=\"T_4ab75_row1_col6\" class=\"data row1 col6\" >Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium and transportation hubs, we feature the best in convenience and comfort.</td>\n", " <td id=\"T_4ab75_row1_col7\" class=\"data row1 col7\" >Unmatched Luxury. Visit our<em> downtown hotel </em>to indulge in<em> luxury accommodations.</em> Moments from the stadium and transportation hubs, we feature the best in convenience and comfort.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_4ab75_row2_col0\" class=\"data row2 col0\" >1</td>\n", " <td id=\"T_4ab75_row2_col1\" class=\"data row2 col1\" >2</td>\n", " <td id=\"T_4ab75_row2_col2\" class=\"data row2 col2\" >0.028898</td>\n", " <td id=\"T_4ab75_row2_col3\" class=\"data row2 col3\" >2.531881</td>\n", " <td id=\"T_4ab75_row2_col4\" class=\"data row2 col4\" >50</td>\n", " <td id=\"T_4ab75_row2_col5\" class=\"data row2 col5\" >Head Wind Resort</td>\n", " <td id=\"T_4ab75_row2_col6\" class=\"data row2 col6\" >The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the hotel.</td>\n", " <td id=\"T_4ab75_row2_col7\" class=\"data row2 col7\" ><em>The best of old town hospitality combined </em>with<em> views of the river and cool breezes off the prairie.</em> Our<em> penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the </em>hotel.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_4ab75_row3_col0\" class=\"data row3 col0\" >3</td>\n", " <td id=\"T_4ab75_row3_col1\" class=\"data row3 col1\" >3</td>\n", " <td id=\"T_4ab75_row3_col2\" class=\"data row3 col2\" >0.028298</td>\n", " <td id=\"T_4ab75_row3_col3\" class=\"data row3 col3\" >2.446100</td>\n", " <td id=\"T_4ab75_row3_col4\" class=\"data row3 col4\" >18</td>\n", " <td id=\"T_4ab75_row3_col5\" class=\"data row3 col5\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_4ab75_row3_col6\" class=\"data row3 col6\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_4ab75_row3_col7\" class=\"data row3 col7\" ><em>New Luxury Hotel </em>for the vacation of a<em> lifetime.</em> <em>Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</em></td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_4ab75_row4_col0\" class=\"data row4 col0\" >30</td>\n", " <td id=\"T_4ab75_row4_col1\" class=\"data row4 col1\" >4</td>\n", " <td id=\"T_4ab75_row4_col2\" class=\"data row4 col2\" >0.028283</td>\n", " <td id=\"T_4ab75_row4_col3\" class=\"data row4 col3\" >2.165249</td>\n", " <td id=\"T_4ab75_row4_col4\" class=\"data row4 col4\" >35</td>\n", " <td id=\"T_4ab75_row4_col5\" class=\"data row4 col5\" >Bellevue Suites</td>\n", " <td id=\"T_4ab75_row4_col6\" class=\"data row4 col6\" >Comfortable city living in the very center of downtown Bellevue. Newly reimagined, this hotel features apartment-style suites with sleeping, living and work spaces. Located across the street from the Light Rail to downtown. Free shuttle to the airport.</td>\n", " <td id=\"T_4ab75_row4_col7\" class=\"data row4 col7\" ><em>Comfortable city living </em>in the<em> very center of downtown Bellevue.</em> Newly reimagined, this hotel features<em> apartment-style suites </em>with<em> sleeping, living and work spaces.</em> Located across the street from the Light Rail to downtown. Free shuttle to the airport.</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff8f4a50>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "### Answers" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_0b693_row0_col0, #T_0b693_row0_col1, #T_0b693_row0_col2, #T_0b693_row1_col0, #T_0b693_row1_col1, #T_0b693_row1_col2, #T_0b693_row2_col0, #T_0b693_row2_col1, #T_0b693_row2_col2 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_0b693\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_0b693_level0_col0\" class=\"col_heading level0 col0\" >key</th>\n", " <th id=\"T_0b693_level0_col1\" class=\"col_heading level0 col1\" >score</th>\n", " <th id=\"T_0b693_level0_col2\" class=\"col_heading level0 col2\" >text</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_0b693_row0_col0\" class=\"data row0 col0\" >16</td>\n", " <td id=\"T_0b693_row0_col1\" class=\"data row0 col1\" >0.983000</td>\n", " <td id=\"T_0b693_row0_col2\" class=\"data row0 col2\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0b693_row1_col0\" class=\"data row1 col0\" >36</td>\n", " <td id=\"T_0b693_row1_col1\" class=\"data row1 col1\" >0.948000</td>\n", " <td id=\"T_0b693_row1_col2\" class=\"data row1 col2\" >Stunning Downtown Hotel with indoor Pool. Ideally located close to theatres, museums and the convention center. Indoor Pool and Sauna and fitness centre. Popular Bar & Restaurant.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_0b693_row2_col0\" class=\"data row2 col0\" >27</td>\n", " <td id=\"T_0b693_row2_col1\" class=\"data row2 col1\" >0.943000</td>\n", " <td id=\"T_0b693_row2_col2\" class=\"data row2 col2\" >Complimentary Airport Shuttle & WiFi. Book Now and save - Spacious All Suite Hotel, Indoor Outdoor Pool, Fitness Center, Florida Green certified, Complimentary Coffee, HDTV.</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff89c610>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = run_query(\"best hotel?\", semantic_config=\"semantic-config-with-title-and-keywords\", include_captions=True, include_answers=True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6.4 - Semantic Ranker on Individual Documents\n", "\n", "Sometimes it can be useful to find the semantic ranker score for a specific document given a query. By supplying the right [filter](https://learn.microsoft.com/azure/search/search-filters) to your search, you can extract the reranker score for any given document and query, provided you know that document's ID. Adding the `document_ids=[id1, id2, ... idN]` parameter to `run_query` allows you to extract this ranker score for the appropriate document. Please note that only up to 50 documents can be reranked for a request, so requests to rerank more than 50 documents at a time must be batched." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Reranked Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_f6f46_row0_col0, #T_f6f46_row0_col1, #T_f6f46_row0_col2, #T_f6f46_row0_col3, #T_f6f46_row0_col4, #T_f6f46_row0_col5, #T_f6f46_row0_col6, #T_f6f46_row0_col7, #T_f6f46_row0_col8, #T_f6f46_row0_col9 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_f6f46\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_f6f46_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_f6f46_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_f6f46_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_f6f46_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_f6f46_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_f6f46_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_f6f46_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " <th id=\"T_f6f46_level0_col7\" class=\"col_heading level0 col7\" >Title</th>\n", " <th id=\"T_f6f46_level0_col8\" class=\"col_heading level0 col8\" >Content</th>\n", " <th id=\"T_f6f46_level0_col9\" class=\"col_heading level0 col9\" >Keywords</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_f6f46_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_f6f46_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_f6f46_row0_col2\" class=\"data row0 col2\" >0.033333</td>\n", " <td id=\"T_f6f46_row0_col3\" class=\"data row0 col3\" >2.446100</td>\n", " <td id=\"T_f6f46_row0_col4\" class=\"data row0 col4\" >18</td>\n", " <td id=\"T_f6f46_row0_col5\" class=\"data row0 col5\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_f6f46_row0_col6\" class=\"data row0 col6\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_f6f46_row0_col7\" class=\"data row0 col7\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_f6f46_row0_col8\" class=\"data row0 col8\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_f6f46_row0_col9\" class=\"data row0 col9\" >view\r\n", "pool\r\n", "restaurant</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260df0d8c10>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = run_query(\"best hotel?\", semantic_config=\"semantic-config-with-title-and-keywords\", document_ids=[\"18\"], include_debug=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Reranked Results" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_15f0d_row0_col0, #T_15f0d_row0_col1, #T_15f0d_row0_col2, #T_15f0d_row0_col3, #T_15f0d_row0_col4, #T_15f0d_row0_col5, #T_15f0d_row0_col6, #T_15f0d_row0_col7, #T_15f0d_row0_col8, #T_15f0d_row0_col9, #T_15f0d_row1_col0, #T_15f0d_row1_col1, #T_15f0d_row1_col2, #T_15f0d_row1_col3, #T_15f0d_row1_col4, #T_15f0d_row1_col5, #T_15f0d_row1_col6, #T_15f0d_row1_col7, #T_15f0d_row1_col8, #T_15f0d_row1_col9 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_15f0d\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_15f0d_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_15f0d_level0_col1\" class=\"col_heading level0 col1\" >Original Index</th>\n", " <th id=\"T_15f0d_level0_col2\" class=\"col_heading level0 col2\" >@search.score</th>\n", " <th id=\"T_15f0d_level0_col3\" class=\"col_heading level0 col3\" >@search.reranker_score</th>\n", " <th id=\"T_15f0d_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_15f0d_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_15f0d_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " <th id=\"T_15f0d_level0_col7\" class=\"col_heading level0 col7\" >Title</th>\n", " <th id=\"T_15f0d_level0_col8\" class=\"col_heading level0 col8\" >Content</th>\n", " <th id=\"T_15f0d_level0_col9\" class=\"col_heading level0 col9\" >Keywords</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_15f0d_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_15f0d_row0_col1\" class=\"data row0 col1\" >0</td>\n", " <td id=\"T_15f0d_row0_col2\" class=\"data row0 col2\" >0.033060</td>\n", " <td id=\"T_15f0d_row0_col3\" class=\"data row0 col3\" >2.446100</td>\n", " <td id=\"T_15f0d_row0_col4\" class=\"data row0 col4\" >18</td>\n", " <td id=\"T_15f0d_row0_col5\" class=\"data row0 col5\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_15f0d_row0_col6\" class=\"data row0 col6\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_15f0d_row0_col7\" class=\"data row0 col7\" >Ocean Water Resort & Spa</td>\n", " <td id=\"T_15f0d_row0_col8\" class=\"data row0 col8\" >New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.</td>\n", " <td id=\"T_15f0d_row0_col9\" class=\"data row0 col9\" >view\r\n", "pool\r\n", "restaurant</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_15f0d_row1_col0\" class=\"data row1 col0\" >1</td>\n", " <td id=\"T_15f0d_row1_col1\" class=\"data row1 col1\" >1</td>\n", " <td id=\"T_15f0d_row1_col2\" class=\"data row1 col2\" >0.033060</td>\n", " <td id=\"T_15f0d_row1_col3\" class=\"data row1 col3\" >2.083035</td>\n", " <td id=\"T_15f0d_row1_col4\" class=\"data row1 col4\" >6</td>\n", " <td id=\"T_15f0d_row1_col5\" class=\"data row1 col5\" >King's Cellar Hotel</td>\n", " <td id=\"T_15f0d_row1_col6\" class=\"data row1 col6\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " <td id=\"T_15f0d_row1_col7\" class=\"data row1 col7\" >King's Cellar Hotel</td>\n", " <td id=\"T_15f0d_row1_col8\" class=\"data row1 col8\" >Newest kid on the downtown block. Steps away from the most popular destinations in downtown, enjoy free WiFi, an indoor rooftop pool & fitness center, 24 Grab'n'Go & drinks at the bar</td>\n", " <td id=\"T_15f0d_row1_col9\" class=\"data row1 col9\" >free wifi\r\n", "pool\r\n", "bar</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff8f5510>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = run_query(\"best hotel?\", semantic_config=\"semantic-config-with-title-and-keywords\", document_ids=[\"18\", \"6\"], include_debug=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6.5 - Compare semantic ranker configurations\n", "\n", "Sometimes you want to compare the results between multiple semantic ranker configurations. The following function allows you to compare the results by seeing how one semantic ranker's top results are different than another's\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def compare_results(original_config_results: pd.DataFrame, new_config_results: pd.DataFrame, key: Optional[str] = \"HotelId\") -> None:\n", " merged = pd.merge(original_config_results, new_config_results, on=\"HotelId\", suffixes=(\"_left\", \"_right\"))\n", " result_df = merged[[\"Reranked Index_right\", \"@search.reranker_score_left\", \"@search.reranker_score_right\", \"HotelId\", \"HotelName_left\", \"Description_left\"]].rename(columns={\n", " \"Reranked Index_right\": \"New Reranked Index\",\n", " \"@search.reranker_score_left\": \"Original Reranker Score\",\n", " \"@search.reranker_score_right\": \"New Reranker Score\",\n", " \"HotelName_left\": \"HotelName\",\n", " \"Description_left\": \"Description\"\n", " })\n", "\n", " def highlight_rerank_row_changes(row: pd.Series):\n", " reranked_index = row.iloc[1]\n", " new_reranked_index = row.iloc[2]\n", " first_column_style = ''\n", " if new_reranked_index > reranked_index:\n", " first_column_style = 'background-color: green'\n", " elif new_reranked_index < reranked_index:\n", " first_column_style = 'background-color: red'\n", "\n", " return [first_column_style, first_column_style] + ['' for i in range(len(row) - 2)]\n", " df_style = {\n", " 'max-width': '500px',\n", " 'text-align': 'left',\n", " 'white-space': 'normal',\n", " 'word-wrap': 'break-word'\n", " }\n", "\n", " result_df = pd.DataFrame({\n", " \"Reranked Index\": result_df.index.map({reranked_idx: i for i, reranked_idx in enumerate(result_df.index)}),\n", " **result_df.to_dict('list')})\n", "\n", "\n", " compare_df_display = result_df.head(5)\n", " compare_df_display = compare_df_display.style.apply(highlight_rerank_row_changes, axis=1).set_properties(**df_style).hide(axis=\"index\")\n", " display(Markdown(\"### Comparison\"))\n", " display(compare_df_display)\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Comparison" ], "text/plain": [ "<IPython.core.display.Markdown object>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<style type=\"text/css\">\n", "#T_1f7ef_row0_col0, #T_1f7ef_row0_col1, #T_1f7ef_row1_col0, #T_1f7ef_row1_col1, #T_1f7ef_row3_col0, #T_1f7ef_row3_col1, #T_1f7ef_row4_col0, #T_1f7ef_row4_col1 {\n", " background-color: red;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_1f7ef_row0_col2, #T_1f7ef_row0_col3, #T_1f7ef_row0_col4, #T_1f7ef_row0_col5, #T_1f7ef_row0_col6, #T_1f7ef_row1_col2, #T_1f7ef_row1_col3, #T_1f7ef_row1_col4, #T_1f7ef_row1_col5, #T_1f7ef_row1_col6, #T_1f7ef_row2_col2, #T_1f7ef_row2_col3, #T_1f7ef_row2_col4, #T_1f7ef_row2_col5, #T_1f7ef_row2_col6, #T_1f7ef_row3_col2, #T_1f7ef_row3_col3, #T_1f7ef_row3_col4, #T_1f7ef_row3_col5, #T_1f7ef_row3_col6, #T_1f7ef_row4_col2, #T_1f7ef_row4_col3, #T_1f7ef_row4_col4, #T_1f7ef_row4_col5, #T_1f7ef_row4_col6 {\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "#T_1f7ef_row2_col0, #T_1f7ef_row2_col1 {\n", " background-color: green;\n", " max-width: 500px;\n", " text-align: left;\n", " white-space: normal;\n", " word-wrap: break-word;\n", "}\n", "</style>\n", "<table id=\"T_1f7ef\">\n", " <thead>\n", " <tr>\n", " <th id=\"T_1f7ef_level0_col0\" class=\"col_heading level0 col0\" >Reranked Index</th>\n", " <th id=\"T_1f7ef_level0_col1\" class=\"col_heading level0 col1\" >New Reranked Index</th>\n", " <th id=\"T_1f7ef_level0_col2\" class=\"col_heading level0 col2\" >Original Reranker Score</th>\n", " <th id=\"T_1f7ef_level0_col3\" class=\"col_heading level0 col3\" >New Reranker Score</th>\n", " <th id=\"T_1f7ef_level0_col4\" class=\"col_heading level0 col4\" >HotelId</th>\n", " <th id=\"T_1f7ef_level0_col5\" class=\"col_heading level0 col5\" >HotelName</th>\n", " <th id=\"T_1f7ef_level0_col6\" class=\"col_heading level0 col6\" >Description</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <td id=\"T_1f7ef_row0_col0\" class=\"data row0 col0\" >0</td>\n", " <td id=\"T_1f7ef_row0_col1\" class=\"data row0 col1\" >12</td>\n", " <td id=\"T_1f7ef_row0_col2\" class=\"data row0 col2\" >2.559352</td>\n", " <td id=\"T_1f7ef_row0_col3\" class=\"data row0 col3\" >2.316807</td>\n", " <td id=\"T_1f7ef_row0_col4\" class=\"data row0 col4\" >1</td>\n", " <td id=\"T_1f7ef_row0_col5\" class=\"data row0 col5\" >Stay-Kay City Hotel</td>\n", " <td id=\"T_1f7ef_row0_col6\" class=\"data row0 col6\" >This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_1f7ef_row1_col0\" class=\"data row1 col0\" >1</td>\n", " <td id=\"T_1f7ef_row1_col1\" class=\"data row1 col1\" >21</td>\n", " <td id=\"T_1f7ef_row1_col2\" class=\"data row1 col2\" >2.353051</td>\n", " <td id=\"T_1f7ef_row1_col3\" class=\"data row1 col3\" >2.110063</td>\n", " <td id=\"T_1f7ef_row1_col4\" class=\"data row1 col4\" >17</td>\n", " <td id=\"T_1f7ef_row1_col5\" class=\"data row1 col5\" >City Skyline Antiquity Hotel</td>\n", " <td id=\"T_1f7ef_row1_col6\" class=\"data row1 col6\" >In vogue since 1888, the Antiquity Hotel takes you back to bygone era. From the crystal chandeliers that adorn the Green Room, to the arched ceilings of the Grand Hall, the elegance of old New York beckons. Elevate Your Experience. Upgrade to a premiere city skyline view for less, where old world charm combines with dramatic views of the city, local cathedral and midtown.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_1f7ef_row2_col0\" class=\"data row2 col0\" >2</td>\n", " <td id=\"T_1f7ef_row2_col1\" class=\"data row2 col1\" >1</td>\n", " <td id=\"T_1f7ef_row2_col2\" class=\"data row2 col2\" >2.152909</td>\n", " <td id=\"T_1f7ef_row2_col3\" class=\"data row2 col3\" >2.648679</td>\n", " <td id=\"T_1f7ef_row2_col4\" class=\"data row2 col4\" >16</td>\n", " <td id=\"T_1f7ef_row2_col5\" class=\"data row2 col5\" >Double Sanctuary Resort</td>\n", " <td id=\"T_1f7ef_row2_col6\" class=\"data row2 col6\" >5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_1f7ef_row3_col0\" class=\"data row3 col0\" >3</td>\n", " <td id=\"T_1f7ef_row3_col1\" class=\"data row3 col1\" >17</td>\n", " <td id=\"T_1f7ef_row3_col2\" class=\"data row3 col2\" >2.109974</td>\n", " <td id=\"T_1f7ef_row3_col3\" class=\"data row3 col3\" >2.213789</td>\n", " <td id=\"T_1f7ef_row3_col4\" class=\"data row3 col4\" >23</td>\n", " <td id=\"T_1f7ef_row3_col5\" class=\"data row3 col5\" >Downtown Mix Hotel</td>\n", " <td id=\"T_1f7ef_row3_col6\" class=\"data row3 col6\" >Mix and mingle in the heart of the city. Shop and dine, mix and mingle in the heart of downtown, where fab lake views unite with a cheeky design.</td>\n", " </tr>\n", " <tr>\n", " <td id=\"T_1f7ef_row4_col0\" class=\"data row4 col0\" >4</td>\n", " <td id=\"T_1f7ef_row4_col1\" class=\"data row4 col1\" >22</td>\n", " <td id=\"T_1f7ef_row4_col2\" class=\"data row4 col2\" >2.077806</td>\n", " <td id=\"T_1f7ef_row4_col3\" class=\"data row4 col3\" >2.092782</td>\n", " <td id=\"T_1f7ef_row4_col4\" class=\"data row4 col4\" >9</td>\n", " <td id=\"T_1f7ef_row4_col5\" class=\"data row4 col5\" >Smile Up Hotel</td>\n", " <td id=\"T_1f7ef_row4_col6\" class=\"data row4 col6\" >Experience the fresh, modern downtown. Enjoy updated rooms, bold style & prime location. Don't miss our weekend live music series featuring who's new/next on the scene.</td>\n", " </tr>\n", " </tbody>\n", "</table>\n" ], "text/plain": [ "<pandas.io.formats.style.Styler at 0x260ff9882d0>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results_title = run_query(\"new york\", semantic_config=\"semantic-config-with-title\", should_display=False)\n", "results_title_and_keywords = run_query(\"new york hotel with pool or gym\", semantic_config=\"semantic-config-with-title-and-keywords\", should_display=False)\n", "\n", "compare_results(results_title, results_title_and_keywords)" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }