次の方法で共有


Google テキスト検索の使用 (プレビュー)

警告

セマンティック カーネル テキスト検索機能はプレビュー段階であり、破壊的変更を必要とする機能強化は、リリース前の限られた状況で引き続き発生する可能性があります。

概要

Google テキスト検索の実装では、 Google Custom Search を使用して検索結果を取得します。 このコンポーネントを使用するには、独自の Google Search Api キーと検索エンジン ID を指定する必要があります。

制限事項

機能領域 サポート
API の検索 Google Custom Search API のみ。
サポートされているフィルター句 "等しい" フィルター句のみがサポートされています。
サポートされているフィルター キー "cr"、"dateRestrict"、"exactTerms"、"excludeTerms"、"filter"、"gl"、"hl"、"linkSite"、"lr"、"orTerms"、"rights"、"siteSearch" の各パラメーターがサポートされています。 詳細については、 パラメーターを参照してください。

作業の開始

次のサンプルは、 GoogleTextSearch を作成し、それを使用してテキスト検索を実行する方法を示しています。

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}");
}

間もなく利用できます

詳細は近日公開予定です。

間もなく利用できます

詳細は近日公開予定です。

次のステップ

ドキュメントの次のセクションでは、次の方法について説明します。

  1. pluginを作成し、それを取得拡張生成 (RAG) に使用します。
  2. 関数呼び出しと共にテキスト検索を使用します。
  3. テキスト検索に ベクトル ストア を使用する方法の詳細を確認します。