Category: Azure AI

  • Azure AI Document Intelligence

    Every organization deals with paperwork — invoices, receipts, contracts, ID cards, tax forms. Extracting data from these documents manually is slow and error-prone. Azure AI Document Intelligence uses machine learning to read, understand, and extract structured data from documents automatically.

    This article covers what the service offers, which models to use for different scenarios, and how to process your first document with just a few lines of code.


    What is Azure AI Document Intelligence?

    Azure AI Document Intelligence (formerly Form Recognizer) is an AI service that extracts text, key-value pairs, tables, and structures from documents. It handles:

    • Scanned PDFs and images (via built-in OCR).
    • Digital PDFs with complex layouts.
    • Photos of receipts, business cards, and forms.
    • Handwritten text in multiple languages.

    Unlike basic OCR that just reads text, Document Intelligence understands the structure of your documents — it knows which text is a header, which values belong to which fields, and how tables are organized.

    Prebuilt models vs. custom models

    The service comes with two categories of models:

    Prebuilt models

    Ready to use with zero training. Microsoft has already trained these on millions of documents:

    ModelWhat it extracts
    InvoiceVendor name, amounts, line items, tax, due date
    ReceiptMerchant, total, items, date, payment method
    ID DocumentName, date of birth, document number, expiration
    W-2 (US tax)Employer info, wages, tax withholdings
    Health Insurance CardMember ID, group number, plan details
    Business CardName, title, company, phone, email, address
    LayoutText, tables, selection marks, document structure
    ReadPlain text extraction (OCR) with line and word positions

    Custom models

    When your documents don’t match any prebuilt model — like internal forms, proprietary reports, or industry-specific paperwork — you can train a custom model using as few as 5 labeled samples.

    Real-world use cases

    Accounts payable automation

    Process incoming invoices automatically: extract vendor, amount, line items, and PO numbers, then push the data into your ERP system. Teams that used to spend hours on manual data entry can process hundreds of invoices in minutes.

    Expense report processing

    Employees snap photos of receipts. Document Intelligence reads the merchant, date, total, and category, then populates the expense report automatically.

    Contract analysis

    Extract key clauses, dates, and parties from contracts. Combine with Azure OpenAI to summarize terms or flag unusual conditions.

    Healthcare intake

    Read insurance cards and patient forms at check-in. Extract member IDs, group numbers, and patient details to reduce front-desk workload and data entry errors.

    Getting started

    Step 1: Create the resource

    1. Go to the Azure Portal and search for “Document Intelligence”.
    2. Click Create.
    3. Choose your subscription, resource group, region, and pricing tier.
    4. Click Review + Create.

    Step 2: Try it in Document Intelligence Studio

    Before writing any code, explore Document Intelligence Studio at documentintelligence.ai.azure.com. Upload a sample document, pick a prebuilt model, and see the extracted data instantly. It’s the fastest way to evaluate whether a prebuilt model fits your documents.

    Step 3: Analyze a document with Python

    Here’s how to extract data from an invoice using Python:

    from azure.ai.documentintelligence import DocumentIntelligenceClient
    from azure.core.credentials import AzureKeyCredential
    
    client = DocumentIntelligenceClient(
        endpoint="https://YOUR-RESOURCE.cognitiveservices.azure.com/",
        credential=AzureKeyCredential("YOUR-API-KEY")
    )
    
    # Analyze an invoice from a URL
    poller = client.begin_analyze_document(
        "prebuilt-invoice",
        analyze_request={"url_source": "https://example.com/invoice.pdf"}
    )
    result = poller.result()
    
    for doc in result.documents:
        print(f"Vendor: {doc.fields['VendorName'].content}")
        print(f"Total: {doc.fields['InvoiceTotal'].content}")
        print(f"Date:  {doc.fields['InvoiceDate'].content}")
    
        if "Items" in doc.fields:
            for item in doc.fields["Items"].value:
                desc = item.value["Description"].content
                amount = item.value["Amount"].content
                print(f"  - {desc}: {amount}")

    Install the SDK:

    pip install azure-ai-documentintelligence

    Step 4: Extract tables and layout

    For documents that don’t match a prebuilt model, the Layout model extracts all text, tables, and structure:

    poller = client.begin_analyze_document(
        "prebuilt-layout",
        analyze_request={"url_source": "https://example.com/report.pdf"}
    )
    result = poller.result()
    
    # Extract tables
    for table in result.tables:
        print(f"Table: {table.row_count} rows x {table.column_count} columns")
        for cell in table.cells:
            print(f"  [{cell.row_index},{cell.column_index}] {cell.content}")

    Combining with Azure OpenAI

    Document Intelligence and Azure OpenAI are a powerful combination. A common pattern:

    1. Extract text and tables from a PDF using Document Intelligence.
    2. Send the extracted content to GPT-4o with a prompt like “Summarize this contract” or “Find all penalties and deadlines.”
    3. Get structured, actionable output that would have taken hours to compile manually.

    This is especially effective for contracts, financial reports, and regulatory filings where you need both extraction accuracy and natural language understanding.

    Pricing overview

    ModelPrice per page (approx.)
    Read (OCR)$0.001
    Layout$0.01
    Prebuilt (Invoice, Receipt, etc.)$0.01
    Custom$0.03 (training is free for first model)

    At these prices, processing 1,000 invoices costs about $10. Compare that to the cost of manual data entry and the ROI becomes obvious.

    Next steps

    1. Open Document Intelligence Studio and upload a real document to see extraction results instantly.
    2. Start with a prebuilt model — invoices and receipts cover the most common automation scenarios.
    3. Train a custom model if your document type isn’t covered — 5 samples is all you need to start.
    4. Read the official docs: learn.microsoft.com/azure/ai-services/document-intelligence

    Conclusion

    Azure AI Document Intelligence eliminates the tedious work of reading and typing data from documents. Whether you’re processing 10 invoices a week or 10,000, the service scales to match your workload. Combined with Azure OpenAI, it turns raw documents into structured, actionable data — the kind of automation that delivers measurable ROI from day one.

    Next up, we’ll explore Copilot Studio, Microsoft’s platform for building custom AI assistants without writing code.

    What documents are slowing your team down? Share your document processing challenge in the comments and let’s figure out the right approach together.
  • Azure AI Search & RAG

    Imagine asking a question in plain English and getting an accurate answer pulled directly from your company’s own documents. That’s the power behind Retrieval-Augmented Generation (RAG), and Azure AI Search is the service that makes it possible at scale on Microsoft Azure.

    In this guide, you’ll learn what Azure AI Search is, how RAG works, and how to build your first search-powered AI solution.


    What is Azure AI Search?

    Azure AI Search (formerly Azure Cognitive Search) is a fully managed search service on Azure. It goes far beyond traditional keyword search by offering:

    • Full-text search: classic keyword matching with filters, facets, and scoring profiles.
    • Vector search: find results based on meaning, not just exact words.
    • Hybrid search: combine keyword and vector search for the best of both worlds.
    • Semantic ranking: a built-in AI layer that re-ranks results by relevance.
    • Integrated vectorization: automatically generate embeddings from your content using Azure OpenAI.

    Think of it as the intelligent retrieval engine sitting between your data and your AI models.

    What is RAG and why does it matter?

    RAG stands for Retrieval-Augmented Generation. It’s a pattern that solves one of the biggest challenges with large language models: they don’t know your private data.

    Here’s how it works:

    1. The user asks a question (e.g., “What’s our refund policy for enterprise clients?”).
    2. The system searches your documents using Azure AI Search to find the most relevant content.
    3. The retrieved content is sent to a language model (like GPT-4o) along with the question.
    4. The model generates a grounded answer based on your actual documents, not its general training data.

    The result? Accurate, up-to-date answers that cite your own sources, with far fewer hallucinations.

    RAG vs. fine-tuning: when to use each

    AspectRAGFine-tuning
    Best forAnswering questions over your documentsChanging the model’s tone, format, or behavior
    Data freshnessAlways current (search index is updated)Frozen at training time
    Setup complexityModerate (index + prompt engineering)High (training pipeline + compute)
    CostSearch service + token usageTraining compute + token usage
    Hallucination riskLower (grounded in retrieved docs)Higher without retrieval

    For most enterprise use cases, RAG is the recommended starting point. Fine-tuning is complementary, not a replacement.

    Key components of a RAG solution on Azure

    1. Data sources

    Azure AI Search can pull data from Azure Blob Storage, Azure SQL Database, Cosmos DB, SharePoint, and many other sources using built-in indexers.

    2. Search index

    Your data is processed and stored in a search index. During indexing, you can apply skillsets that enrich the data — extract text from PDFs, detect languages, split documents into chunks, and generate vector embeddings.

    3. Query pipeline

    When a user asks a question, the query is converted into a vector (using the same embedding model), and Azure AI Search retrieves the most relevant chunks using hybrid search.

    4. Language model

    The retrieved chunks are passed to Azure OpenAI (GPT-4o or similar) as context, and the model generates a natural language answer.

    Setting up your first RAG pipeline

    Step 1: Create an Azure AI Search resource

    1. Go to the Azure Portal (portal.azure.com).
    2. Search for “AI Search” and click Create.
    3. Select your subscription, resource group, and region.
    4. Choose a pricing tier (Free works for testing, Basic for small production workloads).
    5. Click Review + Create.

    Step 2: Upload your documents

    Upload your files (PDFs, Word docs, text files) to an Azure Blob Storage container. This will be your data source.

    Step 3: Create an index with integrated vectorization

    In the Azure portal, use the “Import and vectorize data” wizard on your AI Search resource. It will:

    • Connect to your Blob Storage.
    • Chunk your documents automatically.
    • Generate embeddings using an Azure OpenAI embedding model.
    • Create the search index with both text and vector fields.

    Step 4: Query with Python

    from azure.search.documents import SearchClient
    from azure.core.credentials import AzureKeyCredential
    
    client = SearchClient(
        endpoint="https://YOUR-SEARCH-SERVICE.search.windows.net",
        index_name="your-index",
        credential=AzureKeyCredential("YOUR-API-KEY")
    )
    
    results = client.search(
        search_text="refund policy for enterprise",
        top=3,
        query_type="semantic",
        semantic_configuration_name="my-semantic-config"
    )
    
    for result in results:
        print(result["chunk"], result["@search.score"])

    Step 5: Connect to Azure OpenAI for the full RAG flow

    import openai
    
    # 1. Retrieve relevant chunks (from the search above)
    context = "\n\n".join([r["chunk"] for r in results])
    
    # 2. Send to Azure OpenAI with the retrieved context
    ai_client = openai.AzureOpenAI(
        api_key="YOUR-OPENAI-KEY",
        api_version="2024-10-21",
        azure_endpoint="https://YOUR-RESOURCE.openai.azure.com/"
    )
    
    response = ai_client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": f"Answer using only this context:\n\n{context}"},
            {"role": "user", "content": "What's the refund policy for enterprise clients?"}
        ]
    )
    
    print(response.choices[0].message.content)

    To install the required libraries:

    pip install azure-search-documents openai

    Pricing overview

    TierMonthly cost (approx.)Best for
    Free$0Learning and prototyping (50 MB, 3 indexes)
    Basic~$75 USDSmall production workloads (2 GB, 15 indexes)
    Standard S1~$250 USDMedium workloads with semantic ranking

    Vector search and semantic ranking are included at no extra charge on Basic and above. Embedding generation costs depend on your Azure OpenAI pricing.

    Next steps

    1. Try the “Import and vectorize data” wizard in the Azure portal — it’s the fastest way to see RAG in action.
    2. Explore Azure AI Studio: it provides a visual RAG pipeline builder with built-in chat evaluation.
    3. Experiment with chunking strategies: document splitting has a big impact on answer quality.
    4. Check the official docs: learn.microsoft.com/azure/search

    Conclusion

    Azure AI Search combined with RAG lets you build AI solutions that actually know your data. Instead of hoping a language model has the right answer, you give it the right context. It’s the most practical way to bring generative AI into your organization without exposing sensitive data or dealing with hallucinations.

    In the next article, we’ll look at Azure AI Document Intelligence, the service that extracts structured data from forms, invoices, and documents automatically.

    Ready to build your first RAG app? Drop a comment with your use case and I’ll point you in the right direction.