次の方法で共有

从 Azure Blob 存储和 ADLS Gen2 创建 Blob 知识源

注释

此功能目前处于公开预览状态。 此预览版未随附服务级别协议,建议不要用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅适用于 Azure 预览版的补充使用条款

使用 Blob 知识来源在代理检索管道中为 Azure Blob 内容编制索引并对其进行查询。 知识源 是独立创建的,在 知识库中引用,并在代理或聊天机器人在查询时调用 检索作 时用作基础数据。

与指定现有合格索引的搜索索引知识源不同,Blob 知识源指定外部数据源、模型和属性,以自动生成以下 Azure AI 搜索对象:

  • 表示 Blob 容器的数据源。
  • 一个技能包,用于对来自容器内的多模态内容进行分块处理和可选矢量化。
  • 存储扩充内容并满足代理检索条件的索引。
  • 使用先前的对象来驱动索引和扩展管道的索引器。

注释

如果在 Azure 存储中的文档(blob)级别指定了用户访问,知识源可以将权限元数据转发到 Azure AI 搜索中的索引内容。 有关详细信息,请参阅 ADLS Gen2 权限元数据Blob RBAC 范围

先决条件

注释

尽管可以使用 Azure 门户创建 Blob 知识源,但门户使用 2025-08-01-preview,该预览版使用以前的“知识代理”术语,不支持所有 2025-11-01-preview 功能。 如需中断性变更方面的帮助,请参阅迁移智能体检索代码

检查现有知识来源

知识来源是顶级可重用对象。 了解现有知识源有助于重复使用或命名新对象。

运行以下代码,按名称和类型列出知识源。

// 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 知识源。

Name Description 类型 可编辑 必选
name 知识源的名称,该名称在知识源集合中必须是唯一的,并遵循 Azure AI 搜索中对象的 命名准则 String 是的
Description 知识源的说明。 String 是的
encryptionKey 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 物体 是的
chatCompletionParams 当检索推理工作量较低或中等时,聊天完成模型的特定参数用于查询计划和可选答案合成。 物体
embeddingParams 针对嵌入模型中用于将内容区块向量化的特定参数。 物体
azureBlobParameters 特定于 blob 知识源的参数:connectionStringcontainerNamefolderPathisAdlsGen2 物体
connectionString 基于密钥的 连接字符串 ,或者,如果使用托管标识,则为资源 ID。 String 是的
containerName Blob 存储容器的名称。 String 是的
folderPath 容器中的文件夹。 String
isAdlsGen2 默认值为 False。 如果使用的是 ADLS Gen2 存储帐户,则设置为 True 布尔

ingestionParameters 属性

仅对于索引知识源,可以传递以下 ingestionParameters 属性来控制内容引入和处理方式。

Name Description 类型 可编辑 必选
Identity 生成的索引器中要使用的托管标识 物体 是的
DisableImageVerbalization 启用或禁用图像描述功能。 默认值为False启用图像描述功能。 将True设置为禁用图像描述功能。 布尔
ChatCompletionModel 一个聊天完成模型,用于口头处理图像或提取内容。 支持的模型包括gpt-4ogpt-4o-mini、、gpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nanoGenAI 提示技能将包含在生成的技能集中。 设置此参数还需要 disable_image_verbalization 设置为 False. 物体 api_keydeployment_name 可编辑
EmbeddingModel 一个文本嵌入模型,用于在索引编制和查询时向量文本和图像内容。 支持的模型是 text-embedding-ada-002text-embedding-3-small以及 text-embedding-3-largeAzure OpenAI 嵌入技能将包含在生成的技能集中,Azure OpenAI 向量器将包含在生成的索引中。 物体 api_keydeployment_name 可编辑
ContentExtractionMode 控制如何从文件中提取内容。 默认值为 minimal:对文本和图像使用标准内容提取。 将 standard 设置为使用 Azure 内容理解技能进行高级文档破解和分块,该技能将包含在生成的技能集中。 对于standard,仅AiServicesAssetStore参数是可指定的。 String
AiServices 用于在 Foundry 工具中访问 Azure 内容理解的 Azure Foundry 资源。 设置此参数需要 ContentExtractionMode 设置为 standard. 物体 api_key 可编辑 是的
IngestionSchedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 物体 是的
IngestionPermissionOptions 从所选知识源引入的文档级权限: ADLS Gen2。 如果指定 user_idsgroup_idsrbac_scope生成的 ADLS Gen2 索引器 将包含引入的权限。 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. 检查可搜索内容的索引。 使用搜索资源管理器运行查询。
  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.");
    

注释

此功能目前处于公开预览状态。 此预览版未随附服务级别协议,建议不要用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅适用于 Azure 预览版的补充使用条款

使用 Blob 知识来源在代理检索管道中为 Azure Blob 内容编制索引并对其进行查询。 知识源 是独立创建的,在 知识库中引用,并在代理或聊天机器人在查询时调用 检索作 时用作基础数据。

与指定现有合格索引的搜索索引知识源不同,Blob 知识源指定外部数据源、模型和属性,以自动生成以下 Azure AI 搜索对象:

  • 表示 Blob 容器的数据源。
  • 一个技能包,用于对来自容器内的多模态内容进行分块处理和可选矢量化。
  • 存储扩充内容并满足代理检索条件的索引。
  • 使用先前的对象来驱动索引和扩展管道的索引器。

注释

如果在 Azure 存储中的文档(blob)级别指定了用户访问,知识源可以将权限元数据转发到 Azure AI 搜索中的索引内容。 有关详细信息,请参阅 ADLS Gen2 权限元数据Blob RBAC 范围

先决条件

注释

尽管可以使用 Azure 门户创建 Blob 知识源,但门户使用 2025-08-01-preview,该预览版使用以前的“知识代理”术语,不支持所有 2025-11-01-preview 功能。 如需中断性变更方面的帮助,请参阅迁移智能体检索代码

检查现有知识来源

知识来源是顶级可重用对象。 了解现有知识源有助于重复使用或命名新对象。

运行以下代码,按名称和类型列出知识源。

# 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 知识源。

Name Description 类型 可编辑 必选
name 知识源的名称,该名称在知识源集合中必须是唯一的,并遵循 Azure AI 搜索中对象的 命名准则 String 是的
description 知识源的说明。 String 是的
encryption_key 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 物体 是的
azure_blob_parameters 特定于 blob 知识源的参数:connection_stringcontainer_namefolder_pathis_adls_gen2 物体
connection_string 基于密钥的 连接字符串 ,或者,如果使用托管标识,则为资源 ID。 String 是的
container_name Blob 存储容器的名称。 String 是的
folder_path 容器中的文件夹。 String
is_adls_gen2 默认值为 False。 如果使用的是 ADLS Gen2 存储帐户,则设置为 True 布尔

ingestionParameters 属性

仅对于索引知识源,可以传递以下 ingestionParameters 属性来控制内容引入和处理方式。

Name Description 类型 可编辑 必选
identity 生成的索引器中要使用的托管标识 物体 是的
disable_image_verbalization 启用或禁用图像描述功能。 默认值为False启用图像描述功能。 将True设置为禁用图像描述功能。 布尔
chat_completion_model 一个聊天完成模型,用于口头处理图像或提取内容。 支持的模型包括gpt-4ogpt-4o-mini、、gpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nanoGenAI 提示技能将包含在生成的技能集中。 设置此参数还需要 disable_image_verbalization 设置为 False. 物体 api_keydeployment_name 可编辑
embedding_model 一个文本嵌入模型,用于在索引编制和查询时向量文本和图像内容。 支持的模型是 text-embedding-ada-002text-embedding-3-small以及 text-embedding-3-largeAzure OpenAI 嵌入技能将包含在生成的技能集中,Azure OpenAI 向量器将包含在生成的索引中。 物体 api_keydeployment_name 可编辑
content_extraction_mode 控制如何从文件中提取内容。 默认值为 minimal:对文本和图像使用标准内容提取。 将 standard 设置为使用 Azure 内容理解技能进行高级文档破解和分块,该技能将包含在生成的技能集中。 对于standard,仅ai_servicesasset_store参数是可指定的。 String
ai_services 用于在 Foundry 工具中访问 Azure 内容理解的 Azure Foundry 资源。 设置此参数需要 content_extraction_mode 设置为 standard. 物体 api_key 可编辑 是的
asset_store 用于存储提取映像的 Blob 容器。 设置此参数需要 content_extraction_mode 设置为 standard. 物体
ingestion_schedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 物体 是的
ingestion_permission_options 要从特定知识源引入数据的文档级权限:如 ADLS Gen2。 如果指定 user_idsgroup_idsrbac_scope生成的 ADLS Gen2 索引器 将包含引入的权限。 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. 检查可搜索内容的索引。 使用搜索资源管理器运行查询。
  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.azure.cn/$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.")
    

注释

此功能目前处于公开预览状态。 此预览版未随附服务级别协议,建议不要用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅适用于 Azure 预览版的补充使用条款

使用 Blob 知识来源在代理检索管道中为 Azure Blob 内容编制索引并对其进行查询。 知识源 是独立创建的,在 知识库中引用,并在代理或聊天机器人在查询时调用 检索作 时用作基础数据。

与指定现有合格索引的搜索索引知识源不同,Blob 知识源指定外部数据源、模型和属性,以自动生成以下 Azure AI 搜索对象:

  • 表示 Blob 容器的数据源。
  • 一个技能包,用于对来自容器内的多模态内容进行分块处理和可选矢量化。
  • 存储扩充内容并满足代理检索条件的索引。
  • 使用先前的对象来驱动索引和扩展管道的索引器。

注释

如果在 Azure 存储中的文档(blob)级别指定了用户访问,知识源可以将权限元数据转发到 Azure AI 搜索中的索引内容。 有关详细信息,请参阅 ADLS Gen2 权限元数据Blob RBAC 范围

先决条件

注释

尽管可以使用 Azure 门户创建 Blob 知识源,但门户使用 2025-08-01-preview,该预览版使用以前的“知识代理”术语,不支持所有 2025-11-01-preview 功能。 如需中断性变更方面的帮助,请参阅迁移智能体检索代码

检查现有知识来源

知识来源是顶级可重用对象。 了解现有知识源有助于重复使用或命名新对象。

使用 知识源 - 获取(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"
    }
  }
}

注释

敏感信息已经过编修。 生成的资源显示在响应的末尾。

创建知识来源

使用 知识源 - 创建或更新(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 知识源。

Name Description 类型 可编辑 必选
name 知识源的名称,该名称在知识源集合中必须是唯一的,并遵循 Azure AI 搜索中对象的 命名准则 String 是的
kind 知识源的类型,其为azureBlob在本例中。 String 是的
description 知识源的说明。 String 是的
encryptionKey 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 物体 是的
azureBlobParameters 特定于 blob 知识源的参数:connectionStringcontainerNamefolderPathisADLSGen2 物体
connectionString 基于密钥的 连接字符串 ,或者,如果使用托管标识,则为资源 ID。 String 是的
containerName Blob 存储容器的名称。 String 是的
folderPath 容器中的文件夹。 String
isADLSGen2 默认值为 false。 如果使用的是 ADLS Gen2 存储帐户,则设置为 true 布尔

ingestionParameters 属性

仅对于索引知识源,可以传递以下 ingestionParameters 属性来控制内容引入和处理方式。

Name Description 类型 可编辑 必选
identity 生成的索引器中要使用的托管标识 物体 是的
disableImageVerbalization 启用或禁用图像描述功能。 默认值为false启用图像描述功能。 将true设置为禁用图像描述功能。 布尔
chatCompletionModel 一个聊天完成模型,用于口头处理图像或提取内容。 支持的模型包括gpt-4ogpt-4o-mini、、gpt-4.1gpt-4.1-minigpt-4.1-nanogpt-5gpt-5-minigpt-5-nanoGenAI 提示技能将包含在生成的技能集中。 设置此参数还需要 disableImageVerbalization 设置为 false. 物体 apiKeydeploymentId 可编辑
embeddingModel 一个文本嵌入模型,用于在索引编制和查询时向量文本和图像内容。 支持的模型是 text-embedding-ada-002text-embedding-3-small以及 text-embedding-3-largeAzure OpenAI 嵌入技能将包含在生成的技能集中,Azure OpenAI 向量器将包含在生成的索引中。 物体 apiKeydeploymentId 可编辑
contentExtractionMode 控制如何从文件中提取内容。 默认值为 minimal:对文本和图像使用标准内容提取。 将 standard 设置为使用 Azure 内容理解技能进行高级文档破解和分块,该技能将包含在生成的技能集中。 对于standard,仅aiServicesassetStore参数是可指定的。 String
aiServices 用于在 Foundry Tools 中访问 Azure 内容理解的 Azure Foundry 资源。 设置此参数需要 contentExtractionMode 设置为 standard. 物体 apiKey 可编辑 是的
assetStore 用于存储提取映像的 Blob 容器。 设置此参数需要 contentExtractionMode 设置为 standard. 物体
ingestionSchedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 物体 是的
ingestionPermissionOptions 从所选知识源中摄取文档级权限:ADLS Gen2。 如果指定 userIdsgroupIdsrbacScope生成的 ADLS Gen2 索引器 将包含引入的权限。 Array

检查引入状态

使用 知识源 - 状态 (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. 检查可搜索内容的索引。 使用搜索资源管理器运行查询。
  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.azure.cn/$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}}