Azure AI Search .NET Samples
repository·main·Indexed 41 days ago
https://github.com/azure-samples/azure-search-dotnet-samplesA collection of C# code samples demonstrating implementation patterns for Azure AI Search. Examples cover full-text keyword search, semantic ranking, vector search (including hybrid and semantic hybrid), AI enrichment pipelines using Azure AI Services, and advanced agentic retrieval with image-serving and LLM integration. Includes guidance on using the Azure SDK for .NET and required NuGet packages such as Azure.Search.Documents 12.1.0-beta.2.
What's inside Azure AI Search .NET Samples
- This repository provides a collection of C# code samples designed to demonstrate various capabilities of Azure AI Search. These samples are intended to be used with an Azure AI Search service, and they are compatible with the shared (free) pricing tier unless otherwise specified.
Quickstart: Vector search in Azure AI Search using C#
mainThis sample provides a complete walkthrough for implementing vector search capabilities using the Azure SDK for .NET. It covers the end-to-end lifecycle of vector search: creating a vector index, populating that index with documents containing embeddings, and executing various query types including vector, hybrid, and semantic hybrid searches.Quickstart: Agentic retrieval in Azure AI Search using C#
mainThis sample demonstrates how to implement an agentic retrieval pipeline using Azure AI Search and C#. The workflow involves creating a search index, defining a knowledge source that targets that index, and building a knowledge base that integrates a Large Language Model (LLM) for query planning and answer synthesis.Tutorial: AI enrichment in Azure AI Search using C#
mainThis sample demonstrates how to build an AI enrichment indexing pipeline. It automates the process of detecting and extracting text from images and scanned documents stored in Azure Blob Storage. The pipeline uses built-in Azure AI Search skills to extract text and structure, which is then stored in a search index to enable full-text search over the enriched content.Understand the components of the Keyword Search sample
mainThe sample is organized into the following functional components:
AzureSearchQuickstart.csproj: The project file containing necessary NuGet dependencies and build configurations.Program.cs: The main entry point that orchestrates the index creation, document ingestion, and query execution.Hotel.cs&Address.cs: Data models that define the structure and schema of the search index.Hotel.Methods.cs&Address.Methods.cs: Helper files containingToString()overrides to facilitate readable console output during the demonstration.
Explore the components of the Agentic Retrieval sample
mainThe sample consists of the following key files:
sample.env: A template containing the environment variables required for configuration.AgenticRetrievalQuickstart.csproj: The C# project file defining necessary dependencies and build settings.program.cs: A console application that executes the entire agentic retrieval pipeline sequentially.quickstart.ipynb: A Jupyter notebook designed for users who want to run and inspect individual steps of the process manually.
Understand the components of the AI enrichment sample
mainThe sample is composed of three primary files that work together to create the enrichment pipeline:
Program.cs: The main entry point that orchestrates the creation of the enrichment pipeline.DemoIndex.cs: Defines the search index schema, including the fields used to store enriched data.appsettings.json: The configuration file used to provide service endpoints and authentication keys for Azure services.
Explore vector search sample implementations
mainThe sample is organized into three main functional areas:
VectorSearchCreatePopulateIndex: Handles the infrastructure setup, specifically creating and populating a vector index using hotel data.VectorSearchExamples: Demonstrates how to execute different search patterns:- Vector queries: Searching based on vector embeddings.
- Hybrid queries: Combining keyword search with vector search.
- Semantic hybrid queries: Combining keyword, vector, and semantic ranking.
VectorSearchShared: Contains the shared data models used across the sample, such asHotel.cs,Address.cs, andLocation.cs.
Understand the Image serving for agentic retrieval workflow
mainThe image-serving workflow for agentic retrieval (preview) follows these conceptual steps:
- Ingestion: A blob knowledge source uses managed ingestion (via Azure Content Understanding in Foundry Tools) to perform semantic chunking, table preservation, figure description, and image extraction.
- Indexing: Azure AI Search stores the extracted images in an asset store and maintains
image_pathreferences within the generated index. - Retrieval & Synthesis: When retrieval is enabled, the service identifies relevant images and supplies their content to a multimodal model during the answer synthesis phase.
Verification Metrics
A successful run verifies the following behaviors:
- Wildcard Search: An ordinary wildcard query against the index finds a non-empty
image_path, and the asset can be downloaded. - Disabled Retrieval: When retrieval is disabled, zero images are sent to the model.
- Enabled Retrieval: When retrieval is enabled, the response reports positive values for
ImagesRetrieved,ImagesSentToModel, andTotalImageSizeBytes. - Asset Integrity: The selected blob contains valid bytes and has an
image/*content type.
Quickstart: Keyword search in Azure AI Search using C#
mainThis sample provides a foundational implementation for performing full-text (keyword) search using the Azure SDK for .NET. It covers the complete lifecycle of a search index: creating the index schema, loading documents into the index, and executing keyword queries. The sample uses a simplified 'hotels' dataset to demonstrate these operations.Quickstart: Semantic ranking in Azure AI Search using C#
mainThis sample demonstrates how to implement semantic ranking in Azure AI Search using C#. The workflow involves two main steps: adding a semantic configuration to an existing search index and then executing queries that utilize semantic parameters to improve result relevance.
Sample Components
BuildIndex: A project designed to update an existing index (specifically thehotels-sampleindex) by adding a semantic configuration.QueryIndex: A project that executes semantic queries against the configured index.
Explore Azure AI Search C# sample scenarios
mainThe repository contains several specialized samples covering different search patterns and advanced features:
- Agentic Retrieval:
quickstart-agentic-retrievalsets up a knowledge base to integrate LLM reasoning into query planning. - Full-text Search:
quickstart-keyword-searchis a console application demonstrating fundamental tasks: creating an index, loading data, and querying (using a subset of the Hotels dataset). - Semantic Ranking:
quickstart-semantic-rankingdemonstrates how to add semantic ranking to an existing index and formulate semantic queries. - Vector Search:
quickstart-vector-searchcreates an index with vectorized descriptions and demonstrates vector queries. - AI Enrichment:
tutorial-ai-enrichmentimplements an AI enrichment pipeline (index, indexer, data source, and skillset) using Azure AI Services for image analysis, OCR, and NLP to structure blob content. - Image Serving in Agentic Retrieval:
image-serving-exampledemonstrates managed ingestion and compares retrieval with image serving enabled vs disabled, including querying and downloading indexed images from Azure Blob Storage.
- Agentic Retrieval: