The Algolia SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models access to Algolia's search, browse, record retrieval, and AI-powered recommendation capabilities.
Installation
1
dotnetaddpackageAlgolia
Available Tools
Search Tools (AlgoliaClient)
Method
Tool Name
Description
AsSearchTool(indexName)
AlgoliaSearch
Searches an Algolia index for matching records
AsGetObjectTool(indexName)
AlgoliaGetObject
Retrieves a single record by object ID
AsListIndicesTool()
AlgoliaListIndices
Lists all indices with record counts and update times
AsBrowseTool(indexName)
AlgoliaBrowse
Browses records without ranking (useful for data export)
Recommend Tools (AlgoliaRecommendClient)
Method
Tool Name
Description
AsFrequentlyBoughtTogetherTool(indexName)
AlgoliaFrequentlyBoughtTogether
Gets products frequently bought with a given item
AsRelatedProductsTool(indexName)
AlgoliaRelatedProducts
Gets products related to a given item
AsTrendingItemsTool(indexName)
AlgoliaTrendingItems
Gets currently trending items
AsLookingSimilarTool(indexName)
AlgoliaLookingSimilar
Gets visually similar items based on image attributes
usingAlgolia;usingMicrosoft.Extensions.AI;varalgoliaClient=newAlgoliaClient(apiKey:Environment.GetEnvironmentVariable("ALGOLIA_API_KEY")!);algoliaClient.WithApplicationId(Environment.GetEnvironmentVariable("ALGOLIA_APP_ID")!);varoptions=newChatOptions{Tools=[ algoliaClient.AsSearchTool(indexName: "products"), algoliaClient.AsGetObjectTool(indexName: "products"), algoliaClient.AsListIndicesTool(), ],};IChatClientchatClient=/* your chat client */;varmessages=newList<ChatMessage>{new(ChatRole.User,"Search for 'wireless headphones' in the products index."),};while(true){varresponse=awaitchatClient.GetResponseAsync(messages,options);messages.AddRange(response.ToChatMessages());if(response.FinishReason==ChatFinishReason.ToolCalls){varresults=awaitresponse.CallToolsAsync(options);messages.AddRange(results);continue;}Console.WriteLine(response.Text);break;}