建立已編製索引的 Azure SQL 知識來源 (預覽)

Note

Azure AI 搜尋服務 可透過 Azure 入口網站、REST API 及 Azure SDK 取得。 它同時也是 Foundry IQ 的基礎,這是一個管理式知識層,能將企業內容轉化為可重複使用、權限感知的知識庫,供 Microsoft Foundry 入口網站中的代理使用。

Important

標記(預覽)的功能、能力或屬性不受服務等級協議涵蓋,也不建議用於生產工作負載,且在正式上架前可能會有所變動或受限。 Azure AI 搜尋服務 預覽條款適用於所有預覽功能,無論是獨立功能還是正式推出功能的一部分。

已編製索引的 Azure SQL 知識來源(預覽)會將 Azure SQL Database 或 Azure SQL 受控執行個體 中的資料列擷取並匯入 Azure AI 搜尋服務 的代理式擷取管線。 知識來源 獨立建立,並在 知識庫中被引用,並在 執行時查詢知識庫時作為基礎資料。

與基於檔案的知識來源(如 Azure Blob 儲存體 和 OneLake)不同,每個 SQL 列都被視為一個邏輯文件。 你透過明確的欄位映射來驅動索引結構,而不是使用固定的文件架構。

當你建立索引的 Azure SQL 知識來源時,你可以指定一個 SQL 資料來源、可選的欄位映射,以及可選的模型,以自動產生以下 Azure AI 搜尋服務 物件:

  • 代表 SQL 資料表或檢視的資料來源。
  • 欄位衍生自您資料行對應的索引。
  • 產生內嵌的技能集。 服務只有在你指定 embeddingColumns時才會建立技能組。
  • 使用先前物件來驅動內嵌管線的索引子。

產生的索引器符合 Azure SQL索引器,其前提條件、變更偵測策略及限制同樣適用於索引Azure SQL知識來源。 欲了解更多資訊,請參閱 Azure SQL 索引器文件。

使用支援

Azure portal Microsoft Foundry 入口網站 .NET SDK Python SDK Java 開發套件 JavaScript SDK REST API
✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

先決條件

  • 任何 區域內提供主動檢索的 Azure AI 搜尋服務 服務。

  • 完成Azure SQL索引器先修條件,包括:

    • Azure SQL Database或Azure SQL 受控執行個體,並附有表格或視圖可供匯入。

    • 來源資料表或視圖上的單一值主鍵。

    • 對於檢視,適合用於高水位標記變更偵測的資料行。 我們強烈建議使用 rowversion 欄。

  • 允許建立知識來源。 建議使用分配給你的使用者帳號的搜尋服務貢獻者和搜尋索引資料貢獻者角色來設定無密鑰認證,或使用管理員 API 金鑰。

  • 如果您指定 embeddingColumns,搜尋服務必須具有 受控識別,且對裝載嵌入模型的 Microsoft Foundry 資源具有 Cognitive Services User 權限。

  • 如果你設定 networkAccessMode 為 private,請完成以下要求:

    • 使用 S2、S3、L1或L2的搜尋服務。

    • 建立並核准一個包含 sqlServer 群組 ID 的 SQL 伺服器共用私有連結。 對於 SQL 受管理執行個體,請使用managedInstance群組 ID。

    • 使用 SQL 認證或管理身份驗證。 對於受控識別,請授與該識別所需的 Azure 和資料庫角色,並使用包含 Database=<database-name> 與 SQL 伺服器或 SQL 受控執行個體 資源識別碼的連接字串。 僅針對使用者指派的身分識別設定 ingestionParameters.identity。 若省略,索引器會使用搜尋服務系統指定的身份。

    • 為每個受保護的模型端點建立並核准共用的私有連結。 Azure OpenAI 端點使用 foundry_account 群組 ID,Foundry 資源端點則使用 openai_account。

  • 最新的 Azure.Search.Documents 預覽套件:dotnet add package Azure.Search.Documents --prerelease

  • 對於無鑰匙認證,套件如下 Azure.Identity : dotnet add package Azure.Identity

限制與考量

  • 一個知識來源只能從一個資料表或一個檢視擷取資料。
  • 來源資料表或檢視必須有一個單一值的主鍵。 複合金鑰不支援。
  • 主鍵是自動發現的,無法被覆蓋。
  • contentExtractionMode 僅支援 "minimal"。
  • 圖片擷取和影像語音化都不支援。
  • 不支援即時同步。 產生的索引器是基於排程的。
  • 不支援即時 SQL 檢索。 知識來源是有索引的,不是遠端的。

準備產生的索引器

索引化的 Azure SQL 知識來源會自動建立索引器來推動資料擷取。 在建立知識來源前,請先檢視以下細節。

變更偵測

產生的索引器使用標準的 Azure SQL索引器變更偵測:

Authentication

產生的索引器支援兩種認證選項:

  • SQL 認證: 在連接字串中提供使用者名稱和密碼。

  • Managed Identity Authentication: 使用系統指派或使用者指派的管理身份,該身份在 SQL 資源上擁有 Azure RBAC 及資料庫層級的角色。

如需了解連接字串格式、角色需求及設定步驟,請參閱 Azure SQL 索引器必要條件 和 透過受控識別連線。

檢查現有的知識來源

知識來源是一個頂層且可重複使用的物件。 了解現有的知識來源對於重用或命名新物件都很有幫助。

執行以下程式碼,依名稱和類型列出知識來源。

// List knowledge sources by name and type
using Azure.Search.Documents.Indexes;

var indexClient = new SearchIndexClient(new Uri(searchEndpoint), credential);
var knowledgeSources = indexClient.GetKnowledgeSourcesAsync();

Console.WriteLine("Knowledge Sources:");

await foreach (var ks in knowledgeSources)
{
    Console.WriteLine($"  Name: {ks.Name}, Type: {ks.GetType().Name}");
}

參考資料:SearchIndexClient

# List knowledge sources by name and type
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient

index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))

for ks in index_client.list_knowledge_sources():
    print(f"  - {ks.name} ({ks.kind})")

參考資料:SearchIndexClient

### List knowledge sources by name and type
GET {{search-url}}/knowledgesources?api-version={{api-version}}&$select=name,kind
Authorization: Bearer {{token}}

參考資料:知識來源列表

你也可以以名稱回傳單一知識來源,以檢視其 JSON 定義。

using Azure.Search.Documents.Indexes;
using System.Text.Json;

var indexClient = new SearchIndexClient(new Uri(searchEndpoint), credential);

// Specify the knowledge source name to retrieve
string ksNameToGet = "earth-knowledge-source";

// Get its definition
var knowledgeSourceResponse = await indexClient.GetKnowledgeSourceAsync(ksNameToGet);
var ks = knowledgeSourceResponse.Value;

// Serialize to JSON for display
var jsonOptions = new JsonSerializerOptions 
{ 
    WriteIndented = true,
    DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.Never
};
Console.WriteLine(JsonSerializer.Serialize(ks, ks.GetType(), jsonOptions));

參考資料:SearchIndexClient

# Get a knowledge source definition
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
import json

index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))

ks = index_client.get_knowledge_source("knowledge_source_name")
print(json.dumps(ks.as_dict(), indent = 2))

參考資料:SearchIndexClient

### Get a knowledge source definition
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}?api-version={{api-version}}
Authorization: Bearer {{token}}

參考資料:知識來源 - 取得

以下 JSON 是一個針對索引 Azure SQL 知識來源的範例回應。

{
  "name": "indexedsqlks",
  "kind": "indexedSql",
  "description": "Sample indexed Azure SQL knowledge source.",
  "encryptionKey": null,
  "indexedSqlParameters": {
    "connectionString": "<sql-connection-string>",
    "tableOrView": "dbo.tbl_hotels",
    "contentColumns": [
      { "name": "hotelName", "sourceField": "HotelName", "searchFieldType": "Edm.String" },
      { "name": "description", "sourceField": "Description", "searchFieldType": "Edm.String" }
    ],
    "embeddingColumns": [
      { "name": "descriptionVector", "sourceField": "Description" }
    ],
    "ingestionParameters": {
      "contentExtractionMode": "minimal",
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<aoai-endpoint>",
          "deploymentId": "text-embedding-3-large",
          "modelName": "text-embedding-3-large"
        }
      },
      "createdResources": {
        "datasource": "indexedsqlks-datasource",
        "indexer": "indexedsqlks-indexer",
        "skillset": "indexedsqlks-skillset",
        "index": "indexedsqlks-index"
      }
    }
  }
}

建立知識來源

執行以下程式碼建立索引的 Azure SQL 知識來源。

using Azure.Identity;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.KnowledgeBases.Models;

var indexClient = new SearchIndexClient(new Uri(searchEndpoint), new DefaultAzureCredential());

var embeddingParams = new AzureOpenAIVectorizerParameters
{
    ResourceUri = new Uri(aoaiEndpoint),
    DeploymentName = aoaiEmbeddingDeployment,
    ModelName = aoaiEmbeddingModel
};

var ingestionParams = new KnowledgeSourceIngestionParameters
{
    NetworkAccessMode = KnowledgeSourceNetworkAccessMode.Public,
    ContentExtractionMode = "minimal",
    EmbeddingModel = new KnowledgeSourceAzureOpenAIVectorizer
    {
        AzureOpenAIParameters = embeddingParams
    }
};

var sqlParams = new IndexedSqlKnowledgeSourceParameters(
    connectionString: sqlConnectionString,
    tableOrView: "dbo.tbl_hotels")
{
    ContentColumns =
    {
        new ContentColumnMapping("hotelName", "HotelName", "Edm.String"),
        new ContentColumnMapping("description", "Description", "Edm.String")
    },
    EmbeddingColumns =
    {
        new EmbeddingColumnMapping("descriptionVector", "Description")
    },
    IngestionParameters = ingestionParams
};

var knowledgeSource = new IndexedSqlKnowledgeSource(
    name: "indexedsqlks",
    indexedSqlParameters: sqlParams)
{
    Description = "Indexed Azure SQL knowledge source."
};

await indexClient.CreateOrUpdateKnowledgeSourceAsync(knowledgeSource);
Console.WriteLine($"Knowledge source '{knowledgeSource.Name}' created or updated successfully.");

參考資料:SearchIndexClient、 IndexedSqlKnowledgeSource

from azure.identity import DefaultAzureCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    AzureOpenAIVectorizerParameters,
    ContentColumnMapping,
    EmbeddingColumnMapping,
    IndexedSqlKnowledgeSource,
    IndexedSqlKnowledgeSourceParameters,
)
from azure.search.documents.knowledgebases.models import (
    KnowledgeSourceAzureOpenAIVectorizer,
    KnowledgeSourceIngestionParameters,
    KnowledgeSourceNetworkAccessMode,
)

index_client = SearchIndexClient(endpoint="<search-endpoint>", credential=DefaultAzureCredential())

embedding_params = AzureOpenAIVectorizerParameters(
    resource_url="<aoai-endpoint>",
    deployment_name="<aoai-embedding-deployment>",
    model_name="<aoai-embedding-model>",
)

ingestion_params = KnowledgeSourceIngestionParameters(
    network_access_mode=KnowledgeSourceNetworkAccessMode.PUBLIC,
    content_extraction_mode="minimal",
    embedding_model=KnowledgeSourceAzureOpenAIVectorizer(
        azure_open_ai_parameters=embedding_params
    ),
)

knowledge_source = IndexedSqlKnowledgeSource(
    name="indexedsqlks",
    description="Indexed Azure SQL knowledge source.",
    indexed_sql_parameters=IndexedSqlKnowledgeSourceParameters(
        connection_string="Server=tcp:{server}.database.windows.net,1433;Database={db};...;",
        table_or_view="dbo.tbl_hotels",
        content_columns=[
            ContentColumnMapping(
                name="hotelName",
                source_field="HotelName",
                search_field_type="Edm.String",
            ),
            ContentColumnMapping(
                name="description",
                source_field="Description",
                search_field_type="Edm.String",
            ),
        ],
        embedding_columns=[
            EmbeddingColumnMapping(
                name="descriptionVector",
                source_field="Description",
            )
        ],
        ingestion_parameters=ingestion_params,
    ),
)

index_client.create_or_update_knowledge_source(knowledge_source=knowledge_source)
print(f"Knowledge source '{knowledge_source.name}' created or updated successfully.")

參考資料:SearchIndexClient

### Create an indexed Azure SQL knowledge source
PUT {{search-endpoint}}/knowledgesources/indexedsqlks?api-version=2026-08-01-preview
Authorization: Bearer {{search-access-token}}
Content-Type: application/json

{
  "name": "indexedsqlks",
  "kind": "indexedSql",
  "description": "Indexed Azure SQL knowledge source.",
  "indexedSqlParameters": {
    "connectionString": "Server=tcp:{server}.database.windows.net,1433;Database={db};...;",
    "tableOrView": "dbo.tbl_hotels",
    "contentColumns": [
      { "name": "hotelName", "sourceField": "HotelName", "searchFieldType": "Edm.String" },
      { "name": "description", "sourceField": "Description", "searchFieldType": "Edm.String" }
    ],
    "embeddingColumns": [
      { "name": "descriptionVector", "sourceField": "Description" }
    ],
    "ingestionParameters": {
      "networkAccessMode": "public",
      "contentExtractionMode": "minimal",
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "{{aoai-endpoint}}",
          "deploymentId": "{{aoai-embedding-deployment}}",
          "modelName": "{{aoai-embedding-model}}"
        }
      }
    }
  }
}

參考資料:知識來源 - 建立或更新

用 indexedSqlParameters 來識別要匯入的 SQL 表格或視圖,並定義成為產生索引中欄位的映射。 如果是檢視,請指定用於變更偵測的上限標準欄。

資料行對應

使用 contentColumns 將 SQL 文字資料行對應至產生的 Azure AI 搜尋服務 索引中的可搜尋欄位。 每個內容欄位映射會命名目標索引欄位、來源 SQL 欄位,以及 Azure AI 搜尋服務 欄位類型。 對於 contentColumns,請使用 Edm.String。

嵌入映射

用 embeddingColumns 來將 SQL 文字欄位映射到產生的向量欄位。 在使用嵌入欄位時,請指定一個嵌入模型 ingestionParameters 。

對於索引的 Azure SQL 知識來源,contentExtractionMode必須是"minimal"因為 SQL 的擷取是基於列的,不會從二進位文件中擷取內容。 圖片擷取與影像語音化不支援,因此 chatCompletionModel、 assetStore、 aiServices及影像相關設定均無影響。

預設值設定與驗證規則

當你建立索引化的 Azure SQL 知識來源時,以下預設值會適用。

  • 若省略 contentColumns,服務會自動將可安全以文字表示的 SQL 欄位映射到 Edm.String 產生的索引欄位,採用 1:1 映射,其中 name 等於 sourceField。

  • 如果你省略 embeddingColumns了 ,該服務不會建立向量場,也不會設定嵌入技能。

  • embeddingColumns 與 contentColumns 無關。 要讓向量對應可檢索的文字,請在兩個陣列中包含相同的 SQL 欄位。

  • 來源資料表或檢視的主鍵會自動被發現。 不支援明確覆寫,且來源必須有單一值的主鍵。

限制擷取權限僅限於私人網路

從 2026-08-01-preview API 版本開始,networkAccessMode 會控制為已編製索引的 Azure SQL 知識來源所產生的索引器執行所在的網路環境。 此設定只會影響資料擷取,不會變更知識庫擷取請求或回應。

networkAccessMode 預設為 public,以保留現有的公共網路行為。 當 networkAccessMode 為 private 時,產生的索引器會在 私有執行環境中執行。 它使用核准的共享私有連結來存取 Azure SQL Database 或 SQL 受管理執行個體 原始碼連線,以及支援的 Azure 相依關係,例如 Azure OpenAI 模型和 Microsoft Foundry 資源。

要配置並驗證私人網路存取:

  1. 完成 私人網路的必要條件。

  2. 在建立知識來源的請求中,將 networkAccessMode 設為 private。 你只能在建立時設定這個屬性。 若要稍後更改,請刪除並重新建立知識來源。

    如果服務層級或執行時不支援私有執行,或沒有所需的共享私有連結,建立可能會失敗。

  3. 確認產生的索引器 executionEnvironment 為 private。

  4. 確認每個必要的共用私人連結皆已獲核准,且以正確的相依性為目標。 僅成功建立並不代表連結已獲核准或已設定目標對象。

  5. 輪詢知識來源狀態直到 lastSynchronizationState.endTime 有值為止。 確認 itemsUpdatesFailed 為 0,然後驗證連接器專屬的來源內容。 如果相依項目無法存取,同步就會失敗。

檢查吞食狀態

執行下列程式碼以監視擷取進度和健康情況,包括知識來源種類,以及產生索引子管線並填入搜尋索引之知識來源的詳細索引錯誤。

using Azure.Search.Documents.Indexes;
using System.Text.Json;

var indexClient = new SearchIndexClient(new Uri(searchEndpoint), new AzureKeyCredential(apiKey));

// Get knowledge source ingestion status
var statusResponse = await indexClient.GetKnowledgeSourceStatusAsync(knowledgeSourceName);
var status = statusResponse.Value;

// Serialize to JSON for display
var json = JsonSerializer.Serialize(status, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine(json);

參考資料:SearchIndexClient

# Check knowledge source ingestion status
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
import json

index_client = SearchIndexClient(endpoint="search_url", credential=AzureKeyCredential("api_key"))

status = index_client.get_knowledge_source_status("knowledge_source_name")
print(json.dumps(status.as_dict(), indent=2))

參考資料:SearchIndexClient

### Check knowledge source ingestion status
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}/status?api-version={{api-version}}
Authorization: Bearer {{token}}
Content-Type: application/json 

參考資料:知識來源 - 取得狀態

對於包含資料匯入參數且正在主動匯入內容的請求回應,可能如下範例。

{
  "kind": "azureBlob",
  "synchronizationStatus": "active",
  "synchronizationInterval": "1d",
  "currentSynchronizationState": {
    "startTime": "2026-04-10T19:30:00Z",
    "itemUpdatesProcessed": 1100,
    "itemsUpdatesFailed": 100,
    "itemsSkipped": 1100,
    "errors": [
      {
        "key": "Item id 1",
        "docURL": "https://contoso.blob.core.windows.net/contracts/2024/Q4/doc-00023.csv",
        "statusCode": 400,
        "componentName": "DocumentExtraction.AzureBlob.MyDataSource",
        "errorMessage": "Could not read the value of column 'foo' at index '0'.",
        "details": "The file could not be parsed.",
        "documentationLink": "https://go.microsoft.com/fwlink/?linkid=2049388"
      }
    ]
  },
  "lastSynchronizationState": {
    "status": "partialSuccess",
    "startTime": "2026-04-09T19:30:00Z",
    "endTime": "2026-04-09T19:40:01Z",
    "itemUpdatesProcessed": 1100,
    "itemsUpdatesFailed": 100,
    "itemsSkipped": 1100,
    "errors": null
  },
  "statistics": {
    "totalSynchronizations": 25,
    "averageSynchronizationDuration": "00:15:20",
    "averageItemsProcessedPerSynchronization": 500
  }
}

Note

kind屬性和currentSynchronizationState.errors[]陣列提供文件層級錯誤細節,並自 2026-04-01 起於 API 版本中提供。 對於較早期的 API 版本,這些欄位不會回傳。 lastSynchronizationState.status這個欄位也是在 2026-04-01 新增的。

檢視產生的物件

當你建立這個知識來源時,Azure AI 搜尋服務 會自動產生資料來源、技能集、索引器和索引。 建立回應會列出 createdResources 下的每個物件。

這些物件依據固定模板產生,名稱則取自知識來源的名稱。 你無法更改物件名稱。 避免直接編輯這些物件,因為變更可能會產生錯誤或不相容,破壞索引器管線。

你可以使用 Azure 入口網站來驗證物件建立。 工作流程為:

  1. 檢查索引器上的成功或失敗訊息。 連線或配額錯誤會出現在這裡。

  2. 請檢查資料來源以確認與資料儲存的連結。 此連線會依據您設定知識來源的方式,使用連接字串或受控識別。

  3. 檢查技能集,查看您的內容如何分塊,以及是否已選擇性地向量化。

  4. 檢查索引,了解你的內容如何被索引並展示以便檢索,包括哪些欄位可搜尋和篩選,哪些欄位儲存向量以便相似度搜尋。 使用搜尋總管對產生的索引執行查詢。

指派至知識庫

如果你對知識來源感到滿意,就 把它加入知識庫。

查詢知識庫

知識庫設定完成後, 呼叫擷取動作或 MCP 端點 查詢知識來源。

刪除知識來源

在刪除知識來源之前,必須刪除所有引用該來源的知識庫,或更新知識庫定義以移除該參考。 對於產生索引與索引管線的知識來源,所有 產生的物件 也會被刪除。 不過,如果你用現有的索引建立知識來源,你的索引不會被刪除。

如果你嘗試刪除正在使用的知識來源,該動作會失敗,並回傳一份受影響的知識庫清單。

刪除知識來源:

  1. 取得你搜尋服務中所有知識庫的清單。

    using Azure.Search.Documents.Indexes;
    
    var indexClient = new SearchIndexClient(new Uri(searchEndpoint), credential);
    var knowledgeBases = indexClient.GetKnowledgeBasesAsync();
    
    Console.WriteLine("Knowledge Bases:");
    
    await foreach (var kb in knowledgeBases)
    {
        Console.WriteLine($"  - {kb.Name}");
    }
    

    參考資料:SearchIndexClient

    範例回應可能如下所示:

     {
         "@odata.context": "https://my-search-service.search.windows.net/$metadata#knowledgebases(name)",
         "value": [
         {
             "name": "my-kb"
         },
         {
             "name": "my-kb-2"
         }
         ]
     }
    
  2. 取得一個獨立的知識庫定義,以檢查是否有知識來源的參考。

    using Azure.Search.Documents.Indexes;
    using System.Text.Json;
    
    var indexClient = new SearchIndexClient(new Uri(searchEndpoint), credential);
    
    // Specify the knowledge base name to retrieve
    string kbNameToGet = "earth-knowledge-base";
    
    // Get a specific knowledge base definition
    var knowledgeBaseResponse = await indexClient.GetKnowledgeBaseAsync(kbNameToGet);
    var kb = knowledgeBaseResponse.Value;
    
    // Serialize to JSON for display
    string json = JsonSerializer.Serialize(kb, new JsonSerializerOptions { WriteIndented = true });
    Console.WriteLine(json);
    

    參考資料:SearchIndexClient

    範例回應可能如下所示:

     {
       "Name": "earth-knowledge-base",
       "KnowledgeSources": [
         {
           "Name": "earth-knowledge-source"
         }
       ],
       "Models": [
         {}
       ],
       "RetrievalReasoningEffort": {},
       "OutputMode": {},
       "ETag": "\u00220x8DE278629D782B3\u0022",
       "EncryptionKey": null,
       "Description": null,
       "RetrievalInstructions": null,
       "AnswerInstructions": null
     }
    
  3. 要麼刪除知識庫,要麼如果你有多個知識來源,就更新知識庫來移除該來源。 這個例子顯示刪除。

    using Azure.Search.Documents.Indexes;
    var indexClient = new SearchIndexClient(new Uri(searchEndpoint), credential);
    
    await indexClient.DeleteKnowledgeBaseAsync(knowledgeBaseName);
    System.Console.WriteLine($"Knowledge base '{knowledgeBaseName}' deleted successfully.");
    

    參考資料:SearchIndexClient

  4. 刪除知識來源。

    await indexClient.DeleteKnowledgeSourceAsync(knowledgeSourceName);
    System.Console.WriteLine($"Knowledge source '{knowledgeSourceName}' deleted successfully.");
    

    參考資料:SearchIndexClient

  1. 取得你搜尋服務中所有知識庫的清單。

    # Get knowledge bases
    from azure.core.credentials import AzureKeyCredential
    from azure.search.documents.indexes import SearchIndexClient
    
    index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))
    
    print("Knowledge Bases:")
    for kb in index_client.list_knowledge_bases():
        print(f"  - {kb.name}")
    

    參考資料:SearchIndexClient

    範例回應可能如下所示:

     {
         "@odata.context": "https://my-search-service.search.windows.net/$metadata#knowledgebases(name)",
         "value": [
         {
             "name": "my-kb"
         },
         {
             "name": "my-kb-2"
         }
         ]
     }
    
  2. 取得一個獨立的知識庫定義,以檢查是否有知識來源的參考。

    # Get a knowledge base definition
    from azure.core.credentials import AzureKeyCredential
    from azure.search.documents.indexes import SearchIndexClient
    
    index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))
    kb = index_client.get_knowledge_base("knowledge_base_name")
    print(kb)
    

    參考資料:SearchIndexClient

    範例回應可能如下所示:

     {
       "name": "my-kb",
       "description": null,
       "retrievalInstructions": null,
       "answerInstructions": null,
       "outputMode": null,
       "knowledgeSources": [
         {
           "name": "my-blob-ks"
         }
       ],
       "models": [],
       "encryptionKey": null,
       "retrievalReasoningEffort": {
         "kind": "low"
       }
     }
    
  3. 要麼刪除知識庫,要麼如果你有多個知識來源,就更新知識庫來移除該來源。 這個例子顯示刪除。

    # Delete a knowledge base
    from azure.core.credentials import AzureKeyCredential 
    from azure.search.documents.indexes import SearchIndexClient
    
    index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))
    index_client.delete_knowledge_base("knowledge_base_name")
    print(f"Knowledge base deleted successfully.")
    

    參考資料:SearchIndexClient

  4. 刪除知識來源。

    # Delete a knowledge source
    from azure.core.credentials import AzureKeyCredential 
    from azure.search.documents.indexes import SearchIndexClient
    
    index_client = SearchIndexClient(endpoint = "search_url", credential = AzureKeyCredential("api_key"))
    index_client.delete_knowledge_source("knowledge_source_name")
    print(f"Knowledge source deleted successfully.")
    

    參考資料:SearchIndexClient

  1. 取得你搜尋服務中所有知識庫的清單。

    ### Get knowledge bases
    GET {{search-url}}/knowledgebases?api-version={{api-version}}&$select=name
    Authorization: Bearer {{token}}
    

    參考資料:知識庫列表

    範例回應可能如下所示:

     {
         "@odata.context": "https://my-search-service.search.windows.net/$metadata#knowledgebases(name)",
         "value": [
         {
             "name": "my-kb"
         },
         {
             "name": "my-kb-2"
         }
         ]
     }
    
  2. 取得一個獨立的知識庫定義,以檢查是否有知識來源的參考。

    ### Get a knowledge base definition
    GET {{search-url}}/knowledgebases/{{knowledge-base-name}}?api-version={{api-version}}
    Authorization: Bearer {{token}}
    

    參考資料:知識庫 - 取得

    範例回應可能如下所示:

     {
       "name": "my-kb",
       "description": null,
       "retrievalInstructions": null,
       "answerInstructions": null,
       "outputMode": null,
       "knowledgeSources": [
         {
           "name": "my-blob-ks"
         }
       ],
       "models": [],
       "encryptionKey": null,
       "retrievalReasoningEffort": {
         "kind": "low"
       }
     }
    
  3. 要麼刪除知識庫,要麼如果你有多個知識來源,就更新知識庫來移除該來源。 這個例子顯示刪除。

    ### Delete a knowledge base
    DELETE {{search-url}}/knowledgebases/{{knowledge-base-name}}?api-version={{api-version}}
    Authorization: Bearer {{token}}
    

    參考資料:知識庫 - 刪除

  4. 刪除知識來源。

    ### Delete a knowledge source
    DELETE {{search-url}}/knowledgesources/{{knowledge-source-name}}?api-version={{api-version}}
    Authorization: Bearer {{token}}
    

    參考資料:知識來源 - 刪除