Grounded Search Agents: Microsoft Foundry + Azure AI Search + Cosmos DB + Function Calling Microsoft Foundry, Azure AI Search, and Azure Cosmos DB are combined to build a grounded search agent that uses function calling to route between unstructured document retrieval and structured data queries, always returning citations. The system outperforms plain RAG pipelines by integrating vector search with semantic ranking and maintaining conversation state in Cosmos DB. A plain RAG pipeline — embed a query, hit a vector index, stuff the top-k chunks into a prompt — works fine for a single-turn FAQ bot. It falls apart the moment you need: This post builds a small but complete grounded search agent : Azure OpenAI via Microsoft Foundry decides when to call a search tool versus a structured data tool, Azure AI Search handles retrieval and semantic ranking over unstructured documents, and Azure Cosmos DB stores conversation state and structured order/customer metadata. The agent uses OpenAI function calling to route between the two data sources and always returns citations. We'll build this from the ground up in Python. The system has two phases: ingestion getting documents into a searchable index and runtime the agent loop that answers questions . At runtime, the agent sits between the user and two tools, using function calling to decide which one or both to invoke: Create the index with both a vector field for semantic similarity and a semantic configuration for ranking , since combining the two consistently outperforms either alone. python create index.py from azure.search.documents.indexes import SearchIndexClient from azure.search.documents.indexes.models import SearchIndex, SimpleField, SearchableField, SearchField, SearchFieldDataType, VectorSearch, HnswAlgorithmConfiguration, VectorSearchProfile, SemanticConfiguration, SemanticPrioritizedFields, SemanticField, SemanticSearch from azure.core.credentials import AzureKeyCredential endpoint = "https://