Azure-Samples / azure-search-openai-demo-csharp

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure Cognitive Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
MIT License
612 stars 401 forks source link

How cam i use my own data together with the public data in one chat completion? #248

Closed CSchuster closed 9 months ago

CSchuster commented 10 months ago

This issue is for a:

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [X] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

I have set up a Azure Cognitive Search on some docx files and this is running file. The SDK is: Azure.AI.OpenAI Version=1.0.0-beta.9 on asp.net core 8.0

Any log messages given by the failure

none

Expected/desired behavior

when i ask Questions (Chat Completion) i want to have the answers from my Data AND the public available data. (The ShouldRestrictResultScope in the AzureCognitiveSearchChatExtensionConfiguration does not do anything.)

OS and Version?

any

Versions

Mention any other details that might be useful

the code looks like this:

var ext = new AzureCognitiveSearchChatExtensionConfiguration() {
    SearchEndpoint = new Uri(searchEndpoint),
    IndexName = searchIndexName,
    ShouldRestrictResultScope = false
};

ext.SetSearchKey(searchApiKey);

var searchOpts = new AzureChatExtensionsOptions() {
    Extensions = {
        ext
    }
};

var Options = new ChatCompletionsOptions(Deployment.Model, Msgs) {
    Temperature = Temperature,
    MaxTokens = MaxTokens,
    NucleusSamplingFactor = TopP,
    FrequencyPenalty = FrequencyPenalty,
    PresencePenalty = PresencePenalty,
    User = myUser?.UserName,
    AzureExtensionsOptions = searchOpts
};

var cl = new HttpClient() {
    Timeout = TimeSpan.FromMinutes(5)
};

var opts = new OpenAIClientOptions {
    Transport = new HttpClientTransport(cl)
};

var client = new OpenAIClient(
    new Uri(Location.URL),
    new AzureKeyCredential(Location.AccessKey),
    opts
);

var responseWithoutStream = await client.GetChatCompletionsAsync(Options, cancellationToken);
var completions = responseWithoutStream.Value;
var responseMessage = completions.Choices[0]?.Message.Content ?? "";

luisquintanilla commented 9 months ago

Hi @CSchuster,

It doesn't appear this question / issue is in the context of this sample and might get a better answer in the Azure SDK repo.

https://github.com/Azure/azure-sdk-for-net/issues

In general, the SDK will allow you to use data in the Azure Search index you configured. If you have another public data source, when you submit your prompt, you should be able to add that to your prompt as additional context.

i.e.

"""
Using this public data from data source x as additional context:

{public data}

[YOUR-QUESTION]
"""