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

创建 Fabric Ontology 知识来源(预览版)

注释

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

Important

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

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

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

本体描述了企业如何定义其数据、实体及其关系,使智能体能够使用业务语言作答,而不是基于原始表和列进行推理。

与索引知识源不同,Fabric Ontology 知识源在检索时直接查询实时数据。 不需要引入管道。 查询需要最终用户访问令牌,检索引擎使用该令牌代表调用方对Microsoft Fabric进行身份验证。

使用支持

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

先决条件

  • 在任意提供代理检索功能的区域中提供的 Azure AI 搜索服务。

  • 具有本体所需租户设置和本体项的 Microsoft Fabric 工作区。

  • 您的搜索服务和工作区必须属于同一个 Microsoft Entra ID 租户。

  • 创建知识源的权限。 使用分配给用户帐户的搜索服务参与者角色(建议)或使用管理员 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

数据管理和合规性

Fabric IQ 在工作区所在区域的 Microsoft Fabric 合规边界内处理请求。 通过 Fabric IQ 路由代理查询时,以下承诺适用。

数据驻留

Fabric IQ 检索并处理Microsoft Fabric工作区所在的区域内的数据。 在查询执行期间,数据不会跨越区域边界。 适用的区域及其符合性范围由工作区位置确定。 有关每个区域满足的支持区域和符合性框架的列表,请参阅 Microsoft Fabric 区域可用性。

注释

如果Azure AI 搜索服务与Fabric工作区位于不同的Azure区域中,则会跨区域返回查询结果。 在连接位于其他区域的 Fabric 工作区之前,请先查看 Microsoft Fabric 区域可用性以及组织的数据驻留要求。

合规性认证

Fabric IQ 继承工作区区域的Microsoft Fabric合规性认证。 有关适用于每个区域的合规性文档、审核报告和框架,请参阅 Microsoft Fabric 区域可用性。

检查现有知识源

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

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

// 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 是 Fabric 本体知识源的响应示例。

{
  "name": "my-fabric-ontology-ks",
  "kind": "fabricOntology",
  "description": "A Fabric Ontology knowledge source.",
  "encryptionKey": null,
  "fabricOntologyParameters": {
    "workspaceId": "00000000-0000-0000-0000-000000000000",
    "ontologyId": "00000000-0000-0000-0000-000000000001"
  }
}

创建知识源

运行以下代码以创建Fabric Ontology 知识源。

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

Uri searchEndpoint = new Uri("<search-endpoint>");
DefaultAzureCredential credential = new DefaultAzureCredential();
var indexClient = new SearchIndexClient(searchEndpoint, credential);

var fabricOntology = new FabricOntologyKnowledgeSource(
    "<knowledge-source-name>",
    new FabricOntologyKnowledgeSourceParameters("<fabric-workspace-id>", "<fabric-ontology-id>"))
{
    Description = "A Fabric Ontology knowledge source."
};

await indexClient.CreateOrUpdateKnowledgeSourceAsync(fabricOntology);

Reference:SearchIndexClient

from azure.identity import DefaultAzureCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    FabricOntologyKnowledgeSource,
    FabricOntologyKnowledgeSourceParameters,
)

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

knowledge_source = FabricOntologyKnowledgeSource(
    name="<knowledge-source-name>",
    description="A Fabric Ontology knowledge source.",
    fabric_ontology_parameters=FabricOntologyKnowledgeSourceParameters(
        workspace_id="<fabric-workspace-id>",
        ontology_id="<fabric-ontology-id>"
    )
)

index_client.create_or_update_knowledge_source(knowledge_source)

Reference:SearchIndexClient

### Create a Fabric Ontology knowledge source
PUT {{search-endpoint}}/knowledgesources/my-fabric-ontology-ks?api-version=2026-08-01-preview
Authorization: Bearer {{search-access-token}}
Content-Type: application/json

{
  "name": "my-fabric-ontology-ks",
  "kind": "fabricOntology",
  "description": "A Fabric Ontology knowledge source.",
  "fabricOntologyParameters": {
    "workspaceId": "{fabric-workspace-id}",
    "ontologyId": "{fabric-ontology-id}"
  }
}

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

分配给知识库

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

注释

Fabric本体知识源不支持minimal检索推理功能。 请改用 low 或 medium。

查询知识库

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

在查询时强制实施权限

Fabric Ontology 知识来源使用代理 (OBO) 令牌流。 在检索请求的 x-ms-query-source-authorization 标头中传递最终用户访问令牌。 令牌的作用域必须限定为 Azure AI 搜索 受众(https://search.azure.com/.default)。 检索引擎将此令牌交换为 Microsoft Fabric 范围的令牌,并使用它代表最终用户查询本体项。

检索请求中也需要标准 Azure AI 搜索 身份验证。 令牌 x-ms-query-source-authorization 单独传递,不会替换服务身份验证。

有关传递令牌的说明,请参阅查询时强制实施权限(预览版)。

Fabric 本体专用响应字段

Fabric Ontology 知识源会在每个 sourceData 条目的 references 对象中返回结果,并在 activity 数组中返回查询诊断信息。 sourceData 包含:

  • fabricAnswer:本体的自然语言答案。
  • fabricRawData:作为答案依据的结构化数据,以 CSV 格式返回。

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

小窍门

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

{
  "response": [
      // ... Response omitted for brevity
  ],
  "activity": [
    {
      "type": "fabricOntology",
      "id": 1,
      "knowledgeSourceName": "my-fabric-ontology-ks",
      "queryTime": "2026-05-11T20:29:24Z",
      "count": 1,
      "fabricOntologyArguments": {
        "search": "Which airlines operate domestic routes?"
      }
    },
    {
      // ... Additional activity records omitted for brevity
    }
  ],
  "references": [
    {
      "type": "fabricOntology",
      "id": "0",
      "activitySource": 1,
      "sourceData": {
        "fabricAnswer": "There are 3 airlines with domestic routes: Delta, United, and American.",
        "fabricRawData": "Airline,Routes\nDelta,47\nUnited,38\nAmerican,29"
      },
      "rerankerScore": 0,
      "workspaceId": "00000000-0000-0000-0000-000000000000",
      "ontologyId": "00000000-0000-0000-0000-000000000001"
    },
    {
      // ... Additional references omitted for brevity
    }
  ]
}

删除知识源

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

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

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

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

    参考:知识源 - 删除