Azure AI Search is a managed search service that supports vector, keyword, and hybrid retrieval. It handles chunking, vectorization, and indexing through integrated pipelines - the retrieval engine underneath Foundry IQ.

Foundry IQ Integration

Azure AI Search is the indexing and retrieval backend for Foundry IQ knowledge bases. When you create a knowledge base in Foundry IQ, it provisions and manages an AI Search index automatically.

You can also use AI Search directly for custom RAG scenarios that need more control than Foundry IQ provides.

ApproachUse When
Foundry IQStandard enterprise knowledge, automatic permission sync, minimal setup
AI Search (direct)Custom retrieval logic, fine-tuned ranking, multi-index strategies, non-Foundry consumers

Problem It Solves

LLMs hallucinate when they lack context. RAG fixes this by retrieving relevant documents before generation. Azure AI Search provides the retrieval engine: it indexes your data, stores embeddings, and returns ranked results that ground LLM responses in facts.

Search Modes

ModeHow It WorksStrengthsWeaknesses
KeywordBM25 term matchingFast, no embeddings neededMisses semantic similarity
VectorCosine similarity on embeddingsCaptures meaning, handles synonymsMisses exact matches
HybridKeyword + Vector combinedBest of both, highest recallSlightly more compute
Hybrid + Semantic RankingHybrid results re-ranked by cross-encoderBest precision for RAGAdds ~50ms latency
ℹ️
Info

For RAG, use hybrid + semantic ranking. It consistently outperforms single-mode retrieval in precision and recall benchmarks.

Architecture

Implementation

Create an index with vector fields

from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    SearchIndex, SearchField, SearchFieldDataType,
    VectorSearch, HnswAlgorithmConfiguration, VectorSearchProfile,
    SemanticConfiguration, SemanticSearch,
    SemanticPrioritizedFields, SemanticField,
)
from azure.identity import DefaultAzureCredential

client = SearchIndexClient(
    endpoint="https://my-search.search.windows.net",
    credential=DefaultAzureCredential()
)

index = SearchIndex(
    name="documents",
    fields=[
        SearchField(name="id", type=SearchFieldDataType.String, key=True),
        SearchField(name="content", type=SearchFieldDataType.String, searchable=True),
        SearchField(name="content_vector",
                    type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
                    searchable=True, vector_search_dimensions=3072,
                    vector_search_profile_name="default-profile"),
        SearchField(name="source", type=SearchFieldDataType.String, filterable=True),
    ],
    vector_search=VectorSearch(
        algorithms=[HnswAlgorithmConfiguration(name="default-hnsw")],
        profiles=[VectorSearchProfile(name="default-profile",
                                       algorithm_configuration_name="default-hnsw")]
    ),
    semantic_search=SemanticSearch(
        configurations=[SemanticConfiguration(
            name="default-semantic",
            prioritized_fields=SemanticPrioritizedFields(
                content_fields=[SemanticField(field_name="content")]
            )
        )]
    )
)

client.create_or_update_index(index)

Index documents with embeddings

from azure.search.documents import SearchClient
from openai import AzureOpenAI

def get_embedding(text: str) -> list[float]:
    response = openai_client.embeddings.create(
        model="text-embedding-3-large", input=text
    )
    return response.data[0].embedding

search_client = SearchClient(
    endpoint="https://my-search.search.windows.net",
    index_name="documents",
    credential=DefaultAzureCredential()
)

documents = [
    {
        "id": "doc-1",
        "content": "Azure AI Search supports vector, keyword, and hybrid search...",
        "content_vector": get_embedding("Azure AI Search supports..."),
        "source": "docs/azure-search.pdf"
    }
]

search_client.upload_documents(documents)

Query with hybrid search + semantic ranking

from azure.search.documents.models import VectorizableTextQuery

results = search_client.search(
    search_text="How does hybrid search work?",
    vector_queries=[
        VectorizableTextQuery(
            text="How does hybrid search work?",
            k_nearest_neighbors=5,
            fields="content_vector"
        )
    ],
    query_type="semantic",
    semantic_configuration_name="default-semantic",
    top=5
)

for result in results:
    print(f"[{result['@search.score']:.3f}] {result['content'][:100]}")

Integrated Vectorization

Azure AI Search can handle chunking and embedding automatically through skillsets - no custom code needed for ingestion.

ℹ️
Info

This eliminates custom chunking pipelines. Configure once, and new documents are automatically chunked, embedded, and indexed when added to Blob Storage.

Chunking Strategy

StrategyChunk SizeOverlapUse Case
Fixed token512 tokens128 tokensGeneral documents
Fixed token1024 tokens256 tokensLong-form technical docs
Page-based1 page0PDFs with clear page boundaries
SemanticVariableN/ADocuments with clear section headers
⚠️
Warning

Smaller chunks = more precise retrieval but less context per chunk. Larger chunks = more context but noisier retrieval. Always use overlap to avoid splitting mid-sentence.

Production Considerations

Scaling

  • Replicas: Add for read throughput and HA (3+ for 99.9% SLA)
  • Partitions: Add for index size (each = 25GB on Standard tier)
  • Tier selection: Basic (15GB, 3 replicas) → Standard (300GB+) → Storage Optimized (2TB+)

Security

  • Managed identity for indexer connections to Blob, SQL, Cosmos DB
  • Private endpoints for network isolation
  • Document-level security with filters on queries
  • RBAC: Search Index Data Reader (query), Search Index Data Contributor (index)
results = search_client.search(
    search_text=query,
    filter=f"allowed_groups/any(g: g eq '{user_group}')",
    top=5
)

Cost Optimization

  • Use integrated vectorization instead of external embedding pipelines
  • Schedule indexers during off-peak hours
  • Use select to return only needed fields (reduces egress)
  • Standard tier handles most workloads - don't over-provision

When to Use vs. Alternatives

  • RAG on Azure (default choice)
  • Need hybrid search (vector + keyword + semantic)
  • Want integrated chunking and vectorization
  • Need enterprise security (RBAC, private endpoints, audit)

Consider Alternatives

  • pgvector: Already on Postgres, simple vector needs, no extra service
  • Pinecone/Weaviate: Real-time vector updates at massive scale
  • Databricks Vector Search: Already on Databricks lakehouse
  • Neo4j: Need graph + vector combined queries