- AI
- RAG
- Azure OpenAI
Building a RAG assistant on Azure OpenAI and Azure AI Search
How a production retrieval-augmented generation assistant fits together on Azure — ingestion and chunking, hybrid vector and semantic search, grounded prompts with sources, chat history, answer modes and the analytics that keep it honest.
An intranet AI assistant is only as good as what it retrieves. The language model is the easy part; the hard parts are getting the right content in front of it, keeping answers honest, and knowing when the assistant is failing. I build features for a retrieval-augmented generation (RAG) assistant on a global pharmaceutical intranet. Here is the architecture pattern and the trade-offs, without anything client-specific.
The shape of the system
- Ingestion — pull content from the source systems, clean it, split it into chunks, create embeddings and index it.
- Retrieval — hybrid keyword and vector search, re-ranked by a semantic ranker, filtered by what the user is allowed to see.
- Generation — a chat model on Azure OpenAI answers from the retrieved passages and cites them.
- Experience — a streaming chat UI with persistent history and feedback.
- Analytics — usage, queries, feedback and escalations, so content gaps get fixed.
Ingestion and chunking
Chunk by document structure — headings and sections — rather than fixed character counts, with a small overlap so context isn't cut mid-thought. Keep rich metadata on every chunk: title, URL, category, last-modified date and access permissions. That metadata powers filtering, citations and freshness.
Generate embeddings with an Azure OpenAI embedding model and store them in a vector field in Azure AI Search. Re-index when content changes, not on a whim: stale answers erode trust faster than missing ones.
Retrieval: hybrid beats pure vector
Pure vector search is great at meaning and bad at exact terms — product codes, acronyms, policy numbers. Azure AI Search lets you run keyword and vector queries together and fuse the results, then apply the semantic ranker to re-order the top candidates. In practice, hybrid retrieval with semantic ranking is a strong default for enterprise content.
Apply security trimming at query time with filters, so a user can never retrieve content they couldn't open in the intranet itself. In an enterprise, this is not optional.
Generation: grounded, cited, humble
- Instruct the model to answer only from the provided passages and to say when it doesn't know.
- Return sources with every answer so users can verify claims in one click.
- Keep the context budget disciplined — more passages is not always better.
- Stream tokens to the UI; perceived speed matters as much as real speed.
Answer modes: Fast and Deep Think
Not every question deserves the same effort. A quick lookup wants low latency; a multi-part policy question wants more context and more reasoning. Offering two modes lets users choose. One way to implement this: a Fast mode that retrieves fewer passages and answers in a single pass, and a Deep Think mode that rewrites the question, retrieves more broadly and uses a more capable reasoning model — slower, but noticeably better on hard questions.
Chat history that helps retrieval
Persist conversations so users can return to them. Follow-up questions like “what about contractors?” are meaningless on their own, so condense the recent history into a standalone query before retrieval. This one step fixes a large share of “the assistant forgot what we were talking about” complaints.
Analytics: the feedback loop
Ship the dashboard with the assistant, not after it. Track usage trends, top queries, thumbs-up and thumbs-down feedback, and questions with no good answer. Route unanswered questions into helpdesk requests. Every failed query becomes a content task — and the assistant improves because the content does.
Privacy
Azure OpenAI runs inside your Azure subscription, and Microsoft doesn't use your prompts or data to train its models. Combined with security trimming, that's usually what an enterprise security review needs to hear first.
Common pitfalls
- Chunks that are too small lose context; chunks that are too large dilute relevance.
- Ignoring permissions until a security review finds it.
- No evaluation set — so every prompt change is a guess.
- Stale indexes that confidently answer from last year's policy.
Want an assistant that answers from your own content — inside Liferay, Spring Boot or React? See how I build AI integrations or start a conversation.