Overview

3 Search service ingestion

This chapter challenges the assumption that vectors and embeddings are mandatory for RAG. The core objective is not “find the most similar embedding,” but “retrieve the right passage of text.” Mature text search excels at messy, human queries with tools like filters, fuzzy matching, typo tolerance, and semantic ranking, and hybrid search (keywords plus vectors) often outperforms vector-only approaches in accuracy and debuggability. The authors focus on Azure AI Search because it reliably delivered fast, precise retrieval at scale in their experience, while acknowledging viable alternatives and trade-offs. Compared with rigid and slow SQL lookups on large datasets, a dedicated search service yields quicker, more flexible results; however, it comes with setup complexity, costs, and isn’t meant for analytical aggregations.

The chapter then walks through ingesting structured SQL data into a search index designed for hybrid retrieval. You create an index with key text fields (for example, product name, description, specs, manufacturer), a combined Summary field, and a Vector field sized to the embedding model (1536 dimensions). Field capabilities (retrievable, filterable, sortable, facetable, searchable) are chosen deliberately, and cosine similarity with exhaustive KNN is selected for small datasets. An ingestion pipeline processes records in batches: fetch from SQL, summarize the row into a coherent string, clean problematic characters, generate embeddings (for example, text-embedding-3-small with 1536 dimensions), and merge-or-upload the document (ID, original fields, summary, vector, and DateModified) to Azure AI Search. The workflow includes progress tracking, options for asynchronous embedding to speed up large jobs, and careful credential management.

With data loaded, you query using hybrid search: embed the user query for semantic matching while also running a keyword query to capture exact and partial term matches, then combine and rank the results. Practical features include OData filters (to narrow by attributes like manufacturer), field selection (to reduce payloads and token usage), and enforcing stable ordering (for consistent user experiences) by sorting on a chosen field or relevance score. The chapter also covers operational upkeep: scheduled updates for newly created or modified records, and a “soft delete” pattern (a Deleted flag) that triggers removal from the index by ID without reprocessing. Finally, the same principles extend to unstructured content by indexing per-page text from PDFs (plus embeddings and metadata), and even to images or video via multimodal-generated descriptions that are embedded and stored—ensuring a robust, maintainable retrieval layer that reliably surfaces the right text for RAG.

This flowchart shows the key stages of the RAG pipeline. The focus is on Search service ingestion (dashed circle), where raw data is preprocessed and embedded before being added to Azure AI Search for semantic search. This step bridges the transition from data preparation to retrieval.
A correctly set-up Azure AI Search Index. Make sure to set the Retrievable, Filterable, Sortable, Facetable, and Searchable columns exactly as shown in this image.
Workflow for ingesting structured SQL data into Azure AI Search. The process begins by connecting to an SQL database and fetching records in batches. Each batch is summarized, cleaned, embedded, and prepared as documents for upload. The pipeline loops through remaining records until all data is processed and uploaded.
Converting an SQL record into a vector embedding. The process begins by transforming the raw SQL record into a natural language string summary. This summary is then passed through an embedding model to generate a vector representation, which can be used for vector search.
The iterative process for handling SQL records. The loop starts by connecting to the database and fetching the next batch of records. Each batch is summarized and embedded, with a counter updated to track progress. If no more records remain, the loop breaks, and resources like the cursor and connection are closed to ensure efficiency.
Illustration of user confusion caused by inconsistent search result ordering. Two identical searches for "pet games" return the same items in a different order, leading to contradictory responses from the writer agent. This highlights the importance of consistently ranked search results to ensure clarity and user trust.
Workflow for updating records in AI Search. A weekly timer trigger initiates the process, selecting only the records that have been updated in the past week. These records are processed and then sent to AI Search, ensuring the system remains up-to-date with the latest data.
Process for handling "soft delete" records in AI Search. The workflow begins by checking the database for records marked as "Deleted." For each deleted record, its ID is retrieved and used to instruct AI Search to remove that entry from the index, ensuring the search index matches the source database.

Summary

  • Azure AI Search may be more effective than many traditional vector databases. By combining text search, vector search, and natural language processing, Azure AI Search delivers results that are typically more relevant and precise.
  • Setting up an Azure AI Search service and creating an appropriate search index requires defining the right fields for the data. This setup includes adding a vector field of the correct dimensionality and configuring vector search profiles to leverage both text and vector searches.
  • Structured data like SQL records must first be transformed into text that is optimized for retrieval. This transformation involves summarizing the records, removing any unnecessary characters, and generating embeddings that capture the semantic meaning of the data.
  • Uploading processed and embedded SQL records into Azure AI Search enables a hybrid search function that combines vector similarity with semantic understanding. This approach allows more efficient and accurate retrieval than relying on keyword matching or vector matching alone.
  • Maintaining a synchronized search index is crucial when handling frequent data changes. Implementing code to update modified records and remove deleted ones in Azure AI Search ensures that the index remains current.

FAQ

Do I have to use vectors and embeddings for RAG?No. The goal in RAG is to retrieve the right text, not the most similar vector. If a keyword or SQL search reliably finds the correct context, use that. Pure vector search often misses relevant passages; hybridizing with traditional text search usually yields better accuracy and stability.
Why transform SQL records into a single text summary and upload them to a search service?SQL is fast for structured, exact lookups but slow and rigid for fuzzy, human-language queries at scale. A search service like Azure AI Search supports typo tolerance, synonyms, and semantic ranking, returning relevant results quickly. Summaries make each row easier to embed and search semantically while preserving keyword searchability.
How should I design my Azure AI Search index for product-style records?- ProductName: retrievable, filterable, sortable, searchable - ProductDescription: retrievable, searchable - TechnicalSpecifications: retrievable, searchable - Manufacturer: retrievable, filterable, sortable, facetable - Summary: retrievable, searchable - DateModified: retrievable, filterable, sortable - Vector: collection(Edm.Single), dimensions 1536, not retrievable This setup enables both keyword and vector queries plus useful filtering and sorting.
What embedding size and model should I use, and why 1536 dimensions?Use embeddings that match your index’s vector field size. In the chapter, 1536 dimensions with OpenAI’s text-embedding-3-small balances cost and quality and aligns with the index. A mismatch between vector dimensions and index configuration will break vector search.
Should I choose Exhaustive KNN or HNSW, and which similarity metric?For small datasets, choose Exhaustive KNN with cosine similarity to avoid HNSW’s extra memory overhead. Cosine similarity focuses on direction rather than magnitude, making it effective for semantic similarity across varying text lengths. For very large datasets, consider HNSW for speed, understanding it increases index space.
What’s the recommended ingestion pattern for large SQL datasets?- Fetch rows in batches (e.g., 100 at a time) - Summarize each record into a clean text string - Clean the text (remove problematic characters) - Embed the summary - Upload the document (fields + summary + vector) to the index Track progress counters, and consider asynchronous embedding for speed on very large corpora.
How do I run hybrid search (vector + keyword) and why is it better?Embed the user query and submit: - a VectorizedQuery against your Vector field, and - a standard keyword search (search_text). Merging both captures semantically similar passages and exact or near-exact keyword matches, reducing misses from using only one method.
How can I filter results and limit returned fields to control token usage?Use OData filters, e.g., Manufacturer eq 'Banana Angel inc.' (also supports neq, lt, gt). Use select to return only needed fields (e.g., ProductName) to reduce payload and token costs. Ensure fields you want back are marked retrievable in the index.
How do I keep result ordering consistent for end users?Sort results deterministically, either by the relevance score or by a stable field such as ProductName or DateModified. Decide the rule with stakeholders (e.g., newest first, specific brand first). You can sort client-side after retrieval if needed.
How do I keep the index in sync with new, updated, and deleted records?- Periodically select records modified within a time window (e.g., past week) and merge or upload them - Use a “soft delete” flag (Deleted) in SQL; when set, call delete_documents in AI Search for that ID - Optionally run this on a nightly schedule Azure’s built-in Indexer exists, but a custom process can be simpler and more flexible.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Enterprise RAG ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Enterprise RAG ebook for free