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)

FAQs

What is vector profile in Azure AI search? ›

In Azure AI Search, a vector store has an index schema that defines vector and nonvector fields, a vector configuration for algorithms that create and compress the embedding space, and settings on vector field definitions that are used in query requests.

What is the difference between semantic search and vector search in Azure cognitive search? ›

While Semantic Search enhances search accuracy by understanding the meaning behind words, Vector Search takes things a step further by leveraging the power of machine learning and deep learning techniques. Here's how Vector Search works: 1.

What is AI search in Azure? ›

Azure AI Search (formerly known as "Azure Cognitive Search") provides secure information retrieval at scale over user-owned content in traditional and generative AI search applications. Information retrieval is foundational to any app that surfaces text and vectors.

How does Azure OpenAI work? ›

Azure OpenAI On Your Data works by sending instructions to a large language model in the form of prompts to answer user queries using your data. If there is a certain behavior that is critical to the application, you can repeat the behavior in system message to increase its accuracy.

What is vector search with an example? ›

With vector search, user preferences, interests, hobbies, and information can be built into the data representation that represents them and recommendations can be made based on close in similarity the result from their query matches their profile. Take for example somebody searching for tennis balls.

When to use vector search? ›

Frequently used for semantic search, vector search finds similar data using approximate nearest neighbor (ANN) algorithms. Compared to traditional keyword search, vector search yields more relevant results and executes faster.

Is Azure Cognitive Search same as Elasticsearch? ›

While Elasticsearch can only respond in JSON, but its API does allow you to query or delete documents, create and manage indices, get analytics and control search configuration. Azure Search utilizes a simple query string syntax for basic text search, but needs engineering to handle more structured queries.

What is the new name for Azure Cognitive Search? ›

Azure Cognitive Search is now Azure AI Search.

What is semantic search vs vector search? ›

While Semantic Search aims to provide personalized and contextually accurate results aligned with user intent, Vector Search excels in capturing nuanced relationships within data points .

What is the difference between Azure AI search and Azure OpenAI? ›

The Azure OpenAI Connector provides powerful AI functionalities such as generating embeddings, summarization, and chat completion, which are pivotal for creating sophisticated AI applications. Meanwhile, the Azure AI Search Connector enhances data retrieval with advanced vector and hybrid search operations.

What is Azure AI used for? ›

Azure AI services help developers and organizations rapidly create intelligent, cutting-edge, market-ready, and responsible applications with out-of-the-box and prebuilt and customizable APIs and models.

How are ChatGPT OpenAI and Azure OpenAI related? ›

In summary, ChatGPT is developed by OpenAI, and Azure OpenAI is the collaboration between OpenAI and Microsoft to make OpenAI's models accessible through the Azure platform.

How to use Azure OpenAI for free? ›

Note: Azure does not allow the free account tier to access OpenAI services. Once you have an Azure subscription, you need to go to the Azure Portal Page, sign in, and get your subscription ID. You'll find it through the “Subscriptions” service.

Does Azure AI search store data? ›

Where does Azure AI Search store customer data? It stores your data in the geography (Geo) where your service is deployed. Microsoft might replicate your data within the same geo for high availability and durability.

What is the main advantage of using Azure OpenAI services? ›

Azure OpenAI Service offers pricing based on both Pay-As-You-Go and Provisioned Throughput Units (PTUs). Pay-As-You-Go allows you to pay for the resources you consume, making it flexible for variable workloads.

What is vector in Azure OpenAI? ›

Vector search is an approach in information retrieval that supports indexing and query execution over numeric representations of content.

What is vector data in AI? ›

A vector database is a collection of data stored as mathematical representations. Vector databases make it easier for machine learning models to remember previous inputs, allowing machine learning to be used to power search, recommendations, and text generation use-cases.

What is vector file in AI? ›

A vector graphics file is an image that can be made infinitely large or small without losing quality. Common vector file types include . AI (Adobe Illustrator), . EPS (Encapsulated Postscript), and . SVG (Scalable Vector Graphics).

What is vector AI used for? ›

In Computer Science, vector processing refers to the ability to parallelize single-threaded operations such as database query processing. AI-based natural language processing allows non-technical users to formulate data requests using a conversational dialog.

References

Top Articles
Bjc Remote Access
Transcript: Grade 9 and 10 Math Integrated ELD
Menards Thermal Fuse
NOAA: National Oceanic &amp; Atmospheric Administration hiring NOAA Commissioned Officer: Inter-Service Transfer in Spokane Valley, WA | LinkedIn
Duralast Gold Cv Axle
Limp Home Mode Maximum Derate
La connexion à Mon Compte
Poplar | Genus, Description, Major Species, & Facts
Best Cav Commanders Rok
Otr Cross Reference
FIX: Spacebar, Enter, or Backspace Not Working
FAQ: Pressure-Treated Wood
2024 U-Haul ® Truck Rental Review
Drago Funeral Home & Cremation Services Obituaries
Rainfall Map Oklahoma
Lima Funeral Home Bristol Ri Obituaries
Red Devil 9664D Snowblower Manual
Fraction Button On Ti-84 Plus Ce
Air Force Chief Results
Military life insurance and survivor benefits | USAGov
What Are The Symptoms Of A Bad Solenoid Pack E4od?
Valic Eremit
eugene bicycles - craigslist
Mcclendon's Near Me
Ultra Ball Pixelmon
Dell 22 FHD-Computermonitor – E2222H | Dell Deutschland
Big Boobs Indian Photos
Delta Math Login With Google
Craigslist Auburn Al
Meggen Nut
Uno Fall 2023 Calendar
Kiddie Jungle Parma
Bfri Forum
Bursar.okstate.edu
Kaiju Paradise Crafting Recipes
Shnvme Com
Muma Eric Rice San Mateo
Arcadia Lesson Plan | Day 4: Crossword Puzzle | GradeSaver
Austin Automotive Buda
Busch Gardens Wait Times
Keir Starmer looks to Italy on how to stop migrant boats
Mid America Irish Dance Voy
All Characters in Omega Strikers
Tripadvisor Vancouver Restaurants
Sams Gas Price Sanford Fl
2Nd Corinthians 5 Nlt
Nimbleaf Evolution
Quest Diagnostics Mt Morris Appointment
F9 2385
Sam's Club Fountain Valley Gas Prices
Craigslist Psl
Powah: Automating the Energizing Orb - EnigmaticaModpacks/Enigmatica6 GitHub Wiki
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6422

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.