Combining RAG with function calling #7440
-
Is it possible to combine data retrieval with Azure AI Search and chat-completion function calling? When attempting it with a generalized message (which won't call functions) I get a response from AI Search successfully. Code exampleWorking function calling without combining with RAG: // ChatHistory chatHistory <= created elsewhere
var openAIPromptExecutionSettings = new OpenAIPromptExecutionSettings
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
await chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings: openAIPromptExecutionSettings, kernel: kernel); Combining with RAG: // ChatHistory chatHistory <= created elsewhere
var chatExtensionConfiguration = new AzureSearchChatExtensionConfiguration
{
Authentication = new OnYourDataApiKeyAuthenticationOptions("<redacted>"),
IndexName = "<redacted>",
SearchEndpoint = new Uri("<redacted>")
};
var chatExtensionsOptions = new AzureChatExtensionsOptions { Extensions = { chatExtensionConfiguration } };
var openAIPromptExecutionSettings = new OpenAIPromptExecutionSettings
{
AzureChatExtensionsOptions = chatExtensionsOptions,
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
await chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings: openAIPromptExecutionSettings, kernel: kernel); Error output
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
@adrian-watson-pts It looks like it's not supported by Azure .NET SDK, which we are using at the moment:
|
Beta Was this translation helpful? Give feedback.
-
The solution to this is to make two calls, first to the knowledge/data retrieval service (Azure AI Search in my case) and then add its response (as |
Beta Was this translation helpful? Give feedback.
-
I am also thinking about combining RAG with function calling. The problem I want to resolve is I want the llm to decide do I need to retrieve data or not. For example, saying hello at first didn't need to retrieve the data. I think the other way to do it is by agent to hook up with the retrieval plugin? Didn't try that yet, but if the functional calling is not working, I think this might be the only way to go? |
Beta Was this translation helpful? Give feedback.
-
I am exploring the best to combine rag and function calling .. I am currently trying to implement it using the new agent functionality in sk :
I Will post some code sample in a GitHub repo when I have something working properly |
Beta Was this translation helpful? Give feedback.
-
Is it the same like this: |
Beta Was this translation helpful? Give feedback.
@adrian-watson-pts It looks like it's not supported by Azure .NET SDK, which we are using at the moment:
https://github.com/Azure/azure-sdk-for-net/tree/49b0ace48d35cb4b2ace93b517036b660fc12ca4/sdk/openai/Azure.AI.OpenAI#use-your-own-data-with-azure-openai