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.
| Approach | Use When |
|---|---|
| Foundry IQ | Standard 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
| Mode | How It Works | Strengths | Weaknesses |
|---|---|---|---|
| Keyword | BM25 term matching | Fast, no embeddings needed | Misses semantic similarity |
| Vector | Cosine similarity on embeddings | Captures meaning, handles synonyms | Misses exact matches |
| Hybrid | Keyword + Vector combined | Best of both, highest recall | Slightly more compute |
| Hybrid + Semantic Ranking | Hybrid results re-ranked by cross-encoder | Best precision for RAG | Adds ~50ms latency |
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.
This eliminates custom chunking pipelines. Configure once, and new documents are automatically chunked, embedded, and indexed when added to Blob Storage.
Chunking Strategy
| Strategy | Chunk Size | Overlap | Use Case |
|---|---|---|---|
| Fixed token | 512 tokens | 128 tokens | General documents |
| Fixed token | 1024 tokens | 256 tokens | Long-form technical docs |
| Page-based | 1 page | 0 | PDFs with clear page boundaries |
| Semantic | Variable | N/A | Documents with clear section headers |
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
selectto return only needed fields (reduces egress) - Standard tier handles most workloads - don't over-provision
When to Use vs. Alternatives
Use Azure AI Search
- 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