6: Implement knowledge mining and information extraction solutions

    Provision an Azure AI Search resource, create an index, and define a skillset

    Azure AI Search is the retrieval substrate for every knowledge mining workload on Microsoft Foundry. The service provides three primary objects that you must provision in order: a search service (the regional resource that holds capacity), an index (the schema and the inverted, vector, and semantic stores), and a skillset (the directed graph of cognitive transformations applied to each document during ingestion). A data source and an indexer connect these objects together, but the index and skillset are the design surface where most architectural decisions land. Getting them right matters because the index is mutable in only narrow ways after creation, and the skillset shapes every downstream field including the ones that feed retrieval-augmented generation flows defined in earlier chapters.

    The service tier is the first decision. Basic and Standard S1, S2, S3 tiers are general-purpose, with replicas adding query throughput and partitions adding storage and indexing throughput. Storage Optimized L1 and L2 trade query latency for cheaper per-gigabyte storage and suit archive search. Free F0 is one partition and one replica and is intended for proof of concept only. The high-density tiers like S3 HD pack many small indexes into one search service for multi-tenant SaaS patterns where each tenant gets a dedicated index. The semantic ranker is a paid add-on at the service level and is billed separately from base capacity; you turn it on with a single property and you keep it bounded with a documented monthly free-tier quota of low-volume queries before paid usage begins.

    After the service exists, you create an index. The index defines fields with names, types, and attributes that determine which subset of the search engine each field participates in. The attribute searchable enrolls a string field in the full-text inverted index; filterable enables $filter predicates; sortable enables $orderby; facetable enables faceted aggregation; retrievable allows the field to be returned in result documents; key marks the single string key field that every document must populate uniquely. Vector fields declare a dimensions value and a vector search profile that selects an algorithm and a vectorizer; the profile points to a configuration that names either HNSW or exhaustive KNN. Complex fields and collections nest sub-fields under a single field path and are queried with dotted paths and any/all lambda syntax.

    The skillset is a JSON description of cognitive enrichments. Each skill is a node with an input mapping, an output mapping, a context expression that names the iteration target (the root document, an array of pages, an array of tokens), and a skill-specific configuration. The built-in catalog covers OCR, text split, entity recognition, language detection, key phrase extraction, sentiment, PII detection, image analysis 4.0 features, vector embeddings, and document extraction. The Document Intelligence layout skill, named DocumentIntelligenceLayoutSkill in the skill catalog, sends pages to the prebuilt layout model and returns structured Markdown plus tables and paragraphs that downstream skills can chunk. The Azure OpenAI Embedding skill calls a deployed embedding model and writes a vector field. Custom skills extend the catalog with a WebApi endpoint and follow a fixed input and output envelope covered in section 3.

    💡 Exam Trap: Vector search requires a numeric vector field, which has type Collection(Edm.Single) (32-bit floats), Collection(Edm.Half) (16-bit floats), Collection(Edm.Byte) (8-bit signed integers), or Collection(Edm.SByte) for scalar quantization, paired with a dimensions value and a vectorSearchProfile reference. Using Collection(Edm.Double) or omitting the profile leaves the field non-vector and queries that target it return BM25 ranks, not cosine similarity.

    💡 Exam Trap: The key attribute can only be set on one field per index and that field must be a Edm.String. Document Intelligence and indexer outputs often emit IDs as integers; you must cast them to string with a Shaper skill output or with the Edm.String data-type expectation in the indexer field mappings, otherwise the indexer fails on the first document.

    📊 Limit: A single index supports up to 1,000 fields in total, including subfields of complex collections counted with their parents, and the public REST API caps individual document payload at 16 MB. Vector fields count toward the total but enforce additional per-tier dimension and document-count ceilings that vary by SKU and are published in the search-service-limits documentation page.

    ⚠️ Anti-Pattern: Building one giant flat index with 800 mostly empty fields to accommodate optional schema branches. Sparse indexes inflate storage cost, hurt indexing throughput, and produce noisy facets. Split into multiple indexes routed by document type, or model the branches as a Collection(Edm.ComplexType) with type and value subfields and query with lambda predicates.

    Use prebuilt models to extract data from documents

    Document Intelligence ships prebuilt models that accept binary input and return strongly typed structured fields. The prebuilt-layout model extracts pages, lines, words, tables, paragraphs, selection marks, and Markdown that downstream chunking treats as ground truth structure. The prebuilt-read model is OCR only and returns text plus word-level polygons. The domain-specific prebuilt catalog includes invoice, receipt, ID document, US tax forms (W-2, 1098, 1099, 1040, W-4, 1095 family), business card, contract, credit card, health insurance card, marriage certificate, mortgage documents (1003 and 1008), check, and bank statement; each returns model-specific field paths under documents[].fields[].valueObject with confidence scores attached to every field.

    When the source repository is uniformly invoices or receipts, calling the prebuilt model directly during indexing is the right architecture. Azure AI Search provides the DocumentIntelligenceLayoutSkill for layout, and you can call other prebuilt models from a custom skill that wraps the Document Intelligence REST analyze endpoint. The end-to-end flow inside a skillset reads a binary file from a blob data source, runs the prebuilt model, extracts the fields, and projects them into typed index fields or into a knowledge store table for downstream BI.

    # Provision a search service with semantic ranker enabled and managed identity
    az search service create \
     --name foundry-km-search \
     --resource-group foundry-km-rg \
     --location eastus2 \
     --sku standard \
     --partition-count 1 \
     --replica-count 2 \
     --semantic-search standard \
     --identity-type SystemAssigned \
     --public-network-access disabled
    
    {
     "name": "invoices-index",
     "fields": [
     { "name": "id", "type": "Edm.String", "key": true, "filterable": true },
     { "name": "vendorName", "type": "Edm.String", "searchable": true, "filterable": true, "facetable": true },
     { "name": "invoiceTotal", "type": "Edm.Double", "filterable": true, "sortable": true },
     { "name": "invoiceDate", "type": "Edm.DateTimeOffset", "filterable": true, "sortable": true },
     { "name": "content", "type": "Edm.String", "searchable": true, "analyzer": "en.microsoft" },
     { "name": "contentVector", "type": "Collection(Edm.Single)", "searchable": true,
     "dimensions": 1536, "vectorSearchProfile": "hnsw-default" },
     { "name": "lineItems", "type": "Collection(Edm.ComplexType)", "fields": [
     { "name": "description", "type": "Edm.String", "searchable": true },
     { "name": "amount", "type": "Edm.Double", "filterable": true },
     { "name": "quantity", "type": "Edm.Double", "filterable": true }
     ]}
     ],
     "vectorSearch": {
     "algorithms": [
     { "name": "hnsw-eucl", "kind": "hnsw",
     "hnswParameters": { "m": 4, "efConstruction": 400, "efSearch": 500, "metric": "cosine" } }
     ],
     "profiles": [
     { "name": "hnsw-default", "algorithm": "hnsw-eucl", "vectorizer": "aoai-embeddings" }
     ],
     "vectorizers": [
     { "name": "aoai-embeddings", "kind": "azureOpenAI",
     "azureOpenAIParameters": {
     "resourceUri": "https://foundry-aoai.openai.azure.com",
     "deploymentId": "text-embedding-3-small",
     "modelName": "text-embedding-3-small"
     }
     }
     ]
     },
     "semantic": {
     "configurations": [
     { "name": "default",
     "prioritizedFields": {
     "titleField": { "fieldName": "vendorName" },
     "contentFields": [{ "fieldName": "content" }],
     "keywordsFields": []
     }
     }
     ]
     }
    }
    
    # Define a skillset that uses the prebuilt layout model and then embeds chunks
    from azure.search.documents.indexes import SearchIndexerClient
    from azure.search.documents.indexes.models import (
     SearchIndexerSkillset,
     DocumentIntelligenceLayoutSkill,
     SplitSkill,
     AzureOpenAIEmbeddingSkill,
     InputFieldMappingEntry,
     OutputFieldMappingEntry,
    )
    from azure.identity import DefaultAzureCredential
    
    client = SearchIndexerClient(
     endpoint="https://foundry-km-search.search.windows.net",
     credential=DefaultAzureCredential(),
    )
    
    layout = DocumentIntelligenceLayoutSkill(
     name="di-layout",
     description="Run Document Intelligence layout for structured Markdown and tables",
     context="/document",
     output_mode="oneToMany",
     markdown_header_depth="h3",
     inputs=[InputFieldMappingEntry(name="file_data", source="/document/file_data")],
     outputs=[
     OutputFieldMappingEntry(name="markdown_document", target_name="markdownChunks"),
     ],
    )
    
    split = SplitSkill(
     name="chunk-pages",
     text_split_mode="pages",
     maximum_page_length=2000,
     page_overlap_length=200,
     context="/document/markdownChunks/*",
     inputs=[InputFieldMappingEntry(name="text", source="/document/markdownChunks/*/content")],
     outputs=[OutputFieldMappingEntry(name="textItems", target_name="pages")],
    )
    
    embed = AzureOpenAIEmbeddingSkill(
     name="embed-pages",
     resource_url="https://foundry-aoai.openai.azure.com",
     deployment_id="text-embedding-3-small",
     model_name="text-embedding-3-small",
     dimensions=1536,
     context="/document/markdownChunks/*/pages/*",
     inputs=[InputFieldMappingEntry(name="text", source="/document/markdownChunks/*/pages/*")],
     outputs=[OutputFieldMappingEntry(name="embedding", target_name="vector")],
    )
    
    client.create_or_update_skillset(SearchIndexerSkillset(
     name="invoices-ss",
     description="Layout, split, embed",
     skills=[layout, split, embed],
    ))
    

    Provisioning the search service over a managed identity is the supported authentication path for indexers that pull from blob storage, Cosmos DB, SQL Database, or ADLS Gen2 within a virtual network. The data plane API for index and skillset CRUD also supports Microsoft Entra ID via the Search Index Data Contributor and Search Service Contributor roles assigned to a user, group, or service principal. Network isolation pairs a private endpoint on the search service with a shared private link resource for each downstream data source, which is the architecture that satisfies enterprise compliance requirements without forcing public network access on either side.

    🎯 Scenario: A claims processing team receives 50,000 PDFs per week, each one of three contract templates. They need to retrieve clauses by semantic similarity and filter by contract type. The right architecture provisions a single Standard S1 service with semantic ranker enabled, one index per contract type to avoid sparse fields, a layout-driven skillset that emits Markdown and chunks, and an Azure OpenAI Embedding skill that writes a 1536-dimension vector field. Query routing chooses the index by classifier output, falling back to a federated multi-index query when type is uncertain.

    Decision Anchor: Choose Standard S1, S2, or S3 when query latency and indexer throughput matter and storage is moderate. Choose Storage Optimized L1 or L2 when the index exceeds a terabyte and query latency tolerance is in the hundreds of milliseconds. Choose Basic only for development or low-volume single-index workloads, and never use Free F0 for production because semantic ranker, customer-managed keys, and shared private link are not available on that tier.


    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Microsoft - AI-102 learning hub.