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

创建 Work IQ 知识源(预览)

注释

Azure AI 搜索可通过Azure门户、REST API 和Azure SDK获取。 它也是 Foundry IQ 的基础;Foundry IQ 是一个托管式知识层,可将企业内容转化为供 Microsoft Foundry 门户中的智能体使用的、可复用且具备权限感知能力的知识库。

Important

标记为“预览”的特性、功能或属性不受服务级别协议 (SLA) 保障,不建议用于生产工作负载,并且在正式发布之前可能会更改或受到限制。 Azure AI 搜索预览条款适用于所有预览功能,无论是独立功能还是正式版功能的一部分。

连接到 Work IQ 时,可能会产生成本,并且数据可能发送到Azure合规性边界之外,并根据适用的服务条款和数据处理策略进行处理。

Work IQ 知识源(预览版)将 Work IQ连接到 Azure AI 搜索 中的代理检索管道。 知识库是在运行时查询知识库时独立创建的、在知识库中引用的,并用作基础数据。

工作 IQ 从Microsoft 365内容中显示组织智能,包括跨Microsoft 365应用的文档、电子邮件、会议和活动。

与索引知识源不同,Work IQ 知识源在检索时直接查询实时数据。 不需要引入管道。 查询需要为Microsoft Entra应用注册颁发的用户访问令牌。 Azure AI 搜索 用该令牌换取一个委派的 Work IQ 令牌,并代表用户调用 Work IQ。

Warning

在此预览版中,Work IQ 知识源可能会使用 Work IQ 中可执行操作的功能,而不仅仅是检索信息。 谨慎使用它,限制对受信任的应用程序和用户的访问权限,并在启用之前查看方案的权限和治理控制。

使用支持

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

先决条件

  • 最新的 Azure.Search.Documents 预览包:dotnet add package Azure.Search.Documents --prerelease

  • 对于无密钥身份验证,请使用 Azure.Identity 软件包:dotnet add package Azure.Identity

  • 最新的 azure-search-documents 预览包:pip install --pre azure-search-documents

  • 对于无密钥身份验证,请使用 azure-identity 软件包:pip install azure-identity

数据管理和合规性

在启用工作 IQ 检索之前,请查看Microsoft Copilot的数据、隐私和安全性。

数据使用和隐私

通过Microsoft Graph访问的提示、响应和数据不用于训练基础语言模型。

访问控制

Work IQ 在每次请求中都会应用 Microsoft 365 权限设置。 检索仅返回已登录用户有权访问的组织数据。

数据驻留和合规性

查看 Microsoft 365 文档,了解适用于贵组织和场景的数据驻留、隐私、安全性和合规性承诺。

设置 Microsoft Entra 身份验证

从 2026-08-01-preview API 版本开始,每个 Work IQ 知识源都使用客户自有的 Microsoft Entra 应用注册用于身份验证。 在查询时,身份验证的工作原理如下:

  1. 客户端应用登录用户,并将用户断言发送到Azure AI 搜索。
  2. 搜索服务托管标识通过联合凭据以客户自有应用的身份进行身份验证。
  3. Azure AI 搜索 使用用户声明换取委托的 Work IQ 令牌,并代表已登录用户调用 Work IQ。

工作 IQ 知识源上未存储任何客户端机密。 配置应用及其权限一次,然后为每个使用该应用的搜索服务标识创建联合凭据。

配置 Work IQ 应用注册

要配置 Azure AI 搜索 用于调用 Work IQ 的客户自有应用,请按以下步骤操作:

  1. 在要管理 Work IQ 同意授权的 Microsoft Entra 租户中注册应用程序。 对于“支持的帐户类型”设置,请选择“仅限此组织目录中的帐户”。

  2. 在应用注册的 “概述 ”页上,复制 应用程序(客户端)ID 和 目录(租户)ID。 您需要应用程序 ID 来配置 Work IQ 身份验证,还需要租户 ID 来登录到包含该应用注册的租户。

  3. 在应用注册的 Expose an API 页面上,access_as_user,其名称必须严格为 。 使用此小写名称;不要替换另一个范围名称。 完整范围为 api://<application-client-id>/access_as_user.

  4. 在应用注册的 API 权限页上,选择 添加权限>。

  5. 搜索 工作 IQ (应用程序 ID fdcc1f02-fc51-4226-8753-f668596af7f7),选择 委派权限>WorkIQAgent.Ask,然后选择“ 添加权限”。

  6. 请让满足先决条件中所列同意角色要求的管理员在同一页面上选择 为[你的租户]授予管理员同意。 此同意允许应用将用户断言交换为委托的 Work IQ 令牌。

配置搜索服务标识

若要配置 Azure AI 搜索 在作为你的 Work IQ 应用进行身份验证时使用的标识:

  1. 在搜索服务上启用系统分配的托管标识。 如果无法使用系统分配的托管标识,请仅配置一个用户分配的托管标识。 不支持具有多个用户分配的标识且没有系统分配的标识的搜索服务。

  2. 在搜索服务的 “标识 ”页上,复制 “对象”(主体)ID。 联合凭据使用此值作为其 subject值。

  3. 转到 Microsoft Entra ID>Overview 并复制租户 ID。 联合凭据在其 issuer URL 中使用此值。

创建联合凭据

若要为搜索服务标识创建联合凭据,

  1. 创建名为 的文件 credential.json。 将 <search-service-tenant-id>、<search-service-principal-id> 和 <search-service-name> 替换为你的搜索服务对应的值。

    {
      "name": "<search-service-name>-identity",
      "issuer": "https://login.microsoftonline.com/<search-service-tenant-id>/v2.0",
      "subject": "<search-service-principal-id>",
      "audiences": ["api://AzureADTokenExchange"]
    }
    

    凭据名称在应用注册上必须是唯一的。 该值 subject 必须与托管标识主体 ID 完全匹配。 不匹配会在查询时出现,而不是在创建知识源时出现。

  2. 使用包含该应用注册的租户登录到Azure CLI。

    az login --tenant <app-tenant-id> --allow-no-subscriptions
    
  3. 创建联合凭据。

    az ad app federated-credential create --id <application-client-id> --parameters credential.json --query id --output tsv
    
  4. 复制命令输出。 创建工作 IQ 知识源时,请使用此值 federatedCredentialId 。

每个联合凭据仅信任一个托管标识主体 ID。 如果另一个搜索服务身份使用该应用注册,请使用唯一的凭据名称以及该身份的租户 ID 和主体 ID 重复此过程。 为每个 Work IQ 知识源使用相应的凭据 ID。

配置客户端应用

要配置用于让用户登录并发送检索请求的应用:

  1. 在客户端应用的 API 权限页面上,选择 添加权限>。

  2. 将之前复制 的应用程序(客户端)ID 粘贴到搜索框中,然后选择工作 IQ 应用注册。

  3. 选择access_as_user委派的权限>,然后选择“添加权限”。

  4. 完成租户的用户同意策略要求的任何同意操作。 如果需要管理员同意,请让管理员 为 [租户]选择“授予管理员许可”。

客户端应用现可为 Work IQ 应用注册请求用户断言。 该 access_as_user 权限不授予客户端应用直接访问 Work IQ 的权限。

身份验证值

创建工作 IQ 知识源时,请使用Microsoft Entra应用设置中的以下entraAppAuthentication值。 你提供的每个值都必须为 GUID。

财产 必需 Value
applicationId 是的 你的 Work IQ 应用注册的应用程序(客户端)ID。
federatedCredentialId 是的 在应用中创建的联合凭据的对象 ID。 它不是凭据名称,不是搜索服务主体 ID。
tenantId 否 应用注册的目录(租户)ID。 当应用注册和搜索服务位于同一租户中时,省略此属性。 如果它们位于不同的租户中,则需要此属性。

检查现有知识源

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

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

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

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}}
Authorization: Bearer {{token}}

参考:知识源 - 获取

以下 JSON 是工作 IQ 知识源的示例响应。

{
  "name": "my-workiq-ks",
  "kind": "workIQ",
  "description": "A sample Work IQ knowledge source.",
  "workIQParameters": {
    "entraAppAuthentication": {
      "applicationId": "11111111-1111-1111-1111-111111111111",
      "federatedCredentialId": "22222222-2222-2222-2222-222222222222",
      "tenantId": null
    }
  },
  "encryptionKey": null
}

创建知识源

运行以下代码以创建工作 IQ 知识源。

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

Uri searchEndpoint =
    new("https://<search-service-name>.search.windows.net");
var credential = new DefaultAzureCredential();
var indexClient = new SearchIndexClient(searchEndpoint, credential);

var entraAuthentication = new EntraAppAuthentication(
    Guid.Parse("<application-client-id>"),
    Guid.Parse("<federated-credential-id>"));
var knowledgeSource = new WorkIQKnowledgeSource(
    "my-workiq-ks",
    new WorkIQKnowledgeSourceParameters(entraAuthentication))
{
    Description = "A sample Work IQ knowledge source."
};

KnowledgeSource createdSource =
    await indexClient.CreateOrUpdateKnowledgeSourceAsync(knowledgeSource);
Console.WriteLine($"Created knowledge source '{createdSource.Name}'.");

Reference:SearchIndexClient、 WorkIQKnowledgeSource

from azure.identity import DefaultAzureCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    EntraAppAuthentication,
    WorkIQKnowledgeSource,
    WorkIQKnowledgeSourceParameters,
)

endpoint = "https://<search-service-name>.search.windows.net"
credential = DefaultAzureCredential()

knowledge_source = WorkIQKnowledgeSource(
    name="my-workiq-ks",
    description="A sample Work IQ knowledge source.",
    work_iq_parameters=WorkIQKnowledgeSourceParameters(
        entra_app_authentication=EntraAppAuthentication(
            application_id="<application-client-id>",
            federated_credential_id="<federated-credential-id>",
        )
    ),
)

with SearchIndexClient(endpoint, credential) as index_client:
    created_source = index_client.create_or_update_knowledge_source(
        knowledge_source
    )
print(f"Created knowledge source '{created_source.name}'.")

Reference:SearchIndexClient、 WorkIQKnowledgeSource

@search-endpoint = <search-endpoint> // Example: https://my-service.search.windows.net
@search-access-token = <search-access-token> // Run: az account get-access-token --scope https://search.azure.com/.default --query accessToken -o tsv

### Create a Work IQ knowledge source
PUT {{search-endpoint}}/knowledgesources/my-workiq-ks?api-version=2026-08-01-preview
Authorization: Bearer {{search-access-token}}
Content-Type: application/json
Prefer: return=representation

{
  "name": "my-workiq-ks",
  "kind": "workIQ",
  "description": "A sample Work IQ knowledge source.",
  "workIQParameters": {
    "entraAppAuthentication": {
      "applicationId": "<application-client-id>",
      "federatedCredentialId": "<federated-credential-id>"
    }
  }
}

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

分配给知识库

如果对知识源感到满意, 请将其添加到知识库。

查询知识库

配置知识库后, 调用检索操作或 MCP 终结点 以查询工作 IQ 内容。 此知识源具有唯一的查询时间权限强制和响应特征。

Important

工作 IQ 可能需要 40-60 秒或更多时间才能做出响应。 若要避免超时错误,请在检索请求maxRuntimeInSeconds上设置为120或更高。

在查询时强制实施权限

从 2026-08-01-preview API 版本开始,Work IQ 知识源通过您客户自有的 Microsoft Entra 应用注册使用代表用户(OBO)令牌流。 除了对发往 Azure AI 搜索 的检索请求进行身份验证外,客户端还必须为已登录用户提供面向应用受众的用户断言。

客户端应用必须登录用户并获取用户断言。 获取断言的方式取决于应用的平台和语言。 使用 Microsoft 身份验证库 (MSAL) 和带有代码交换证明密钥的授权代码流 (PKCE) 来请求精确范围 api://<application-client-id>/access_as_user。

在发送用户断言之前,请确认:

  • aud 用于标识您的 Work IQ 应用注册信息。
  • scp 包含 access_as_user。
  • oid 并 tid 标识已登录的用户和应用租户。

在同一检索请求中发送这两个凭据,如以下示例所示。 使用Azure AI 搜索令牌或 API 密钥进行身份验证。 在 x-ms-query-work-iq-source-authorization 标头中传递原始用户断言,而不是在 x-ms-query-source-authorization 中。

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

Uri searchEndpoint =
    new("https://<search-service-name>.search.windows.net");
string userAssertion = "<user-assertion>";
var credential = new DefaultAzureCredential();
var options = new SearchClientOptions();
options.Retry.NetworkTimeout = TimeSpan.FromSeconds(130);
var retrievalClient = new KnowledgeBaseRetrievalClient(
    searchEndpoint,
    "my-kb",
    credential,
    options);

var request = new KnowledgeBaseRetrievalRequest
{
    IncludeActivity = true,
    MaxRuntimeInSeconds = 120
};
request.Intents.Add(
    new KnowledgeRetrievalSemanticIntent("Find my project status."));
request.KnowledgeSourceParams.Add(
    new WorkIQKnowledgeSourceParams("my-workiq-ks")
    {
        IncludeReferences = true,
        IncludeReferenceSourceData = true
    });

var response = await retrievalClient.RetrieveAsync(
    request,
    querySourceAuthorization: null,
    queryWorkIQSourceAuthorization: userAssertion);
Console.WriteLine(response.Value);

参考:KnowledgeBaseRetrievalClient、 KnowledgeBaseRetrievalRequest

from azure.identity import DefaultAzureCredential
from azure.search.documents.knowledgebases import (
    KnowledgeBaseRetrievalClient,
)
from azure.search.documents.knowledgebases.models import (
    KnowledgeBaseRetrievalRequest,
    KnowledgeRetrievalSemanticIntent,
    WorkIQKnowledgeSourceParams,
)

endpoint = "https://<search-service-name>.search.windows.net"
user_assertion = "<user-assertion>"
credential = DefaultAzureCredential()

request = KnowledgeBaseRetrievalRequest(
    intents=[
        KnowledgeRetrievalSemanticIntent(
            search="Find my project status."
        )
    ],
    knowledge_source_params=[
        WorkIQKnowledgeSourceParams(
            knowledge_source_name="my-workiq-ks",
            include_references=True,
            include_reference_source_data=True,
        )
    ],
    include_activity=True,
    max_runtime_in_seconds=120,
)

with KnowledgeBaseRetrievalClient(
    endpoint,
    credential,
    knowledge_base_name="my-kb",
) as retrieval_client:
    response = retrieval_client.retrieve(
        request,
        query_work_iq_source_authorization=user_assertion,
        timeout=130,
    )

print(response)

参考:KnowledgeBaseRetrievalClient、 KnowledgeBaseRetrievalRequest

@search-endpoint = <search-endpoint>
@search-access-token = <search-access-token>
@user-assertion = <user-assertion>

### Query a knowledge base with a Work IQ knowledge source
POST {{search-endpoint}}/knowledgebases/my-kb/retrieve?api-version=2026-08-01-preview
Authorization: Bearer {{search-access-token}}
x-ms-query-work-iq-source-authorization: {{user-assertion}}
Content-Type: application/json

{
  "messages": [{
    "role": "user",
    "content": [{
      "type": "text",
      "text": "Find my project status."
    }]
  }],
  "knowledgeSourceParams": [{
    "knowledgeSourceName": "my-workiq-ks",
    "kind": "workIQ",
    "includeReferences": true,
    "includeReferenceSourceData": true
  }],
  "includeActivity": true,
  "maxRuntimeInSeconds": 120
}

参考:知识检索 - 检索

成功的请求返回 200 OK。 确认 activity 包含一个条目,其 type 为 workIQ,且其 knowledgeSourceName 与您的 Work IQ 知识源匹配。 同时确认 references 中包含 workIQ 条目。

下表列出了常见的配置失败。

地位 原因
400 工作 IQ 授权标头缺失或格式不正确、缺少所需的用户声明,或者搜索服务没有受支持的托管标识配置。
206 或 502 Work IQ 源失败,原因可能是令牌交换、用户同意、委派权限、联合凭据、下游授权或 Work IQ 请求失败或超时。请检查源活动中的错误。 响应 206 意味着另一个源成功。 响应 502 意味着每个选定的源都失败或所需的源失败。

Work IQ 专用响应字段

Work IQ 知识源在 references 数组中返回结果,并在 activity 数组中返回查询诊断信息。 每个引用项都包含:

  • sourceData.parts[].text:来自 Work IQ 的有依据的文本片段。
  • sourceData.parts[].data:Work IQ 引用数据。 引文部件具有媒体类型 application/vnd.ms-workiq-reference。

以下示例显示了一个检索响应,其中包含 Work IQ 知识源引用及与之对应的活动记录。 有关解释检索响应的更广泛指南,请参阅 “查看响应”。

小窍门

若要接收用作引用的sourceData,请在检索请求中的includeReferenceSourceData内的知识源条目上,将true设置为knowledgeSourceParams。

{
  "response": [],
  "activity": [
    {
      "type": "workIQ",
      "id": 0,
      "knowledgeSourceName": "my-workiq-ks",
      "queryTime": "2026-08-01T19:25:23.683Z",
      "count": 1,
      "elapsedMs": 1137,
      "workIQArguments": {
        "search": "my query"
      }
    }
  ],
  "references": [
    {
      "type": "workIQ",
      "id": "83dd7d40",
      "activitySource": 0,
      "rerankerScore": 3.5,
      "sourceData": {
        "parts": [
          {
            "text": "Have your VPN username and password ready."
          },
          {
            "data": {
              "1-abc123": {
                "targetLink": "https://contoso.sharepoint.com/doc.docx",
                "isCitedInResponse": true,
                "isSourceFiltered": false
              }
            },
            "mediaType": "application/vnd.ms-workiq-reference"
          }
        ]
      }
    }
  ]
}

删除知识源

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

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

要删除知识源,请执行以下步骤:

  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

    示例响应可能如下所示:

     {
         "@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);
    

    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
    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}}
    

    参考:知识源 - 删除