INGESTION:
1. Extract — Azure Document Intelligence processes PDFs, Word docs into structured text with layout preservation.
2. Chunk — Split into overlapping chunks (~500 tokens, 10% overlap) to preserve context across boundaries.
3. Embed — Call Azure OpenAI text-embedding-3-small for each chunk; store vectors.
4. Index — Upsert chunks + vectors into Azure AI Search with both keyword (BM25) and vector fields.
RETRIEVAL:
1. Embed the user query with the same embedding model.
2. Hybrid search — run BM25 keyword AND vector similarity in parallel.
3. Reciprocal Rank Fusion (RRF) — merges both result sets, boosting results ranking well in both.
4. Re-rank — cross-encoder on top-N results for semantic precision.
5. Augment — inject top-K chunks into GPT-4o prompt as context.
6. Generate — structured output returns a grounded, cited response.
Key considerations: chunk size tuning, embedding model consistency, conditional LLM calls (skip if cached answer exists), PII scrubbing before ingestion.
var options = new SearchOptions {
VectorSearch = new VectorSearchOptions {
Queries = { new VectorizedQuery(queryEmbedding) {
KNearestNeighborsCount = 10, Fields = { "contentVector" }
}}
},
QueryType = SearchQueryType.Semantic
};
var results = await searchClient.SearchAsync<Doc>(userQuery, options);