{"id":23539196,"url":"https://github.com/rickcau/api-ai-rag-intent","last_synced_at":"2026-02-12T13:39:28.208Z","repository":{"id":229495445,"uuid":"776866879","full_name":"Rickcau/api-ai-rag-intent","owner":"Rickcau","description":"AOAI Chat API that leverages RAG Semantic + Vector with Intent ","archived":false,"fork":false,"pushed_at":"2025-01-01T19:51:52.000Z","size":1378,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T17:11:32.525Z","etag":null,"topics":["ai-search","intent","plugin","rag","semantic-kernel","sk"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rickcau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-24T17:01:30.000Z","updated_at":"2025-01-01T19:51:56.000Z","dependencies_parsed_at":"2024-03-24T19:23:29.035Z","dependency_job_id":"886bc630-d050-4fa8-bfef-cf967e95165d","html_url":"https://github.com/Rickcau/api-ai-rag-intent","commit_stats":null,"previous_names":["rickcau/api-ai-rag-intent"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rickcau/api-ai-rag-intent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rickcau%2Fapi-ai-rag-intent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rickcau%2Fapi-ai-rag-intent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rickcau%2Fapi-ai-rag-intent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rickcau%2Fapi-ai-rag-intent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rickcau","download_url":"https://codeload.github.com/Rickcau/api-ai-rag-intent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rickcau%2Fapi-ai-rag-intent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29367415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-search","intent","plugin","rag","semantic-kernel","sk"],"created_at":"2024-12-26T04:30:30.714Z","updated_at":"2026-02-12T13:39:28.193Z","avatar_url":"https://github.com/Rickcau.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# api-ai-rag-intent\n\n## Update 7/13/2024\nAny updates or example that I create will now be placed in my [ai-rag-intent-blazor](https://github.com/Rickcau/ai-rag-intent-blazor) example, so check that out for a more current example.  I don't have a lot of time to do UI work so that part of the example is lagging a bit.\n\nI also have an issue with Docker on my laptop hence is why you don't see me using DevContainers right now.  I have a new laptop I need to get setup and Docker will be one of the first things I get setup.  ;)\n\n## Summary\nIn this example, I implement an **Intent Recognition** pattern to detect the intent of the user’s prompt. The Chat Completion API allows you to set the **N** property for the prompt and when set it determines how many responses the LLM will provide for the user prompt in one call.  The advantage of this, is that it allows the LLM in one call to attempt to determine the **Intent** multiple times.  The reason this is important is because the LLM can incorrectly predict the **Intent**. \n\nBased on various conversations I have had the Semantic Kernel team, I was advised that I should take advantage of the ResultsPerPrompt property, which is exposed via **OpenAIPromptExecutionSettings** in the Semantic Kernel.  When using the ResultsPerPrompt and setting it to anything greater than 1, you must use **IChatCompletionService.GetChatMessageContentsAsync** and not **IChatCOmpletionService.GetChatMessageContentAsync**.\n\nBy using this pattern, it provides the following benefits:\n•\tAllows you to only make calls to your AI Search Service when the **Intent** of the prompt is document search related.  In this example, the service provides two features, the ability to provide details about documents we have indexed and the ability to perform SubGraph Queries against the UniswapV3 SubGraph Endpoint.\n•\tAllows you to branch based on **Intent** and write more efficient code\n•\tReduces the number of Tokens being consumed and allows you to only call the AI endpoint when needed\n•\tUsing the ResultsPerPrompt allows you to determine the quorum based on 3 results, even if the quorum is incorrect you still minimize the number of times the AI endpoint will be unnecessarily called. \n•\tAllows you to get 3 results from the LLM with just one call to the endpoint.  \n\nIn my testing the LLM seems to perform best with a Temperature of 0.5 and a ResultsPerPrompt of 3.  LLMs can incorrectly predict the **Intent** and this is why you want to ask it for 3 results, as this allows the LLM to reevaluate the prediction.   \n\n## Goal\nThe goal is to demostrate the use of **Intent Recognition** in conjunction with RAG (Retreval Augmentation Generation) using Semantic Kernel (1.4.0) an Isolated Azure Function.  It leverages all the common patterns e.g. dependecy injection, SK Plugins/Functions, AutoInvoke etc. \n\n## Patterns \n- RAG (Retreval Augmentation Generation) using Semantic + Vector Seach\n- Intent Recognition\n- SK Functions \u0026 Plugins\n\n## Technologies\n- Azure Function (Isolated) as REST Endpoint\n- Semantic Kernel (1.4.0)\n- Azure AI Search (Semantic + Vector)\n- UniswapV3 SubGraph API\n- Dependency Injection\n- Azure Open AI\n\n## Bicep Deployment and Scripts\nIf you would like to deploy the resouces for this example you can use the .bicep templates, just read the notess in the files to understand how to use them.\n\nYou can use the UploadDocument.ps1 to upload the employee_handbook.pdf to the Storage Account Container.  The CreateIndex.ps1 script is not complete yet so you will need to refactor it to get it working.  For now, you can simply use the **Import and Vectorize** option from the Azure Portal to build the index that will be used in this example.\n\n### Request Body\nThe function expects you to pass a JSON body with the following information:\n\n        ~~~\n              {\n                 \"userId\": \"stevesmith@contoso.com\",\n                 \"sessionId\": \"12345678\",\n                 \"tenantId\": \"00001\",\n                 \"prompt\": \"Can you tell what my healtcare benefits are for Northwinds\"\n              }\n        ~~~\n\nThe client that is calling the Function will pass these values in and later they can be used to store/retreive prompt history. In a future version I will add support to storing/retreving of ChatHistory using CosmosDB.\n\n## Steps to deploy the Azure Resouces needed for this example\n### Create an Azure Resouce Group\n1. Open a Terminal Windows in Visual Studio and run the following command\n   \n   ~~~\n       az group create --name AIRagIntentResourceGroup --location westus\n   ~~~\n\n2. Open the .bicep files and read the instructions for details on how to deploy the resouces using the templates.\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickcau%2Fapi-ai-rag-intent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickcau%2Fapi-ai-rag-intent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickcau%2Fapi-ai-rag-intent/lists"}