Stage 8, Vector and hybrid search
Optional stretch
This stage sits outside the two-hour budget. Nothing in Stages 0 to 7 depends on it, and the workshop is complete without it. Run it if your room is ahead of schedule, take it home as homework, or use it as a follow-up session.
At a glance
| Start state | End state | Fallback baseline |
|---|---|---|
| An enriched index with lexical and semantic search | The same index also answering vector and hybrid queries | Stage 8 vector index + skillset + indexer |
Learning goals
- Add a vector field, a vector search algorithm, and a vectorizer to an index that already holds data.
- Embed record content at ingestion time with the
AzureOpenAIEmbeddingskill, so you never compute an embedding by hand. - Run the same question three ways (lexical, vector, hybrid) and say concretely which one wins and why.
Why it matters
Lexical search matches words. Semantic ranking, from Stage 4, reorders those word matches by meaning, but it can only reorder what lexical search already found. The archive has records about a cooling unit failing, a radiator that runs all day, and a draughty reception desk. Ask it about office temperature and lexical retrieval never surfaces any of them, because not one of those records contains that word, so there is nothing for semantic ranking to promote.
Vector search fixes the recall problem: it retrieves by meaning in the first place. Hybrid search runs both and fuses the results, which in practice beats either one alone. This is the part of Azure AI Search most people mean when they say "AI search", and it is the natural next step after everything you built today.
What you will build
A contentVector field on your existing index, an HNSW vector-search configuration with an Azure OpenAI vectorizer (so queries get embedded for you), an AzureOpenAIEmbedding skill added to your Stage 5 skillset, one more output field mapping, and a reset-and-rerun of the indexer.
Knowledge-share outline
- What an embedding is: text as a point in space, where distance means similarity.
- Integrated vectorization: the indexer embeds documents at write time, the vectorizer embeds the query at read time, and both use the same model so the numbers are comparable.
- Why hybrid (lexical + vector, fused) beats either alone, and where semantic ranking sits on top of it.
How this extends the pipeline
The skill embeds documents when the indexer runs. The vectorizer embeds your query when you search. They must point at the same deployment, or the vectors are not comparable and results are nonsense.
Session values you need
The Foundry endpoint is the same shared resource for every attendee (for example https://aif-dmsearch-xxxxxx.services.ai.azure.com/); look up the real value, plus the two embedding names, on the Session values page:
| Placeholder below | Value |
|---|---|
<embedding-deployment-name> | The embedding deployment name, for example embed-workshop |
<embedding-base-model-name> | The base model, for example text-embedding-3-small |
Dimensions must match the model exactly
text-embedding-3-small produces 1536 dimensions; text-embedding-3-large produces 3072. The dimensions value on the field, the skill, and the model have to agree. If they do not, the indexer fails on every single document with a dimension-mismatch error.
Lab steps
1. Add the vector field and vector configuration
Open Indexes > tNN-pNN-corporate-index > Edit JSON.
Add one field to the end of the fields array. Note it is not retrievable: you almost never want 1536 floats coming back in your results payload, and leaving it off keeps responses small.
{
"name": "contentVector",
"type": "Collection(Edm.Single)",
"searchable": true,
"filterable": false,
"facetable": false,
"sortable": false,
"retrievable": false,
"dimensions": 1536,
"vectorSearchProfile": "corporate-vector-profile"
}Then add a vectorSearch block as a sibling of "fields" (next to the semantic block you added in Stage 4):
"vectorSearch": {
"algorithms": [
{ "name": "corporate-hnsw", "kind": "hnsw",
"hnswParameters": { "metric": "cosine", "m": 4, "efConstruction": 400, "efSearch": 500 } }
],
"vectorizers": [
{ "name": "corporate-vectorizer", "kind": "azureOpenAI",
"azureOpenAIParameters": {
"resourceUri": "https://aif-dmsearch-xxxxxx.services.ai.azure.com/",
"deploymentId": "<embedding-deployment-name>",
"modelName": "<embedding-base-model-name>"
} }
],
"profiles": [
{ "name": "corporate-vector-profile", "algorithm": "corporate-hnsw",
"vectorizer": "corporate-vectorizer" }
]
}The three pieces chain together: the field names a profile, the profile names an algorithm (how to index and search the vectors) and a vectorizer (how to embed query text), and the vectorizer names the deployment. Save.
Reference copy: definitions/vector-index.template.json.
2. Add the embedding skill
Open Skillsets > tNN-pNN-corporate-skillset and add this skill to the skills array, alongside the two from Stage 5:
{
"@odata.type": "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill",
"name": "content-embedding",
"description": "Embed record content so the index can answer vector and hybrid queries.",
"context": "/document",
"resourceUri": "https://aif-dmsearch-xxxxxx.services.ai.azure.com/",
"deploymentId": "<embedding-deployment-name>",
"modelName": "<embedding-base-model-name>",
"dimensions": 1536,
"inputs": [ { "name": "text", "source": "/document/content" } ],
"outputs": [ { "name": "embedding", "targetName": "contentVector" } ]
}Like every other dependency in this workshop, it reaches the model through the Search service's managed identity. No key appears anywhere. Save.
Reference copy: definitions/vector-skillset.template.json.
3. Map the skill output into the field
Open Indexers > tNN-pNN-corporate-indexer > Edit JSON and add one entry to outputFieldMappings:
{ "sourceFieldName": "/document/contentVector", "targetFieldName": "contentVector" }4. Reset and rerun
Same rule as Stage 5: existing documents were indexed before the embedding skill existed, so they carry no vector. Reset the indexer, then Run it, and wait for 132 documents to succeed.
This run is slower than the Stage 5 one, because every record now also makes an embedding call.
5. Query three ways
Use Search explorer on your index, then select View > JSON view, just as in the earlier stages. For each query, replace the entire request with the JSON shown and select Search so previous filters, vector queries, or semantic settings do not carry over.
Lexical only — the baseline you already know:
{
"search": "printer breakdown",
"queryType": "simple",
"select": "recordId,subject,branch",
"top": 5
}Vector only — note there is no search text at all. The "kind": "text" query is embedded for you by the vectorizer you configured in step 1:
{
"vectorQueries": [
{ "kind": "text", "text": "printer breakdown", "fields": "contentVector", "k": 5 }
],
"select": "recordId,subject,branch"
}Hybrid — both at once. Azure AI Search fuses the two result sets with Reciprocal Rank Fusion:
{
"search": "printer breakdown",
"queryType": "simple",
"vectorQueries": [
{ "kind": "text", "text": "printer breakdown", "fields": "contentVector", "k": 5 }
],
"select": "recordId,subject,branch",
"top": 5
}Hybrid plus semantic ranking — the full stack, reusing your Stage 4 configuration:
{
"search": "printer breakdown",
"vectorQueries": [
{ "kind": "text", "text": "printer breakdown", "fields": "contentVector", "k": 10 }
],
"queryType": "semantic",
"semanticConfiguration": "corporate-semantic",
"select": "recordId,subject,branch",
"top": 5
}6. Find the case that proves the point
Vector search earns its keep on vocabulary mismatch, and the archive has one waiting for you. Several branches logged HR notes about workplace conditions: a cooling unit that failed in the warmest week of the year, a break room radiator nobody can turn off, a boiler still running on its summer schedule. Not one of them uses the word temperature. Ask for it anyway:
{
"vectorQueries": [
{ "kind": "text", "text": "staff unhappy about the office temperature", "fields": "contentVector", "k": 5 }
],
"select": "recordId,subject,branch,recordType"
}Run the same phrase lexically and compare:
{
"search": "staff unhappy about the office temperature",
"queryType": "simple",
"select": "recordId,subject,branch,recordType",
"top": 5
}Lexical retrieval has nothing to match on except the common words, so it comes back with whatever records happen to say staff or office, ranked by term frequency. The vector query returns the workplace-conditions notes. That gap is the entire argument for vector retrieval, and seeing it once on real data is worth more than any explanation.
Expected output
- The indexer run succeeds with 132 documents and no dimension-mismatch errors.
- The vector-only query returns results despite there being no
searchterm. - The hybrid query's top results are a sensible blend: the strong literal matches lexical found, plus topical matches only the vector side retrieved.
- The workplace-conditions query: lexical returns records that merely share a common word, while vector returns the cooling-unit, radiator, and draught notes. The two result sets barely overlap.
Checkpoint
vector-ready: Your index has a populated contentVector field, you can run a vector-only and a hybrid query, and you can name one concrete case from the archive where vector retrieval found a record that lexical search missed.
Fallback baseline
All three edits are pastes, and the finished objects are version-controlled:
Replace {{namespace}}, {{embeddingDeploymentName}}, and {{embeddingModelName}} with your own values, and {{foundryEndpoint}} with the Foundry endpoint from the Session values page (for example https://aif-dmsearch-xxxxxx.services.ai.azure.com/), then reset and run the indexer once.
Troubleshooting
- Every document fails with a dimension mismatch. The
dimensionson the field and on the skill must both equal what the model produces (1536 fortext-embedding-3-small). Field dimensions cannot be changed after creation, so if this one is wrong you have to drop and recreate the field. - The indexer fails calling the embedding deployment. Check
deploymentIdagainst Session values; an embedding deployment name is not the chat deployment name. The managed-identity role (Cognitive Services User) is the same one Stage 5 already used, so if Stage 5 worked, access is not your problem. - The vector query returns nothing. Confirm the indexer actually ran after you added the skill, and that you reset it first. An empty
contentVectorreturns no vector matches and no error. vectorQueriesis rejected. Confirm you are using Search explorer > View > JSON view, not the text search bar, and that you pasted the complete request.- Throttling on the shared Foundry resource. Thirty people re-embedding 132 records at once is a lot of calls. Stagger the reruns across the room rather than retrying in a tight loop.
Optional stretch (on the stretch)
- Add a second vector field over
subjectand query both fields at once. - Compare
"kind": "text"(vectorizer does the work) with passing a raw vector yourself, to see what integrated vectorization is actually saving you. - Weight the vector side of a hybrid query and watch the ranking move.
What we will not cover
- Chunking long documents. These records are short enough to embed whole; real documents need a Text Split skill and a parent/child index design.
- Quantization and storage-reduction options (
scalarQuantization,truncationDimension), which matter at a corpus size this workshop does not reach.