0% found this document useful (0 votes)
11 views

Azure Semantic Search vs. Vector Search

Uploaded by

59613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Azure Semantic Search vs. Vector Search

Uploaded by

59613
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Azure

Semantic Search
vs.
Vector Search

1 ANSHUMAN JHA
Table of Contents
1. Introduction
2. Key Concepts: Semantic Search vs.
Vector Search
3. Use Case Scenarios
4. Implementation Tutorial
5. Prerequisites
6. Step 1: Authenticate and Connect to
Azure Search Service
7. Step 2: Perform Semantic Search
8. Step 3: Perform Vector Search
9.Step 4: Combine Full-Text and Vector
Search (Hybrid Search)
10. Conclusion

2 ANSHUMAN JHA
Introduction

Azure AI Search is a powerful tool for


enhancing search experiences
through advanced features like
Semantic Search and Vector
Search.

3 ANSHUMAN JHA
These technologies cater to modern
needs by leveraging AI to provide
context-aware, accurate search
results.

This tutorial will explore the


differences between these two
features, their use cases.

4 ANSHUMAN JHA
Key Concepts: Semantic
Search vs. Vector
Search
Feature Semantic Vector Search
Search
Focus Understandin Mathematical
g the representations
meaning and and similarity
intent behind calculations.
queries and
content.
How it Uses Transforms
Works language queries and
understandin documents into
g to rank high-
search results dimensional
contextually. vectors.

5 ANSHUMAN JHA
Application Ideal for Suitable for
s improving nuanced
traditional contexts like
search recommendati
ranking. on systems.
Availability Paid feature. Free in all
Azure AI
Search tiers.
Combinatio Cannot Can combine
n natively with keyword
combine searches in
with vector hybrid
search. scenarios.

Use Case Scenarios


6 ANSHUMAN JHA
1. Semantic Search:

Useful for applications like FAQ


bots, where matching the user's intent
to the correct answer matters most.

2. Vector Search:

Ideal for personalized search


experiences, recommendation
systems, and retrieving content with
subtle contextual relevance.

7 ANSHUMAN JHA
Implementation
Tutorial
This section provides a step-by-step
guide for working with Azure
Semantic Search and Azure Vector
Search.

Prerequisites

1. Azure subscription with AI


Search enabled.

2. An existing Azure Search service


and index.

8 ANSHUMAN JHA
3. Python 3.7+ installed locally or
through Colab.

4. Azure Cognitive Search SDK


(azure-search-documents) installed.

!pip install azure-search-documents

9 ANSHUMAN JHA
Step 1: Authenticate and Connect
to Azure Search Service

from azure.search.documents import SearchClient


from azure.core.credentials import
AzureKeyCredential

#Azure Cognitive Search configuration

SEARCH_SERVICE_NAME = "your-search-
service-name"
SEARCH_INDEX_NAME = "your-index-name"
SEARCH_API_KEY = "your-api-key"

# Initialize SearchClient

endpoint =
f"https://{SEARCH_SERVICE_NAME}.search.win
dows.net"
search_client = SearchClient(
endpoint=endpoint,
index_name=SEARCH_INDEX_NAME,

credential=AzureKeyCredential(SEARCH_API_KE
Y),
)
print("Connected to Azure Search Service!")
10 ANSHUMAN JHA
Step 2: Perform Semantic Search

# Query for semantic search


query = "What is the refund policy for orders?"

# Use semantic search

response = search_client.search(
query,
semantic_configuration_name="your-
semantic-config-name",
query_type="semantic",
query_language="en-us"
)

# Display results

print("Semantic Search Results:")


for result in response:
print(f"- {result['@search.score']}:
{result['content']}")

11 ANSHUMAN JHA
Explanation:

• semantic_configuration_name:

Specifies the configuration to use for


semantic ranking.

query_type: Set to semantic for


language-aware ranking.

12 ANSHUMAN JHA
Step 3: Perform Vector Search

from azure.search.documents.models import


Vector

# Query vector (assumes precomputed


embeddings for simplicity)

query_vector = [0.1, 0.2, 0.3, 0.4] # Replace with


actual query embedding

# Vector search parameters

response = search_client.search(
search_text="", # Leave empty for vector
search
vector=Vector(value=query_vector, k=3,
fields="content_vector"), # Top 3 results
)

# Display results

print("Vector Search Results:")


for result in response:
print(f"- {result['@search.score']}:
{result['content']}")

13 ANSHUMAN JHA
Explanation:

• Vector: Defines the vector used for


similarity search.

• fields: Specifies the vectorized field


in the index (e.g., content_vector).

• k: The number of nearest neighbors


to retrieve.

14 ANSHUMAN JHA
Step 4: Combine Full-Text and
Vector Search (Hybrid Search)

# Hybrid search query

hybrid_query = "recommended books for AI"

# Perform hybrid search


response = search_client.search(
search_text=hybrid_query,
vector=Vector(value=query_vector, k=3,
fields="content_vector"),
query_type="simple" # Default query type for
keyword search
)

# Display results

print("Hybrid Search Results:")

for result in response:


print(f"- {result['@search.score']}:
{result['content']}")

15 ANSHUMAN JHA
Conclusion
Azure Semantic Search and Vector
Search are powerful tools for
enriching search experiences:
• Semantic Search improves
traditional keyword searches with
intent-based understanding.
• Vector Search excels in
applications requiring nuanced
context, such as recommendations.
Combining the two approaches
through hybrid search ensures both
precision and contextual relevance.
Experiment with these features in
your projects to harness the full
potential of Azure AI Search.

16 ANSHUMAN JHA
17 ANSHUMAN JHA

You might also like