Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (2024)

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (1)

GitHub Repository:azure-ai-vision-search

Introduction

Vector image search uses AI to revolutionize how we find and retrieve images. This article explains how to combine Azure OpenAI and Azure AI Search for an efficient solution. We'll cover setup, deployment, and usage to guide AI developers and engineers. We'll focus on the search and vectorize methods in the function_app.py Python file, crucial for integrating Azure's AI services for vector image searches. This technology is ideal for applications like e-commerce and digital asset management.

We dive into the core functionalities of the Azure AI Search service, focusing on the search and vectorize methods in the function_app.py python file. These methods are pivotal in integrating Azure's AI services to perform vector image searches.

Prerequisites

  • An Azure account with an active subscription. Create an account for free.
  • An Azure Storage account for storing images. Create a storage account.
  • An Azure AI Search service for any tier and any region Create a service or find an existing service under your current subscription.
  • An Azure OpenAI service for any tier and any region. Create a service.
    Azure Functions setup for processing Create python function.
  • Tools: Azure CLI, Visual Studio Code, and Postman for API testing.

AI Search Setup

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (2)

Below are Azure AI Search schema files that define the index, indexer, and skillset used to store and process image data for efficient search and retrieval. These files are used to configure the Azure AI Search service to work with the vector image search solution.

> Action: Open the Azure AI Search servicein the Azure portal and navigate to each section below to upload the corresponding JSON file.

1. Add Index

This defines the structure and schema of the search index, including specifying fields, data types, and attributes.

> Action: Go to the Indexes blade and create a new index using the JSON definition file vector-image-index-db.json.

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (3)

2. Add Indexer

Set up an indexer to manage data ingestion from a source like Azure Storage to the search index.

> Action: Use the vector-image-indexer.json file in the Indexers blade to create a new indexer.

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (4)

3. Add Skillset

Create a skillset to define the AI enrichment pipeline for image processing before indexing.

> Action: Use the JSON definition file vector-image-skillset.json to create a new skillset in the Skillsets blade.

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (5)

These components work together to enable the ingestion, transformation, and indexing of image data, allowing efficient search and retrieval using Azure AI Search service, with the indexer triggering the vectorize Azure Function for handling image embeddings.

Azure Function Setup

Variables

Configuration variables are stored in the local.settings.json file and should be set as part of the Azure Function Environment variables blade. Key variables to configure include:

export AZURE_OPENAI_API_KEY=<Your Azure OpenAI API Key>export AZURE_OPENAI_ENDPOINT=<Your Azure OpenAI Endpoint>export OPEN_AI_MODEL=gpt-35-turboexport API_VERSION=2024-02-01export AI_VISION_ENDPOINT=<Your Azure Vision Endpoint>export AI_VISION_API_KEY=<Your Azure Vision API Key>export AI_SEARCH_SERVICE_ENDPOINT=<Your Azure Search Service Endpoint>export AZURE_SEARCH_ADMIN_KEY=<Your Azure Search Admin Key>export AI_SEARCH_INDEX_NAME=<Your Azure Search Index Name>export ACCOUNT_KEY=<Your Account Key>

> Action: Set these variables in the Azure Function App Configuration blade.

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (6)

GitHub Action Workflow

The function is being deployed automatically using a GitHub Action workflow. The function app is responsible for processing image data and performing similarity searches using Azure AI Search. The function app consists of two main methods: vectorize and search.

The main-premium.yml GitHub Action workflow file automates the deployment of the function app. It triggers the deployment process whenever changes are pushed to the main branch. The workflow uses the Azure Functions action to deploy the function app to Azure.

>Action: For the workflow to work, you need to set up the following secrets in your GitHub repository:

  • AZURE_RBAC_CREDENTIALS: Azure service principal credentials with access to the Azure subscription. more details here.
  • AZURE_FUNCTIONAPP_PUBLISH_PROFILE_PREMIUM: Publish profile for the Azure Function app. more details here.

Testing the Solution

vectorize

Uploading Files to the storage and then running the Azure AI search Indexer for embedding generation.

  • Use Azure Storage Explorer or Azure CLI for uploading images to the container.
  • Goto your AI Search service, run the indexer to process and vectorize images.
  • Monitor the indexing process via Azure Portal.

search

Using the Search API to Vector Search for Images, Leverage the Azure Search API to perform vector searches.

  • Construct the search query with the image vector {query: "blue sky"}.
  • Execute the query using Postman or code.
  • Interpret the search results to find similar images.

Azure Function Explained

The below sections explain the core functionalities of the Azure Function app, focusing on the vectorize and search methods in the function_app.py Python file. These methods are pivotal in integrating Azure's AI services to perform vector image searches.

The vectorize Method

The vectorize method is responsible for converting images into vector embeddings. This process involves several steps:

1. HTTP Request Handling
  • The method is triggered by a POST request containing image URLs and other metadata.
  • The request body is parsed to extract the values needed for processing.
2. Image Embedding Generation
  • The vectorize_images function is called with the extracted values. This function processes each image URL by invoking the vectorize_image helper function.
  • Within vectorize_image, a SAS token is created for secure access to the image stored in Azure Blob Storage.
  • The get_image_embeddings function from the helper module generates the embeddings using Azure's Computer Vision API. The embeddings are numerical representations capturing the semantic content of the images.
3. Response Construction
  • The embeddings are assembled into a response payload.
  • The response is returned as a JSON object, making the embeddings available for downstream tasks such as indexing and searching.

By leveraging Azure's Computer Vision API, the vectorize method transforms images into vectors. These vectors are numeric representations that encapsulate the images' visual features, making them suitable for similarity searches.

Usage

# Example usageimage_urls = ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]embeddings = vectorize_images(image_urls)print(embeddings)

The search Method

The search method facilitates image similarity searches using vectors generated by the vectorize method. Here's how it works:

1. HTTP Request Handling

The method is triggered by a POST request containing a query string and optional parameters like max_images.

2. Query Processing with OpenAI
  • The provided query is refined using the ask_openai function, which interacts with Azure OpenAI. This function rephrases the query to improve search accuracy.
  • The refined query is then converted into vector embeddings using the generate_embeddings_text function. This function utilizes Azure's Computer Vision API to generate text embeddings.
3. Vector Search Execution
  • A VectorizedQuery object is created, containing the query embeddings and parameters for the search.
  • The search_client performs a vector search on the image vectors stored in the Azure AI Search index. This search identifies images whose vector embeddings are most similar to the query embeddings.
4. Result Compilation
  • The search results are compiled into a response payload. For each result, a SAS token is generated for secure access to the image.
  • The response is returned as a JSON object, containing the image URLs, titles, and search scores.

The search method integrates Azure OpenAI and Azure AI Search to perform efficient and accurate image similarity searches. By converting textual queries into vector embeddings, it ensures that the search results are relevant and precise.

Usage
# Example usagequery = "Find images of mountains"search_results = search_images(query, max_images=5)print(search_results)

Azure Resources

The azure-ai-vision-search repository leverages several Azure services to enable vector image searches:

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (7)

Conclusion

Combining Azure OpenAI with Azure AI Search provides a powerful solution for vector image search. By following this guide, you can set up and deploy a robust search system to meet various business needs. Explore further possibilities by integrating more advanced AI models and expanding your search capabilities.

Vector Image Search using Azure OpenAI & AI Search: A Technical Guide (2024)

References

Top Articles
Wichita Cityxguide
W-9 Form—Fill Out the IRS W-9 Form Online for 2023 | Smallpdf
Funny Roblox Id Codes 2023
Www.mytotalrewards/Rtx
San Angelo, Texas: eine Oase für Kunstliebhaber
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Steamy Afternoon With Handsome Fernando
fltimes.com | Finger Lakes Times
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
978-0137606801
Nwi Arrests Lake County
Missed Connections Dayton Ohio
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
How to Create Your Very Own Crossword Puzzle
Apply for a credit card
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Dashboard Unt
Access a Shared Resource | Computing for Arts + Sciences
2023 Ford Bronco Raptor for sale - Dallas, TX - craigslist
Healthy Kaiserpermanente Org Sign On
Restored Republic
Progressbook Newark
Lawrence Ks Police Scanner
3473372961
Landing Page Winn Dixie
Everstart Jump Starter Manual Pdf
Hypixel Skyblock Dyes
Craigslist Red Wing Mn
American Bully Xxl Black Panther
Ktbs Payroll Login
Jail View Sumter
Thotsbook Com
Funkin' on the Heights
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Marcel Boom X
Www Pig11 Net
Ty Glass Sentenced
Michaelangelo's Monkey Junction
Game Akin To Bingo Nyt
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 5615

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.