Azure AI Search (formerly Azure Cognitive Search) is Microsoft's managed search service and the default retrieval layer behind Azure OpenAI's "On Your Data" and AI Foundry RAG workflows. It supports full-text (BM25), vector, semantic reranking, and hybrid search in a single index, with built-in skillsets that call other Azure AI services (OCR, language, vision) during ingestion.
Edm.String, Collection(Edm.Single) for vectors, etc.) and attributes (searchable, filterable, sortable, facetable, retrievable, key).
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
SearchIndex, SearchField, SearchFieldDataType, SimpleField, SearchableField,
VectorSearch, HnswAlgorithmConfiguration, VectorSearchProfile,
SemanticConfiguration, SemanticField, SemanticPrioritizedFields, SemanticSearch,
)
from azure.core.credentials import AzureKeyCredential
client = SearchIndexClient("https://myco-search.search.windows.net", AzureKeyCredential(""))
index = SearchIndex(
name="hr-policies",
fields=[
SimpleField(name="id", type=SearchFieldDataType.String, key=True),
SearchableField(name="title", type=SearchFieldDataType.String),
SearchableField(name="content", type=SearchFieldDataType.String, analyzer_name="en.microsoft"),
SearchField(
name="content_vector",
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
searchable=True,
vector_search_dimensions=1536,
vector_search_profile_name="hnsw-default",
),
],
vector_search=VectorSearch(
algorithms=[HnswAlgorithmConfiguration(name="hnsw")],
profiles=[VectorSearchProfile(name="hnsw-default", algorithm_configuration_name="hnsw")],
),
semantic_search=SemanticSearch(configurations=[
SemanticConfiguration(
name="default",
prioritized_fields=SemanticPrioritizedFields(
title_field=SemanticField(field_name="title"),
content_fields=[SemanticField(field_name="content")],
),
)
]),
)
client.create_or_update_index(index)
from azure.search.documents import SearchClient
from azure.search.documents.models import VectorizedQuery
from openai import AzureOpenAI
aoai = AzureOpenAI(azure_endpoint="...", api_key="...", api_version="2024-10-21")
def embed(text: str) -> list[float]:
return aoai.embeddings.create(model="embedding-3-large-prod", input=[text]).data[0].embedding
search = SearchClient("https://myco-search.search.windows.net", "hr-policies", AzureKeyCredential(""))
results = search.search(
search_text="parental leave for new parents", # BM25 side
vector_queries=[VectorizedQuery( # vector side
vector=embed("parental leave for new parents"),
k_nearest_neighbors=50,
fields="content_vector",
)],
query_type="semantic", # turns on semantic reranker
semantic_configuration_name="default",
top=5,
select=["id", "title", "content"],
)
for r in results:
print(f"{r['@search.reranker_score']:.3f} {r['title']}")
Point an indexer at a data source, attach a skillset that chunks + embeds, and Azure AI Search handles ingestion end-to-end.
{
"name": "hr-skillset",
"skills": [
{
"@odata.type": "#Microsoft.Skills.Text.SplitSkill",
"textSplitMode": "pages",
"maximumPageLength": 2000,
"pageOverlapLength": 300,
"inputs": [{"name": "text", "source": "/document/content"}],
"outputs": [{"name": "textItems", "targetName": "chunks"}]
},
{
"@odata.type": "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill",
"resourceUri": "https://myco.openai.azure.com",
"deploymentId": "embedding-3-large-prod",
"modelName": "text-embedding-3-large",
"context": "/document/chunks/*",
"inputs": [{"name": "text", "source": "/document/chunks/*"}],
"outputs": [{"name": "embedding", "targetName": "chunk_vector"}]
}
]
}
user_groups = ["hr-admin", "all-employees"]
filter_expr = " or ".join(f"acl_groups/any(g: g eq '{g}')" for g in user_groups)
results = search.search(
search_text="termination policy",
filter=filter_expr,
top=10,
)