Using the Google Text Search (Preview)
Warning
The Semantic Kernel Text Search functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.
Overview
The Google Text Search implementation uses Google Custom Search to retrieve search results. You must provide your own Google Search Api Key and Search Engine Id to use this component.
Limitations
Feature Area | Support |
---|---|
Search API | Google Custom Search API only. |
Supported filter clauses | Only "equal to" filter clauses are supported. |
Supported filter keys | Following parameters are supported: "cr", "dateRestrict", "exactTerms", "excludeTerms", "filter", "gl", "hl", "linkSite", "lr", "orTerms", "rights", "siteSearch". For more information see parameters. |
Tip
Follow this link for more information on how search is performed
Getting started
The sample below shows how to create a GoogleTextSearch
and use it to perform a text search.
using Google.Apis.Http;
using Microsoft.SemanticKernel.Data;
using Microsoft.SemanticKernel.Plugins.Web.Google;
// Create an ITextSearch instance using Google search
var textSearch = new GoogleTextSearch(
initializer: new() { ApiKey = "<Your Google API Key>", HttpClientFactory = new CustomHttpClientFactory(this.Output) },
searchEngineId: "<Your Google Search Engine Id>");
var query = "What is the Semantic Kernel?";
// Search and return results as string items
KernelSearchResults<string> stringResults = await textSearch.SearchAsync(query, new() { Top = 4, Skip = 0 });
Console.WriteLine("——— String Results ———\n");
await foreach (string result in stringResults.Results)
{
Console.WriteLine(result);
}
// Search and return results as TextSearchResult items
KernelSearchResults<TextSearchResult> textResults = await textSearch.GetTextSearchResultsAsync(query, new() { Top = 4, Skip = 4 });
Console.WriteLine("\n——— Text Search Results ———\n");
await foreach (TextSearchResult result in textResults.Results)
{
Console.WriteLine($"Name: {result.Name}");
Console.WriteLine($"Value: {result.Value}");
Console.WriteLine($"Link: {result.Link}");
}
// Search and return results as Google.Apis.CustomSearchAPI.v1.Data.Result items
KernelSearchResults<object> fullResults = await textSearch.GetSearchResultsAsync(query, new() { Top = 4, Skip = 8 });
Console.WriteLine("\n——— Google Web Page Results ———\n");
await foreach (Google.Apis.CustomSearchAPI.v1.Data.Result result in fullResults.Results)
{
Console.WriteLine($"Title: {result.Title}");
Console.WriteLine($"Snippet: {result.Snippet}");
Console.WriteLine($"Link: {result.Link}");
Console.WriteLine($"DisplayLink: {result.DisplayLink}");
Console.WriteLine($"Kind: {result.Kind}");
}
Coming soon
More coming soon.
Coming soon
More coming soon.
Next steps
The following sections of the documentation show you how to:
- Create a plugin and use it for Retrieval Augmented Generation (RAG).
- Use text search together with function calling.
- Learn more about using vector stores for text search.