4 Retrieval using AutoGen agents

 

This chapter covers

  • Using AutoGen ggents for more flexible information retrieval
  • How to give these agents the search functions you created
  • Querying multiple databases or indexes at once
  • Prompting agents effectively to limit hallucinations

In the last chapter, you learned how to prep and upload your data to a search service, a big leap toward building a truly performant Retrieval Augmented Generation (RAG) system. But even if you can retrieve the right data, there’s still a chance your system will hand users incomplete or incorrect answers. In this chapter, we’ll tackle that problem head-on by introducing AutoGen agents, which can orchestrate queries, refine ambiguous user requests, and reduce hallucinations.

You’ll see how to integrate the search functions you created in Chapter 3 with Autogen’s agent framework. Instead of a simple function call that blindly embeds user questions, agents will decide which database or index to consult and how best to search it. If a user’s request isn’t clear or doesn’t yield good results, agents can run multiple searches, pivot to another approach, or even ask the user for clarification.

4.1 Using agents for smarter retrieval in RAG

4.1.1 Getting into agents

4.1.2 Setting up AutoGen agents

4.2 Assigning a search function to the agents

4.2.1 Creating query embeddings for the AI search index

4.2.2 Setting up the Azure AI Search client

4.3 Searching multiple databases simultaneously

4.3.1 Using group chats for simultaneous queries

4.4 Writing the final answer

4.5 Making sure the bot answers in the right language

4.5.1 Define the language checker function

4.6 Storing answer information

4.7 The RAGChat function: one RAG to rule them all

4.8 Question triage

4.8.1 Code Setup

4.9 Websocket integration for streaming responses

4.9.1 Essential setup

4.9.2 Handling websocket messages

4.9.3 Starting the websocket server

4.10 Testing the websocket server with a client

4.11 Summary