共用方式為


從 Azure Blob Storage 和 ADLS Gen2 建立 Blob 知識庫

備註

這項功能目前處於公開預覽狀態。 此預覽版在沒有服務等級協議的情況下提供,不建議用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

使用 blob 知識來源,在具代理特性的檢索管線中編製索引和查詢 Azure blob 內容。 知識來源 獨立建立,並在 知識庫中被引用,並作為代理或聊天機器人在查詢時呼叫 擷取動作 時的基礎資料。

不同於指定現有且限定索引的 搜尋索引知識來源,Blob 知識來源會指定外部資料來源、模型和屬性,以自動產生下列 Azure AI 搜尋服務物件:

  • 代表 Blob 容器的資料來源。
  • 從容器分塊並選擇性向量化多模式內容的技能集。
  • 儲存擴充內容並符合代理程式擷取準則的索引。
  • 使用先前物件來驅動編製索引和擴充管線的索引子。

備註

若在 Azure Storage 的文件(blob)層級指定使用者存取,知識來源可將權限元資料轉發至 Azure AI Search 的索引內容。 欲了解更多資訊,請參閱 ADLS Gen2 權限元資料Blob RBAC 範圍。

先決條件

檢查現有的知識來源

知識來源是一個頂層、可重複使用的物件。 瞭解現有的知識來源有助於重複使用或命名新物件。

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

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

您也可以按名稱傳回單一知識來源以檢閱其 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));

以下 JSON 是一個針對 blob 知識來源的範例回應。

{
  "name": "my-blob-ks",
  "kind": "azureBlob",
  "description": "A sample blob knowledge source.",
  "encryptionKey": null,
  "azureBlobParameters": {
    "connectionString": "<REDACTED>",
    "containerName": "blobcontainer",
    "folderPath": null,
    "isADLSGen2": false,
    "ingestionParameters": {
      "disableImageVerbalization": false,
      "ingestionPermissionOptions": [],
      "contentExtractionMode": "standard",
      "identity": null,
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "text-embedding-3-large",
          "apiKey": "<REDACTED>",
          "modelName": "text-embedding-3-large",
          "authIdentity": null
        }
      },
      "chatCompletionModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "gpt-5-mini",
          "apiKey": "<REDACTED>",
          "modelName": "gpt-5-mini",
          "authIdentity": null
        }
      },
      "ingestionSchedule": null,
      "assetStore": null,
      "aiServices": {
        "uri": "<REDACTED>",
        "apiKey": "<REDACTED>"
      }
    },
    "createdResources": {
      "datasource": "my-blob-ks-datasource",
      "indexer": "my-blob-ks-indexer",
      "skillset": "my-blob-ks-skillset",
      "index": "my-blob-ks-index"
    }
  }
}

備註

敏感性資訊已被遮蔽。 產生的資源會出現在回應的結尾。

建立知識來源

執行以下程式碼來 建立一個 blob 知識來源

// Create a blob knowledge source
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.KnowledgeBases.Models;
using Azure;

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

var chatCompletionParams = new AzureOpenAIVectorizerParameters
{
    ResourceUri = new Uri(aoaiEndpoint),
    DeploymentName = aoaiGptDeployment,
    ModelName = aoaiGptModel
};

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

var ingestionParams = new KnowledgeSourceIngestionParameters
{
    DisableImageVerbalization = false,
    ChatCompletionModel = new KnowledgeBaseAzureOpenAIModel(azureOpenAIParameters: chatCompletionParams),
    EmbeddingModel = new KnowledgeSourceAzureOpenAIVectorizer
    {
        AzureOpenAIParameters = embeddingParams
    }
};

var blobParams = new AzureBlobKnowledgeSourceParameters(
    connectionString: connectionString,
    containerName: containerName
)
{
    IsAdlsGen2 = false,
    IngestionParameters = ingestionParams
};

var knowledgeSource = new AzureBlobKnowledgeSource(
    name: "my-blob-ks",
    azureBlobParameters: blobParams
)
{
    Description = "This knowledge source pulls from a blob storage container."
};

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

來源特異性特性

你可以傳遞以下屬性來建立一個 blob 知識來源。

名稱 Description 類型 可編輯 為必填項目
name 知識來源的名稱必須在知識來源集合中唯一,並遵循 Azure AI 搜尋中物件 的命名指引 繩子 Yes
Description 這是知識來源的描述。 繩子 Yes
encryptionKey 客戶管理的金鑰 ,用於加密知識來源與產生物件中的敏感資訊。 物體 Yes
chatCompletionParams 專用於聊天完成模型的參數,這些模型用於查詢規劃,以及在檢索推理工作量為低或中等時選用的答案合成。 物體
embeddingParams 這些參數專門用於嵌入模型,如果你想向量化內容區塊。 物體
azureBlobParameters 針對 blob 知識來源的參數:connectionStringcontainerNamefolderPathisAdlsGen2 物體
connectionString 金鑰型連接字串,或 (若使用受控識別) 資源 ID。 繩子 Yes
containerName Blob 儲存體容器的名稱。 繩子 Yes
folderPath 容器裡的一個資料夾。 繩子
isAdlsGen2 預設值為 False。 如果你使用ADLS Gen2儲存帳號,請設定為True 布林值

ingestionParameters 屬性

僅針對索引的知識來源,您可以傳遞以下 ingestionParameters 屬性來控制內容的擷取與處理方式。

名稱 Description 類型 可編輯 為必填項目
Identity 用於生成索引器的 托管身份 物體 Yes
DisableImageVerbalization 啟用或禁止影像語言化的使用。 預設為 False使影像語言化成為可能 。 設定為 True停用影像語言化。 布林值
ChatCompletionModel 一種能用語音表達圖片或擷取內容的聊天完成模型。 支援的模型有 gpt-4ogpt-4o-minigpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nano和 。 生成的技能組將包含GenAI Prompt技能。 設定此參數也需要 disable_image_verbalization 將 設為 False 物體 只有 api_keydeployment_name 是可編輯的
EmbeddingModel 一個文字嵌入模型,能在索引及查詢時將文字與影像內容向量化。 支援的模型有 text-embedding-ada-002、 、 text-embedding-3-smalltext-embedding-3-large和 。 Azure OpenAI 嵌入式技能 將包含在生成的技能集中,Azure OpenAI 向量器 則會包含在生成的索引中。 物體 只有 api_keydeployment_name 是可編輯的
ContentExtractionMode 控制內容如何從檔案中擷取。 預設為 minimal,使用標準內容擷取來處理文字與圖片。 設定為 standard 使用 Azure 內容理解技能進行進階文件破解與分塊,該技能將包含在生成的技能組中。 僅限於 standard,可以指定參數 AiServicesAssetStore 繩子
AiServices 一個 Microsoft Foundry 資源,用於存取 Azure Content Understanding in Foundry Tools。 設定此參數必須將ContentExtractionMode設為standard 物體 只有 api_key 是可編輯的 Yes
IngestionSchedule 將排程資訊加入產生的索引器。 您也可以稍後 新增排程 ,以自動重新整理資料。 物體 Yes
IngestionPermissionOptions 要從選取知識來源內嵌的文件層級權限:ADLS Gen2已編製索引的 SharePoint。 如果您指定 user_idsgroup_idsrbac_scope,產生的 ADLS Gen2 索引器SharePoint 索引器 將包含所接收的權限。 Array

檢查內嵌狀態

執行以下程式碼以監視擷取的進度與健康情況,包括那些產生索引器管線並填入搜尋索引的知識來源的索引器狀態

// Get knowledge source ingestion status
using Azure.Search.Documents.Indexes;
using System.Text.Json;

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

// Get the knowledge source 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);

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

{ 
  "synchronizationStatus": "active", // creating, active, deleting 
  "synchronizationInterval" : "1d", // null if no schedule 
  "currentSynchronizationState" : { // spans multiple indexer "runs" 
    "startTime": "2025-10-27T19:30:00Z", 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "lastSynchronizationState" : {  // null on first sync 
    "startTime": "2025-10-27T19:30:00Z", 
    "endTime": "2025-10-27T19:40:01Z", // this value appears on the activity record on each /retrieve 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "statistics": {  // null on first sync 
    "totalSynchronization": 25, 
    "averageSynchronizationDuration": "00:15:20", 
    "averageItemsProcessedPerSynchronization" : 500 
  } 
} 

檢閱已建立的物件

當你建立 blob 知識來源時,搜尋服務也會建立索引器、索引、技能集和資料來源。 我們不建議你編輯這些物件,因為引入錯誤或不相容可能會破壞管線。

建立知識來源之後,回應會列出已建立的物件。 這些物件是根據固定的範本建立的,其名稱是根據知識來源的名稱而建立的。 您無法變更物件名稱。

建議您使用 Azure 入口網站來驗證輸出建立。 工作流程為:

  1. 檢查索引子是否有成功或失敗訊息。 連線或配額錯誤會出現在這裡。
  2. 檢查索引中是否有可搜尋的內容。 使用 Search Explorer 來執行查詢。
  3. 檢查技能集,了解如何將您的內容進行分塊和選擇性向量化。
  4. 請查看資料來源以獲取連接細節。 我們的範例使用 API 金鑰以簡化流程,但你也可以使用 Microsoft Entra ID 來進行認證,並用基於角色的存取控制來授權。

指派到知識庫

如果你對知識來源感到滿意,就繼續下一步:在 知識庫中指定知識來源。

知識庫設定完成後,使用 擷取動作 查詢知識來源。

刪除知識來源

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

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

刪除知識來源:

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

    範例回應可能如下所示:

     Knowledge Bases:
       - earth-knowledge-base
       - hotels-sample-knowledge-base
       - my-demo-knowledge-base
    
  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);
    

    範例回應可能如下所示:

     {
       "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.");
    
  4. 刪除知識來源。

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

備註

這項功能目前處於公開預覽狀態。 此預覽版在沒有服務等級協議的情況下提供,不建議用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

使用 blob 知識來源,在具代理特性的檢索管線中編製索引和查詢 Azure blob 內容。 知識來源 獨立建立,並在 知識庫中被引用,並作為代理或聊天機器人在查詢時呼叫 擷取動作 時的基礎資料。

不同於指定現有且限定索引的 搜尋索引知識來源,Blob 知識來源會指定外部資料來源、模型和屬性,以自動產生下列 Azure AI 搜尋服務物件:

  • 代表 Blob 容器的資料來源。
  • 從容器分塊並選擇性向量化多模式內容的技能集。
  • 儲存擴充內容並符合代理程式擷取準則的索引。
  • 使用先前物件來驅動編製索引和擴充管線的索引子。

備註

若在 Azure Storage 的文件(blob)層級指定使用者存取,知識來源可將權限元資料轉發至 Azure AI Search 的索引內容。 欲了解更多資訊,請參閱 ADLS Gen2 權限元資料Blob RBAC 範圍。

先決條件

檢查現有的知識來源

知識來源是一個頂層、可重複使用的物件。 瞭解現有的知識來源有助於重複使用或命名新物件。

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

# List knowledge sources by name and type
import requests
import json

endpoint = "{search_url}/knowledgesources"
params = {"api-version": "2025-11-01-preview", "$select": "name, kind"}
headers = {"api-key": "{api_key}"}

response = requests.get(endpoint, params = params, headers = headers)
print(json.dumps(response.json(), indent = 2))

您也可以按名稱傳回單一知識來源以檢閱其 JSON 定義。

# Get a knowledge source definition
import requests
import json

endpoint = "{search_url}/knowledgesources/{knowledge_source_name}"
params = {"api-version": "2025-11-01-preview"}
headers = {"api-key": "{api_key}"}

response = requests.get(endpoint, params = params, headers = headers)
print(json.dumps(response.json(), indent = 2))

以下 JSON 是一個針對 blob 知識來源的範例回應。

{
  "name": "my-blob-ks",
  "kind": "azureBlob",
  "description": "A sample blob knowledge source.",
  "encryptionKey": null,
  "azureBlobParameters": {
    "connectionString": "<REDACTED>",
    "containerName": "blobcontainer",
    "folderPath": null,
    "isADLSGen2": false,
    "ingestionParameters": {
      "disableImageVerbalization": false,
      "ingestionPermissionOptions": [],
      "contentExtractionMode": "standard",
      "identity": null,
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "text-embedding-3-large",
          "apiKey": "<REDACTED>",
          "modelName": "text-embedding-3-large",
          "authIdentity": null
        }
      },
      "chatCompletionModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "gpt-5-mini",
          "apiKey": "<REDACTED>",
          "modelName": "gpt-5-mini",
          "authIdentity": null
        }
      },
      "ingestionSchedule": null,
      "assetStore": null,
      "aiServices": {
        "uri": "<REDACTED>",
        "apiKey": "<REDACTED>"
      }
    },
    "createdResources": {
      "datasource": "my-blob-ks-datasource",
      "indexer": "my-blob-ks-indexer",
      "skillset": "my-blob-ks-skillset",
      "index": "my-blob-ks-index"
    }
  }
}

備註

敏感性資訊已被遮蔽。 產生的資源會出現在回應的結尾。

建立知識來源

執行以下程式碼來建立一個 blob 知識來源。

# Create a blob knowledge source
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import AzureBlobKnowledgeSource, AzureBlobKnowledgeSourceParameters, KnowledgeBaseAzureOpenAIModel, AzureOpenAIVectorizerParameters, KnowledgeSourceAzureOpenAIVectorizer, KnowledgeSourceContentExtractionMode, KnowledgeSourceIngestionParameters

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

knowledge_source = AzureBlobKnowledgeSource(
    name = "my-blob-ks",
    description = "This knowledge source pulls from a blob storage container.",
    encryption_key = None,
    azure_blob_parameters = AzureBlobKnowledgeSourceParameters(
        connection_string = "blob_connection_string",
        container_name = "blob_container_name",
        folder_path = None,
        is_adls_gen2 = False,
        ingestion_parameters = KnowledgeSourceIngestionParameters(
            identity = None,
            disable_image_verbalization = False,
            chat_completion_model = KnowledgeBaseAzureOpenAIModel(
                azure_open_ai_parameters = AzureOpenAIVectorizerParameters(
                    # TRIMMED FOR BREVITY
                )
            ),
            embedding_model = KnowledgeSourceAzureOpenAIVectorizer(
                azure_open_ai_parameters=AzureOpenAIVectorizerParameters(
                    # TRIMMED FOR BREVITY
                )
            ),
            content_extraction_mode = KnowledgeSourceContentExtractionMode.MINIMAL,
            ingestion_schedule = None,
            ingestion_permission_options = None
        )
    )
)

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

來源特異性特性

你可以傳遞以下屬性來建立一個 blob 知識來源。

名稱 Description 類型 可編輯 為必填項目
name 知識來源的名稱必須在知識來源集合中唯一,並遵循 Azure AI 搜尋中物件 的命名指引 繩子 Yes
description 這是知識來源的描述。 繩子 Yes
encryption_key 客戶管理的金鑰 ,用於加密知識來源與產生物件中的敏感資訊。 物體 Yes
azure_blob_parameters 針對 blob 知識來源的參數:connection_stringcontainer_namefolder_pathis_adls_gen2 物體
connection_string 金鑰型連接字串,或 (若使用受控識別) 資源 ID。 繩子 Yes
container_name Blob 儲存體容器的名稱。 繩子 Yes
folder_path 容器裡的一個資料夾。 繩子
is_adls_gen2 預設值為 False。 如果你使用ADLS Gen2儲存帳號,請設定為True 布林值

ingestionParameters 屬性

僅針對索引的知識來源,您可以傳遞以下 ingestionParameters 屬性來控制內容的擷取與處理方式。

名稱 Description 類型 可編輯 為必填項目
identity 用於生成索引器的 托管身份 物體 Yes
disable_image_verbalization 啟用或禁止影像語言化的使用。 預設為 False使影像語言化成為可能 。 設定為 True停用影像語言化。 布林值
chat_completion_model 一種能用語音表達圖片或擷取內容的聊天完成模型。 支援的模型有 gpt-4ogpt-4o-minigpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nano和 。 生成的技能組將包含GenAI Prompt技能。 設定此參數也需要 disable_image_verbalization 將 設為 False 物體 只有 api_keydeployment_name 是可編輯的
embedding_model 一個文字嵌入模型,能在索引及查詢時將文字與影像內容向量化。 支援的模型有 text-embedding-ada-002、 、 text-embedding-3-smalltext-embedding-3-large和 。 Azure OpenAI 嵌入式技能 將包含在生成的技能集中,Azure OpenAI 向量器 則會包含在生成的索引中。 物體 只有 api_keydeployment_name 是可編輯的
content_extraction_mode 控制內容如何從檔案中擷取。 預設為 minimal,使用標準內容擷取來處理文字與圖片。 設定為 standard 使用 Azure 內容理解技能進行進階文件破解與分塊,該技能將包含在生成的技能組中。 僅限於 standard,可以指定參數 ai_servicesasset_store 繩子
ai_services 一個 Microsoft Foundry 資源,用於存取 Azure Content Understanding in Foundry Tools。 設定此參數必須將content_extraction_mode設為standard 物體 只有 api_key 是可編輯的 Yes
asset_store 一個用來儲存擷取影像的 blob 容器。 設定此參數必須將content_extraction_mode設為standard 物體
ingestion_schedule 將排程資訊加入產生的索引器。 您也可以稍後 新增排程 ,以自動重新整理資料。 物體 Yes
ingestion_permission_options 要從選取知識來源內嵌的文件層級權限:ADLS Gen2已編製索引的 SharePoint。 如果您指定 user_idsgroup_idsrbac_scope,產生的 ADLS Gen2 索引器SharePoint 索引器 將包含所接收的權限。 Array

檢查內嵌狀態

執行以下程式碼以監控資料匯入進度與健康狀態,包括知識來源的索引器狀態,此索引器會產生索引器管線並填充搜尋索引。

# Check knowledge source ingestion status
import requests
import json

endpoint = "{search_url}/knowledgesources/{knowledge_source_name}/status"
params = {"api-version": "2025-11-01-preview"}
headers = {"api-key": "{api_key}"}

response = requests.get(endpoint, params = params, headers = headers)
print(json.dumps(response.json(), indent = 2))

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

{ 
  "synchronizationStatus": "active", // creating, active, deleting 
  "synchronizationInterval" : "1d", // null if no schedule 
  "currentSynchronizationState" : { // spans multiple indexer "runs" 
    "startTime": "2025-10-27T19:30:00Z", 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "lastSynchronizationState" : {  // null on first sync 
    "startTime": "2025-10-27T19:30:00Z", 
    "endTime": "2025-10-27T19:40:01Z", // this value appears on the activity record on each /retrieve 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "statistics": {  // null on first sync 
    "totalSynchronization": 25, 
    "averageSynchronizationDuration": "00:15:20", 
    "averageItemsProcessedPerSynchronization" : 500 
  } 
} 

檢閱已建立的物件

當你建立 blob 知識來源時,搜尋服務也會建立索引器、索引、技能集和資料來源。 我們不建議你編輯這些物件,因為引入錯誤或不相容可能會破壞管線。

建立知識來源之後,回應會列出已建立的物件。 這些物件是根據固定的範本建立的,其名稱是根據知識來源的名稱而建立的。 您無法變更物件名稱。

建議您使用 Azure 入口網站來驗證輸出建立。 工作流程為:

  1. 檢查索引子是否有成功或失敗訊息。 連線或配額錯誤會出現在這裡。
  2. 檢查索引中是否有可搜尋的內容。 使用 Search Explorer 來執行查詢。
  3. 檢查技能集,了解如何將您的內容進行分塊和選擇性向量化。
  4. 請查看資料來源以獲取連接細節。 我們的範例使用 API 金鑰以簡化流程,但你也可以使用 Microsoft Entra ID 來進行認證,並用基於角色的存取控制來授權。

指派到知識庫

如果你對知識來源感到滿意,就繼續下一步:在 知識庫中指定知識來源。

知識庫設定完成後,使用 擷取動作 查詢知識來源。

刪除知識來源

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

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

刪除知識來源:

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

    # Get knowledge bases
    import requests
    import json
    
    endpoint = "{search_url}/knowledgebases"
    params = {"api-version": "2025-11-01-preview", "$select": "name"}
    headers = {"api-key": "{api_key}"}
    
    response = requests.get(endpoint, params = params, headers = headers)
    print(json.dumps(response.json(), indent = 2))
    

    範例回應可能如下所示:

     {
         "@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
    import requests
    import json
    
    endpoint = "{search_url}/knowledgebases/{knowledge_base_name}"
    params = {"api-version": "2025-11-01-preview"}
    headers = {"api-key": "{api_key}"}
    
    response = requests.get(endpoint, params = params, headers = headers)
    print(json.dumps(response.json(), indent = 2))
    

    範例回應可能如下所示:

     {
       "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.")
    
  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.")
    

備註

這項功能目前處於公開預覽狀態。 此預覽版在沒有服務等級協議的情況下提供,不建議用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

使用 blob 知識來源,在具代理特性的檢索管線中編製索引和查詢 Azure blob 內容。 知識來源 獨立建立,並在 知識庫中被引用,並作為代理或聊天機器人在查詢時呼叫 擷取動作 時的基礎資料。

不同於指定現有且限定索引的 搜尋索引知識來源,Blob 知識來源會指定外部資料來源、模型和屬性,以自動產生下列 Azure AI 搜尋服務物件:

  • 代表 Blob 容器的資料來源。
  • 從容器分塊並選擇性向量化多模式內容的技能集。
  • 儲存擴充內容並符合代理程式擷取準則的索引。
  • 使用先前物件來驅動編製索引和擴充管線的索引子。

備註

若在 Azure Storage 的文件(blob)層級指定使用者存取,知識來源可將權限元資料轉發至 Azure AI Search 的索引內容。 欲了解更多資訊,請參閱 ADLS Gen2 權限元資料Blob RBAC 範圍。

先決條件

檢查現有的知識來源

知識來源是一個頂層、可重複使用的物件。 瞭解現有的知識來源有助於重複使用或命名新物件。

使用 知識來源 - 取得 (REST API) 依名稱和類型列出知識來源。

### List knowledge sources by name and type
GET {{search-url}}/knowledgesources?api-version=2025-11-01-preview&$select=name,kind
api-key: {{api-key}}

您也可以按名稱傳回單一知識來源以檢閱其 JSON 定義。

### Get a knowledge source definition
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}?api-version=2025-11-01-preview
api-key: {{api-key}}

以下 JSON 是一個針對 blob 知識來源的範例回應。

{
  "name": "my-blob-ks",
  "kind": "azureBlob",
  "description": "A sample blob knowledge source.",
  "encryptionKey": null,
  "azureBlobParameters": {
    "connectionString": "<REDACTED>",
    "containerName": "blobcontainer",
    "folderPath": null,
    "isADLSGen2": false,
    "ingestionParameters": {
      "disableImageVerbalization": false,
      "ingestionPermissionOptions": [],
      "contentExtractionMode": "standard",
      "identity": null,
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "text-embedding-3-large",
          "apiKey": "<REDACTED>",
          "modelName": "text-embedding-3-large",
          "authIdentity": null
        }
      },
      "chatCompletionModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "gpt-5-mini",
          "apiKey": "<REDACTED>",
          "modelName": "gpt-5-mini",
          "authIdentity": null
        }
      },
      "ingestionSchedule": null,
      "assetStore": null,
      "aiServices": {
        "uri": "<REDACTED>",
        "apiKey": "<REDACTED>"
      }
    },
    "createdResources": {
      "datasource": "my-blob-ks-datasource",
      "indexer": "my-blob-ks-indexer",
      "skillset": "my-blob-ks-skillset",
      "index": "my-blob-ks-index"
    }
  }
}

備註

敏感性資訊已被遮蔽。 產生的資源會出現在回應的結尾。

建立知識來源

使用 Knowledge Sources - Create 或 Update(REST API) 來建立一個 blob 知識來源。

PUT {{search-url}}/knowledgesources/my-blob-ks?api-version=2025-11-01-preview
api-key: {{api-key}}
Content-Type: application/json

{
  "name": "my-blob-ks",
  "kind": "azureBlob",
  "description": "This knowledge source pulls from a blob storage container.",
  "encryptionKey": null,
  "azureBlobParameters": {
    "connectionString": "<YOUR AZURE STORAGE CONNECTION STRING>",
    "containerName": "<YOUR BLOB CONTAINER NAME>",
    "folderPath": null,
    "isADLSGen2": false,
    "ingestionParameters": {
        "identity": null,
        "disableImageVerbalization": null,
        "chatCompletionModel": { TRIMMED FOR BREVITY },
        "embeddingModel": { TRIMMED FOR BREVITY },
        "contentExtractionMode": "minimal",
        "ingestionSchedule": null,
        "ingestionPermissionOptions": []
    }
  }
}

來源特異性特性

你可以傳遞以下屬性來建立一個 blob 知識來源。

名稱 Description 類型 可編輯 為必填項目
name 知識來源的名稱必須在知識來源集合中唯一,並遵循 Azure AI 搜尋中物件 的命名指引 繩子 Yes
kind 這種知識來源,在這個情況下是 azureBlob 繩子 Yes
description 這是知識來源的描述。 繩子 Yes
encryptionKey 客戶管理的金鑰 ,用於加密知識來源與產生物件中的敏感資訊。 物體 Yes
azureBlobParameters 針對 blob 知識來源的參數:connectionStringcontainerNamefolderPathisADLSGen2 物體
connectionString 金鑰型連接字串,或 (若使用受控識別) 資源 ID。 繩子 Yes
containerName Blob 儲存體容器的名稱。 繩子 Yes
folderPath 容器裡的一個資料夾。 繩子
isADLSGen2 預設值為 false。 如果你使用ADLS Gen2儲存帳號,請設定為true 布林值

ingestionParameters 屬性

僅針對索引的知識來源,您可以傳遞以下 ingestionParameters 屬性來控制內容的擷取與處理方式。

名稱 Description 類型 可編輯 為必填項目
identity 用於生成索引器的 托管身份 物體 Yes
disableImageVerbalization 啟用或禁止影像語言化的使用。 預設為 false使影像語言化成為可能 。 設定為 true停用影像語言化。 布林值
chatCompletionModel 一種能用語音表達圖片或擷取內容的聊天完成模型。 支援的模型有 gpt-4ogpt-4o-minigpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nano和 。 生成的技能組將包含GenAI Prompt技能。 設定此參數也需要 disableImageVerbalization 將 設為 false 物體 只有 apiKeydeploymentId 是可編輯的
embeddingModel 一個文字嵌入模型,能在索引及查詢時將文字與影像內容向量化。 支援的模型有 text-embedding-ada-002、 、 text-embedding-3-smalltext-embedding-3-large和 。 Azure OpenAI 嵌入式技能 將包含在生成的技能集中,Azure OpenAI 向量器 則會包含在生成的索引中。 物體 只有 apiKeydeploymentId 是可編輯的
contentExtractionMode 控制內容如何從檔案中擷取。 預設為 minimal,使用標準內容擷取來處理文字與圖片。 設定為 standard 使用 Azure 內容理解技能進行進階文件破解與分塊,該技能將包含在生成的技能組中。 僅限於 standard,可以指定參數 aiServicesassetStore 繩子
aiServices 一個 Microsoft Foundry 資源,用於存取 Azure Content Understanding in Foundry Tools。 設定此參數必須將contentExtractionMode設為standard 物體 只有 apiKey 是可編輯的 Yes
assetStore 一個用來儲存擷取影像的 blob 容器。 設定此參數必須將contentExtractionMode設為standard 物體
ingestionSchedule 將排程資訊加入產生的索引器。 您也可以稍後 新增排程 ,以自動重新整理資料。 物體 Yes
ingestionPermissionOptions 要從選取知識來源內嵌的文件層級權限:ADLS Gen2已編製索引的 SharePoint。 如果您指定 userIdsgroupIdsrbacScope,產生的 ADLS Gen2 索引器SharePoint 索引器 將包含所接收的權限。 Array

檢查內嵌狀態

使用 Knowledge Sources - Status(REST API) 來監控資料擷取進度與健康狀態,包括產生索引器管線並填充搜尋索引的知識來源索引器狀態。

### Check knowledge source ingestion status
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}/status?api-version=2025-11-01-preview
api-key: {{api-key}}
Content-Type: application/json 

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

{ 
  "synchronizationStatus": "active", // creating, active, deleting 
  "synchronizationInterval" : "1d", // null if no schedule 
  "currentSynchronizationState" : { // spans multiple indexer "runs" 
    "startTime": "2025-10-27T19:30:00Z", 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "lastSynchronizationState" : {  // null on first sync 
    "startTime": "2025-10-27T19:30:00Z", 
    "endTime": "2025-10-27T19:40:01Z", // this value appears on the activity record on each /retrieve 
    "itemUpdatesProcessed": 1100, 
    "itemsUpdatesFailed": 100, 
    "itemsSkipped": 1100, 
  }, 
  "statistics": {  // null on first sync 
    "totalSynchronization": 25, 
    "averageSynchronizationDuration": "00:15:20", 
    "averageItemsProcessedPerSynchronization" : 500 
  } 
} 

檢閱已建立的物件

當你建立 blob 知識來源時,搜尋服務也會建立索引器、索引、技能集和資料來源。 我們不建議你編輯這些物件,因為引入錯誤或不相容可能會破壞管線。

建立知識來源之後,回應會列出已建立的物件。 這些物件是根據固定的範本建立的,其名稱是根據知識來源的名稱而建立的。 您無法變更物件名稱。

建議您使用 Azure 入口網站來驗證輸出建立。 工作流程為:

  1. 檢查索引子是否有成功或失敗訊息。 連線或配額錯誤會出現在這裡。
  2. 檢查索引中是否有可搜尋的內容。 使用 Search Explorer 來執行查詢。
  3. 檢查技能集,了解如何將您的內容進行分塊和選擇性向量化。
  4. 請查看資料來源以獲取連接細節。 我們的範例使用 API 金鑰以簡化流程,但你也可以使用 Microsoft Entra ID 來進行認證,並用基於角色的存取控制來授權。

指派到知識庫

如果你對知識來源感到滿意,就繼續下一步:在 知識庫中指定知識來源。

知識庫設定完成後,使用 擷取動作 查詢知識來源。

刪除知識來源

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

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

刪除知識來源:

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

    ### Get knowledge bases
    GET {{search-endpoint}}/knowledgebases?api-version=2025-11-01-preview&$select=name
    api-key: {{api-key}}
    

    範例回應可能如下所示:

     {
         "@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-endpoint}}/knowledgebases/{{knowledge-base-name}}?api-version=2025-11-01-preview
    api-key: {{api-key}}
    

    範例回應可能如下所示:

     {
       "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-endpoint}}/knowledgebases/{{knowledge-base-name}}?api-version=2025-11-01-preview
    api-key: {{api-key}}
    
  4. 刪除知識來源。

    ### Delete a knowledge source
    DELETE {{search-endpoint}}/knowledgesources/{{knowledge-source-name}}?api-version=2025-11-01-preview
    api-key: {{api-key}}