I am using Semantic Kernel "RAG" pattern to use Azure Open AI + Bring your own Data to query against some internal docs. I'd like to ensure the Model only searches against data its provided, and not the whole of the Model.
Pseduo code looks like this:
var ai = azureAIChatCompletionService.Instanace.GetRequiredService<IChatCompletionService>();
var chat = memoryCache.Get<ChatHistory>(chatDto.CacheKey);
chat ??= new ChatHistory("I am an assistant programmed to discuss the contents of X Documents, specifically from the additional information provided to me. To maintain data integrity, I will solely rely on the additional information available. If, for any reason, the data is unavailable, I will inform you by saying ‘This service is currently unavailable.’ Please proceed with your queries about the provided additional information, and let’s begin our conversation!");
var builder = new StringBuilder();
var titleSourceList = new List<string>();
await foreach (var result in azureAIMemoryService.Instanace.SearchAsync(chatDto.ChatType.ToString(), chatDto.Query, limit: 5, minRelevanceScore: 0.5))
{
// append additional info
builder.AppendLine(result.Metadata.Description);
titleSourceList.Add(result.Metadata.Id);
}
int contextToRemove = -1;
if (builder.Length != 0)
{
builder.Insert(0, "Here's some additional information: ");
contextToRemove = chat.Count;
chat.AddUserMessage(builder.ToString());
}
chat.AddUserMessage(chatDto.Query);
var response = await ai.GetChatMessageContentAsync(chat);
How can I prevent a search on the model of something like: "Who is Michael Jordan?"
We also have a example where you use Az Cog Search to index the data, then use RAG pattern to use Open AI completion using the matches docs from Az Cog Search.
RAG and generative AI - Azure Cognitive Search | Microsoft Learn
You can prevent a search on the model of something like “Who is Michael Jordan?” by using the filter parameter in the SearchAsync method. This parameter allows you to specify a filter expression that limits the results returned by the search. You can use this to ensure that the model only searches against the data you have provided and not the entire model. For example, you could specify a filter that only returns results from a specific data source or set of data sources that you have provided to the model.