Azure-Samples / azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
https://azure.microsoft.com/products/search
MIT License
6.02k stars 4.12k forks source link

What variables should I change to change the number of retrieved search results. #1032

Open suma-sai-paluri opened 10 months ago

suma-sai-paluri commented 10 months ago

Minimal steps to reproduce

I want to retrieve 5 search results for every query made. How can I change the number in the code apart from changing the number it in the UI. I have tried changing at multiple place in the source code , but wasn't able to retrieve more than set 3 . And also is there a way to dynamically decide the number of search results based on the query ,because it would be helpful when we have a lot of documents. Thank you in advance

Mention any other details that might be useful


Thanks! We'll be in touch soon.

pamelafox commented 10 months ago

Have you tried changing this line?

https://github.com/Azure-Samples/azure-search-openai-demo/blob/a1170562395ad122d2be0e8e29d33cac7ff169c2/app/backend/approaches/chatreadretrieveread.py#L121

To:

top = 10 or some other number?

In terms of dynamically deciding search results based on query, you'd need to change it in that function. I'm not sure what criteria you're using it for changing it, but you could try changing the function call to have a second parameter for number of sources, and then modify the query prompt few shots to demonstrate when it'd call different numbers of sources:

https://github.com/Azure-Samples/azure-search-openai-demo/blob/a1170562395ad122d2be0e8e29d33cac7ff169c2/app/backend/approaches/chatreadretrieveread.py#L132

suma-sai-paluri commented 10 months ago

Hi @pamelafox I have tried making the changes in the following line of code: top = overrides.get("top", 3) but the changes are not being reflected. Do you think I should change else where , as of now I am able to control the number of document from the visual interface of the application only. In the case of dynamically deciding the search results, I am still trying to figure it out. If you have any repos that are using functions or any of these properties would be of great help. Thanks in advance

mahzy commented 8 months ago

any update on this issue ?

pamelafox commented 8 months ago

Ah, sorry! You actually need to change it in the frontend, in Chat.tsx:

https://github.com/Azure-Samples/azure-search-openai-demo/blob/29355ec72e78404b3f1ad473a0695f8ff930226e/app/frontend/src/pages/chat/Chat.tsx#L36

That's because the frontend sends top to the backend here:

https://github.com/Azure-Samples/azure-search-openai-demo/blob/29355ec72e78404b3f1ad473a0695f8ff930226e/app/frontend/src/pages/chat/Chat.tsx#L148

If you removed that line above, then the modification to the Python code should work. But assuming you're keeping "Developer settings" around in the frontend, you should change the default there. Sorry for the confusion!