Azure AI Search .NET Samples

repository·main·Indexed 41 days ago

https://github.com/azure-samples/azure-search-dotnet-samples

A 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.

Tokens
5.3K
Snippets
7
Records
20
Agent score
100%

What's inside Azure AI Search .NET Samples

  1. Quickstart: Vector search in Azure AI Search using C#

    main
    This 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.
  2. Tutorial: AI enrichment in Azure AI Search using C#

    main
    This 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.
  3. Understand the components of the Keyword Search sample

    main

    The 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 containing ToString() overrides to facilitate readable console output during the demonstration.
  4. Explore the components of the Agentic Retrieval sample

    main

    The 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.
  5. Understand the components of the AI enrichment sample

    main

    The 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.
  6. Explore vector search sample implementations

    main

    The 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 as Hotel.cs, Address.cs, and Location.cs.
  7. Understand the Image serving for agentic retrieval workflow

    main

    The image-serving workflow for agentic retrieval (preview) follows these conceptual steps:

    1. 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.
    2. Indexing: Azure AI Search stores the extracted images in an asset store and maintains image_path references within the generated index.
    3. 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, and TotalImageSizeBytes.
    • Asset Integrity: The selected blob contains valid bytes and has an image/* content type.
  8. Quickstart: Keyword search in Azure AI Search using C#

    main
    This 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.
  9. Quickstart: Semantic ranking in Azure AI Search using C#

    main

    This 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 the hotels-sample index) by adding a semantic configuration.
    • QueryIndex: A project that executes semantic queries against the configured index.
  10. Explore Azure AI Search C# sample scenarios

    main

    The repository contains several specialized samples covering different search patterns and advanced features:

    • Agentic Retrieval: quickstart-agentic-retrieval sets up a knowledge base to integrate LLM reasoning into query planning.
    • Full-text Search: quickstart-keyword-search is a console application demonstrating fundamental tasks: creating an index, loading data, and querying (using a subset of the Hotels dataset).
    • Semantic Ranking: quickstart-semantic-ranking demonstrates how to add semantic ranking to an existing index and formulate semantic queries.
    • Vector Search: quickstart-vector-search creates an index with vectorized descriptions and demonstrates vector queries.
    • AI Enrichment: tutorial-ai-enrichment implements 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-example demonstrates managed ingestion and compares retrieval with image serving enabled vs disabled, including querying and downloading indexed images from Azure Blob Storage.