你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

创建索引的 OneLake 知识源

注意

此智能检索功能在 2026-04-01 REST API 版本中通过编程接口普遍可用。 Azure门户和 Microsoft Foundry 门户继续提供对所有代理检索功能的仅限预览的访问权限。 有关迁移指南,请参阅 将代理检索代码迁移到最新版本

使用 索引的 OneLake 知识源为 OneLake 文件编制索引,并在代理检索流水线中进行查询。 知识源 是独立创建的,在 知识库中引用,并在代理或聊天机器人在查询时调用 检索操作 时用作基础数据。

创建索引的 OneLake 知识源时,可以指定外部数据源、模型和属性,以自动生成以下Azure AI 搜索对象:

  • 表示湖仓的一个数据源。
  • 一个技能集能够对来自数据湖仓的多模态内容进行分块,并可选择性地进行向量化处理。
  • 存储扩充内容并满足代理检索条件的索引。
  • 使用前面的对象驱动索引和扩充管道的索引器。

生成的索引 器符合 OneLake 索引器,其先决条件、支持的任务、支持的文档格式、支持的快捷方式和限制也适用于 OneLake 知识源。 有关详细信息,请参阅 OneLake 索引器文档

使用支持

Azure 门户 Microsoft Foundry 门户 .NET SDK Python SDK Java SDK JavaScript SDK REST API
✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

先决条件

  • 必需Azure.Search.Documents 包:

    • 对于 2025-11-01-preview 功能,最新的预览包:dotnet add package Azure.Search.Documents --prerelease

    • 关于2026-04-01的功能,最新的稳定包是:dotnet add package Azure.Search.Documents

  • 所需的 azure-search-documents 包:

    • 对于 2025-11-01-preview 功能,最新的预览包: pip install azure-search-documents --pre

    • 对于 2026-04-01 的特性,最新的稳定包:pip install azure-search-documents

检查现有知识源

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

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

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

Reference: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})")

Reference:SearchIndexClient

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

参考:知识源 - 列表

还可以按名称返回单个知识源以查看其 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));

Reference: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))

Reference:SearchIndexClient

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

参考:知识源 - 获取

以下 JSON 是已编入索引的 OneLake 知识源的示例响应。

{
  "name": "my-onelake-ks",
  "kind": "indexedOneLake",
  "description": "A sample indexed OneLake knowledge source.",
  "encryptionKey": null,
  "indexedOneLakeParameters": {
    "fabricWorkspaceId": "<REDACTED>",
    "lakehouseId": "<REDACTED>",
    "targetPath": null,
    "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"
        }
      },
      "chatCompletionModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<REDACTED>",
          "deploymentId": "gpt-5-mini",
          "apiKey": "<REDACTED>",
          "modelName": "gpt-5-mini"
        }
      },
      "ingestionSchedule": null,
      "aiServices": {
        "uri": "<REDACTED>",
        "apiKey": "<REDACTED>"
      }
    },
    "createdResources": {
    "datasource": "my-onelake-ks-datasource",
    "indexer": "my-onelake-ks-indexer",
    "skillset": "my-onelake-ks-skillset",
    "index": "my-onelake-ks-index"
    }
  }
}

注意

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

创建知识源

运行以下代码以创建索引的 OneLake 知识源。

// Create an indexed OneLake knowledge source
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.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
    },
    IngestionPermissionOptions = new List<KnowledgeSourceIngestionPermissionOption>
    {
        KnowledgeSourceIngestionPermissionOption.UserIds,
        KnowledgeSourceIngestionPermissionOption.GroupIds
    }
};

var oneLakeParams = new IndexedOneLakeKnowledgeSourceParameters(
    fabricWorkspaceId: fabricWorkspaceId,
    lakehouseId: lakehouseId)
{
    IngestionParameters = ingestionParams
};

var knowledgeSource = new IndexedOneLakeKnowledgeSource(
    name: "my-onelake-ks",
    indexedOneLakeParameters: oneLakeParams)
{
    Description = "This knowledge source pulls content from a lakehouse."
};

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

Reference:SearchIndexClientIndexedOneLakeKnowledgeSource

# Create an indexed OneLake knowledge source
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import IndexedOneLakeKnowledgeSource, IndexedOneLakeKnowledgeSourceParameters, KnowledgeBaseAzureOpenAIModel, AzureOpenAIVectorizerParameters, KnowledgeSourceAzureOpenAIVectorizer, KnowledgeSourceContentExtractionMode, KnowledgeSourceIngestionParameters

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

knowledge_source = IndexedOneLakeKnowledgeSource(
    name = "my-onelake-ks",
    description= "This knowledge source pulls content from a lakehouse.",
    encryption_key = None,
    indexed_one_lake_parameters = IndexedOneLakeKnowledgeSourceParameters(
        fabric_workspace_id = "fabric_workspace_id",
        lakehouse_id = "lakehouse_id",
        target_path = None,
        ingestion_parameters = KnowledgeSourceIngestionParameters(
            identity = None,
            disable_image_verbalization = False,
            chat_completion_model = KnowledgeBaseAzureOpenAIModel(
                azure_open_ai_parameters = AzureOpenAIVectorizerParameters(
                    resource_url = "aoai_endpoint",
                    deployment_name = "aoai_gpt_deployment",
                    model_name = "aoai_gpt_model",
                    api_key = "aoai_api_key"
                )
            ),
            embedding_model = KnowledgeSourceAzureOpenAIVectorizer(
                azure_open_ai_parameters=AzureOpenAIVectorizerParameters(
                    resource_url = "aoai_endpoint",
                    deployment_name = "aoai_embedding_deployment",
                    model_name = "aoai_embedding_model",
                    api_key = "aoai_api_key"
                )
            ),
            content_extraction_mode = KnowledgeSourceContentExtractionMode.MINIMAL,
            ingestion_schedule = None,
            ingestion_permission_options = ["user_ids", "group_ids"]
        )
    )
)

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

Reference:SearchIndexClient

### Create an indexed OneLake knowledge source
PUT {{search-url}}/knowledgesources/my-onelake-ks?api-version=2025-11-01-preview
api-key: {{api-key}}
Content-Type: application/json

{
    "name": "my-onelake-ks",
    "kind": "indexedOneLake",
    "description": "This knowledge source pulls content from a lakehouse.",
    "indexedOneLakeParameters": {
      "fabricWorkspaceId": "<YOUR FABRIC WORKSPACE GUID>",
      "lakehouseId": "<YOUR LAKEHOUSE GUID>",
      "targetPath": null,
      "ingestionParameters": {
        "identity": null,
        "disableImageVerbalization": null,
        "chatCompletionModel": {
            "kind": "azureOpenAI",
            "azureOpenAIParameters": {
                "resourceUri": "{{aoai-endpoint}}",
                "deploymentId": "{{aoai-gpt-deployment}}",
                "modelName": "{{aoai-gpt-model}}",
                "apiKey": "{{aoai-key}}"
            }
        },
        "embeddingModel": {
            "kind": "azureOpenAI",
            "azureOpenAIParameters": {
                "resourceUri": "{{aoai-endpoint}}",
                "deploymentId": "{{aoai-embedding-deployment}}",
                "modelName": "{{aoai-embedding-model}}",
                "apiKey": "{{aoai-key}}"
            }
        },
        "contentExtractionMode": "minimal",
        "ingestionSchedule": null,
        "ingestionPermissionOptions": ["userIds", "groupIds"]
    }
  }
}

参考:知识源 - 创建或更新

注意

要使用 ingestionPermissionOptions 实施文档级权限强制,需 2025-11-01-preview API 版本。 2026-04-01 不支持此功能。

特定于源的属性

对于 2025-11-01-preview 和 2026-04-01 API 版本,可以传递以下属性来创建索引的 OneLake 知识源。

名字 描述 类型 可编辑的 必填
Name 知识源的名称,该名称在知识源集合中必须唯一,并遵循Azure AI 搜索中对象的命名准则 字符串 是的
Description 知识源的说明。 字符串 是的
EncryptionKey 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 对象 是的
IndexedOneLakeKnowledgeSourceParameters 特定于 OneLake 知识源的参数: FabricWorkspaceIdLakehouseIdTargetPath 对象 是的
FabricWorkspaceId 包含 Lakehouse 的工作区的 GUID。 字符串 是的
LakehouseId 湖屋的 GUID。 字符串 是的
TargetPath Lakehouse 中的文件夹或快捷方式。 未指定时,将对整个湖仓进行索引。 字符串
名字 描述 类型 可编辑的 必填
name 知识源的名称,该名称在知识源集合中必须唯一,并遵循Azure AI 搜索中对象的命名准则 字符串 是的
description 知识源的说明。 字符串 是的
encryption_key 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 对象 是的
indexed_one_lake_parameters 特定于 OneLake 知识源的参数: fabric_workspace_idlakehouse_idtarget_path 对象 是的
fabric_workspace_id 包含 Lakehouse 的工作区的 GUID。 字符串 是的
lakehouse_id 湖屋的 GUID。 字符串 是的
target_path Lakehouse 中的文件夹或快捷方式。 未指定时,将编制整个湖屋的索引。 字符串
名字 描述 类型 可编辑的 必填
name 知识源的名称,该名称在知识源集合中必须唯一,并遵循Azure AI 搜索中对象的命名准则 字符串 是的
kind 知识源的类型为indexedOneLake,在本例中。 字符串 是的
description 知识源的说明。 字符串 是的
encryptionKey 客户 管理的密钥 ,用于加密知识源和生成的对象中的敏感信息。 对象 是的
indexedOneLakeParameters 特定于 OneLake 知识源的参数: fabricWorkspaceIdlakehouseIdtargetPath 对象 是的
fabricWorkspaceId 包含 Lakehouse 的工作区的 GUID。 字符串 是的
lakehouseId 湖屋的 GUID。 字符串 是的
targetPath Lakehouse 中的文件夹或快捷方式。 未指定时,将编制整个湖屋的索引。 字符串

引入参数属性

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

名字 描述 类型 可编辑的 必填
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. 对象 ApiKeyDeploymentName 可编辑
EmbeddingModel 一个文本嵌入模型,用于在索引编制和查询时向量文本和图像内容。 支持的模型是 text-embedding-ada-002text-embedding-3-small以及 text-embedding-3-largeAzure OpenAI 嵌入技能包含在生成的技能集中,Azure OpenAI 向量器包含在生成的索引中。 对象 ApiKeyDeploymentName 可编辑
ContentExtractionMode 控制如何从文件中提取内容。 默认值为 minimal:对文本和图像使用标准内容提取。 设置为 standard,以便使用生成的技能集中的 Azure 内容理解技能 进行高级文档破解和分块。 仅针对standard,可以指定AiServices参数。 字符串
AiServices Microsoft Foundry 资源,用于在 Foundry 工具中访问 Azure 内容理解。 设置此参数需要 ContentExtractionMode 设置为 standard. 对象 ApiKey 可编辑
IngestionSchedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 对象 是的
IngestionPermissionOptions 用于与内容一起导入的文档级权限。 指定UserIdsGroupIdsRbacScope存储索引中的权限元数据。 有关特定于源的指南,请参阅 从 Blob 存储引入 RBAC 权限从 ADLS Gen2 引入 ACL 的。 若要在查询时强制实施这些权限,请参阅 在查询时强制实施权限 阵 列
名字 描述 类型 可编辑的 必填
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_services参数。 字符串
ai_services Microsoft Foundry 资源,用于在 Foundry 工具中访问 Azure 内容理解。 设置此参数需要 content_extraction_mode 设置为 standard. 对象 api_key 可编辑
ingestion_schedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 对象 是的
ingestion_permission_options 用于与内容一起导入的文档级权限。 指定user_idsgroup_idsrbac_scope存储索引中的权限元数据。 有关特定于源的指南,请参阅 从 Blob 存储引入 RBAC 权限从 ADLS Gen2 引入 ACL 的。 若要在查询时强制实施这些权限,请参阅 在查询时强制实施权限 阵 列
名字 描述 类型 可编辑的 必填
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,可以指定aiServices参数。 字符串
aiServices Microsoft Foundry 资源,用于在 Foundry 工具中访问 Azure 内容理解。 设置此参数需要 contentExtractionMode 设置为 standard. 对象 apiKey 可编辑
ingestionSchedule 将计划信息添加到生成的索引器。 还可以稍后 添加计划 以自动执行数据刷新。 对象 是的
ingestionPermissionOptions 用于与内容一起导入的文档级权限。 指定userIdsgroupIdsrbacScope存储索引中的权限元数据。 有关特定于源的指南,请参阅 从 Blob 存储引入 RBAC 权限从 ADLS Gen2 引入 ACL 的。 若要在查询时强制实施这些权限,请参阅 在查询时强制实施权限 阵 列

检查摄取状态

运行以下代码来监视引入进度和运行状况,包括知识源类型以及生成索引器管道并填充搜索索引的知识源的详细索引错误。

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

Reference: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))

Reference:SearchIndexClient

### Check knowledge source ingestion status
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}/status?api-version={{api-version}}
api-key: {{api-key}}
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
  }
}

注意

从 2026-04-01 API 版本开始,文档级错误详细信息的 kind 属性和 currentSynchronizationState.errors[] 数组即可使用。 对于早期 API 版本,不会返回这些字段。 该 lastSynchronizationState.status 字段也是 2026-04-01 中的新增字段。

查看创建的对象

创建索引的 OneLake 知识源时,搜索服务还会创建索引器、索引、技能集和数据源。 不建议编辑这些对象,因为引入错误或不兼容可能会中断管道。

创建知识源后,响应会列出已创建的对象。 这些对象是根据固定模板创建的,其名称基于知识源的名称。 无法更改对象名称。

建议使用 Azure 门户来验证输出创建。 工作流为:

  1. 检查索引器是否有成功或失败的消息。 这里会显示连接错误或配额错误。
  2. 检查可搜索内容的索引。 使用搜索资源管理器运行查询。
  3. 检查技能集,了解如何对内容进行分块和选择性地矢量化。
  4. 检查数据源以获取连接详细信息。 本示例使用 API 密钥来简单起见,但可以使用Microsoft Entra ID进行身份验证和基于角色的访问控制进行授权。

分配给知识库

如果对知识源感到满意,请继续执行下一步:在 知识库中指定知识库中的知识源。

对于任何指定为 OneLake 知识源且已编入索引的知识库,请确保将 includeReferenceSourceData 设置为 true。 此步骤是将源文档 URL 拉取到引文中所必需的。

配置知识库后,使用 检索操作 查询知识源。

提示

若要强制实施文档级权限,请在创建此知识源时设置 ingestionPermissionOptions ,然后在检索请求中包含用户的访问令牌。 有关详细信息,请参阅 在查询时强制实施权限

删除知识源

在删除知识库之前,必须删除引用它的任何知识库或更新知识库定义以删除引用。 对于生成索引和索引器管道的知识源,也会删除所有 生成的对象 。 但是,如果使用现有索引创建知识源,则不会删除索引。

如果尝试删除正在使用的知识源,该操作将失败并返回受影响的知识库列表。

删除知识源:

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

    Reference:SearchIndexClient

    示例响应可能如下所示:

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

    Reference: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.");
    

    Reference:SearchIndexClient

  4. 删除知识源。

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

    Reference: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}")
    

    Reference: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)
    

    Reference: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.")
    

    Reference: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.")
    

    Reference:SearchIndexClient

  1. 获取搜索服务上所有知识库的列表。

    ### Get knowledge bases
    GET {{search-url}}/knowledgebases?api-version={{api-version}}&$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-url}}/knowledgebases/{{knowledge-base-name}}?api-version={{api-version}}
    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-url}}/knowledgebases/{{knowledge-base-name}}?api-version={{api-version}}
    api-key: {{api-key}}
    

    参考:知识库 - 删除

  4. 删除知识源。

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

    参考:知识源 - 删除