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

创建已编制索引的 Azure SQL 知识源

注释

Foundry IQ (Azure AI 搜索) 提供直接索引和查询 API 以及用于托管检索的高级知识库和知识库 API。 使用 Azure 门户、REST API 或Azure SDK配置这些功能,或将代理连接到 Microsoft Foundry 门户中的知识库。

已编制索引的 Azure SQL 知识源会将 Azure SQL 数据库 或 Azure SQL 托管实例 中的行引入 Foundry IQ (Azure AI 搜索) 中的智能体检索管道。 此功能已通过 REST API 2026-10-01正式发布。 知识源是独立创建的,在知识库中引用,并在知识库于运行时被查询时用作基础数据。

与基于文件的知识源(如 Azure Blob 存储 和 OneLake)不同,每个 SQL 行都被视为一个逻辑文档。 通过显式列映射(而不是使用固定文档架构)驱动索引架构。

创建已编制索引的 Azure SQL 知识源时,可以通过指定 SQL 数据源、可选的列映射以及可选的模型,自动生成以下 Foundry IQ 对象:

  • 表示 SQL 表或视图的数据源。
  • 一个索引,其字段根据您的列映射生成。
  • 生成嵌入向量的技能集。 仅当指定 embeddingColumns时,服务才会创建技能集。
  • 使用前述对象驱动数据引入管道的索引器。

生成的索引器符合 Azure SQL 索引器,其先决条件、更改检测策略和限制也适用于索引Azure SQL知识源。 有关详细信息,请参阅 Azure SQL 索引器文档。

使用支持

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

限制和注意事项

  • 知识源只能从一个表或一个视图中引入数据。
  • 源表或视图必须具有单值主键。 不支持复合键。
  • 主键是自动发现的,无法重写。
  • contentExtractionMode 仅支持 "minimal"。
  • 不支持图像提取和图像语言化。
  • 不支持实时同步。 生成的索引器基于计划。
  • 不支持实时 SQL 检索。 该知识来源已建立索引,而非远程源。

准备已生成的索引器

索引Azure SQL知识源会自动创建索引器来驱动引入。 在创建知识源之前,请查看以下详细信息。

变化检测

生成的索引器使用标准 Azure SQL 索引器更改检测:

身份验证

生成的索引器支持两种身份验证选项:

  • SQL 身份验证:在连接字符串中提供用户名和密码。

  • 托管标识身份验证:使用系统分配的或用户分配的托管标识,该标识在 SQL 资源上具有Azure RBAC 和数据库级角色。

有关连接字符串格式、角色要求和设置步骤,请参阅 Azure SQL 索引器先决条件 和 通过托管标识进行连接。

检查现有知识源

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

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

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

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

参考: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));

参考: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))

参考:SearchIndexClient

### Get a knowledge source definition
GET {{search-url}}/knowledgesources('{{knowledge-source-name}}')?api-version={{api-version}}
Authorization: Bearer {{token}}

参考:知识源 - 获取

以下 JSON 是索引Azure SQL知识源的示例响应。

{
  "name": "indexedsqlks",
  "kind": "indexedSql",
  "description": "Sample indexed Azure SQL knowledge source.",
  "encryptionKey": null,
  "indexedSqlParameters": {
    "connectionString": "<sql-connection-string>",
    "tableOrView": "dbo.tbl_hotels",
    "contentColumns": [
      { "name": "hotelName", "sourceField": "HotelName", "searchFieldType": "Edm.String" },
      { "name": "description", "sourceField": "Description", "searchFieldType": "Edm.String" }
    ],
    "embeddingColumns": [
      { "name": "descriptionVector", "sourceField": "Description" }
    ],
    "ingestionParameters": {
      "contentExtractionMode": "minimal",
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "<aoai-endpoint>",
          "deploymentId": "text-embedding-3-large",
          "modelName": "text-embedding-3-large"
        }
      }
    },
    "createdResources": {
      "datasource": "indexedsqlks-datasource",
      "indexer": "indexedsqlks-indexer",
      "skillset": "indexedsqlks-skillset",
      "index": "indexedsqlks-index"
    }
  }
}

创建知识源

通过使用 REST API2026-11-01-preview,嵌入和聊天引入模型支持Azure API 管理 (APIM) 高级 v2 终结点。 内容理解提取不支持 APIM 终结点。

运行以下代码以创建索引Azure SQL知识源。

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

var indexClient = new SearchIndexClient(new Uri(searchEndpoint), new DefaultAzureCredential());

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

var ingestionParams = new KnowledgeSourceIngestionParameters
{
    NetworkAccessMode = KnowledgeSourceNetworkAccessMode.Public,
    ContentExtractionMode = "minimal",
    EmbeddingModel = new KnowledgeSourceAzureOpenAIVectorizer
    {
        AzureOpenAIParameters = embeddingParams
    }
};

var sqlParams = new IndexedSqlKnowledgeSourceParameters(
    connectionString: sqlConnectionString,
    tableOrView: "dbo.tbl_hotels")
{
    ContentColumns =
    {
        new ContentColumnMapping("hotelName", "HotelName", "Edm.String"),
        new ContentColumnMapping("description", "Description", "Edm.String")
    },
    EmbeddingColumns =
    {
        new EmbeddingColumnMapping("descriptionVector", "Description")
    },
    IngestionParameters = ingestionParams
};

var knowledgeSource = new IndexedSqlKnowledgeSource(
    name: "indexedsqlks",
    indexedSqlParameters: sqlParams)
{
    Description = "Indexed Azure SQL knowledge source."
};

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

Reference:SearchIndexClient, IndexedSqlKnowledgeSource

from azure.identity import DefaultAzureCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
    AzureOpenAIVectorizerParameters,
    ContentColumnMapping,
    EmbeddingColumnMapping,
    IndexedSqlKnowledgeSource,
    IndexedSqlKnowledgeSourceParameters,
)
from azure.search.documents.knowledgebases.models import (
    KnowledgeSourceAzureOpenAIVectorizer,
    KnowledgeSourceIngestionParameters,
    KnowledgeSourceNetworkAccessMode,
)

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

embedding_params = AzureOpenAIVectorizerParameters(
    resource_url="<aoai-endpoint>",
    deployment_name="<aoai-embedding-deployment>",
    model_name="<aoai-embedding-model>",
)

ingestion_params = KnowledgeSourceIngestionParameters(
    network_access_mode=KnowledgeSourceNetworkAccessMode.PUBLIC,
    content_extraction_mode="minimal",
    embedding_model=KnowledgeSourceAzureOpenAIVectorizer(
        azure_open_ai_parameters=embedding_params
    ),
)

knowledge_source = IndexedSqlKnowledgeSource(
    name="indexedsqlks",
    description="Indexed Azure SQL knowledge source.",
    indexed_sql_parameters=IndexedSqlKnowledgeSourceParameters(
        connection_string="Server=tcp:{server}.database.windows.net,1433;Database={db};...;",
        table_or_view="dbo.tbl_hotels",
        content_columns=[
            ContentColumnMapping(
                name="hotelName",
                source_field="HotelName",
                search_field_type="Edm.String",
            ),
            ContentColumnMapping(
                name="description",
                source_field="Description",
                search_field_type="Edm.String",
            ),
        ],
        embedding_columns=[
            EmbeddingColumnMapping(
                name="descriptionVector",
                source_field="Description",
            )
        ],
        ingestion_parameters=ingestion_params,
    ),
)

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

参考:SearchIndexClient

### Create an indexed Azure SQL knowledge source
PUT {{search-endpoint}}/knowledgesources/indexedsqlks?api-version=2026-10-01
Authorization: Bearer {{search-access-token}}
Content-Type: application/json
Prefer: return=representation

{
  "name": "indexedsqlks",
  "kind": "indexedSql",
  "description": "Indexed Azure SQL knowledge source.",
  "indexedSqlParameters": {
    "connectionString": "Server=tcp:{server}.database.windows.net,1433;Database={db};...;",
    "tableOrView": "dbo.tbl_hotels",
    "contentColumns": [
      { "name": "hotelName", "sourceField": "HotelName", "searchFieldType": "Edm.String" },
      { "name": "description", "sourceField": "Description", "searchFieldType": "Edm.String" }
    ],
    "embeddingColumns": [
      { "name": "descriptionVector", "sourceField": "Description" }
    ],
    "ingestionParameters": {
      "networkAccessMode": "public",
      "contentExtractionMode": "minimal",
      "embeddingModel": {
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "{{aoai-endpoint}}",
          "deploymentId": "{{aoai-embedding-deployment}}",
          "modelName": "{{aoai-embedding-model}}"
        }
      }
    }
  }
}

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

使用 indexedSqlParameters 来标识要引入数据的 SQL 表或视图,并定义列映射,这些列映射会成为生成索引中的字段。 对于视图,指定用于更改检测的高水位线列。

列映射

使用 contentColumns 将 SQL 文本列映射到生成的 Foundry IQ 索引中的可搜索字段。 每个内容列映射都指定目标索引字段、源 SQL 列和 Foundry IQ 字段类型。 对于 contentColumns,请使用 Edm.String。

嵌入映射

用于 embeddingColumns 将 SQL 文本列映射到生成的向量字段。 使用嵌入列时,请在 ingestionParameters 中指定嵌入模型。

对于已编制索引的 Azure SQL 知识源,"minimal"必须为contentExtractionMode,因为 SQL 引入过程是基于行的,不会从二进制文档中提取内容。 不支持图像提取和图像语言化,因此chatCompletionModelassetStoreaiServices,与图像相关的设置不起作用。

默认和验证规则

创建索引Azure SQL知识源时,将应用以下默认值。

  • 如果省略 contentColumns,服务会自动将可安全表示为文本的 SQL 列映射到生成索引中的 Edm.String 字段,并使用 1:1 映射,其中 name 等于 sourceField。

  • 如果省略 embeddingColumns,该服务不会创建矢量字段,也不会配置嵌入技能。

  • embeddingColumns 独立于 contentColumns。 若要使向量与可检索的文本相对应,请在两个数组中包含相同的 SQL 列。

  • 源表或视图的主键会被自动发现。 不支持显式重写,并且源必须具有单值主键。

将数据摄取限制在私有网络内

在稳定的 2026-10-01 API 中,networkAccessMode控制在其中为索引Azure SQL知识源运行生成的索引器的网络环境。 此设置仅影响引入,不会更改知识库检索请求或响应。 检查 共享专用链接支持矩阵 ,了解符合条件的配置和独立的预览依赖项。

networkAccessMode 默认为 public,这会保留现有的公共网络行为。 如果 networkAccessMode 为 private,生成的索引器在 专用执行环境中运行。 它使用批准的共享专用链接来访问Azure SQL 数据库或SQL 托管实例源连接和支持的Azure依赖项,例如Azure OpenAI 模型和 Microsoft Foundry 资源。

配置和验证专用网络访问:

  1. 完成 专用网络先决条件。

  2. 在知识源创建请求中,将 networkAccessMode 设置为 private。 只能在创建期间设置此属性,包括在稳定的 2026-10-01 API 中。 若要稍后更改存储模式,请删除并重新创建知识源。 符合条件的 Blob、ADLS Gen2 和 Azure SQL 源可以改用临时生成的索引器网络覆盖。 该异常不适用于索引SharePoint或其他源类型。

    如果服务层或运行时不支持专用执行,或者所需的共享专用链接不存在,则创建可能会失败。 无服务器和 S3 HD 不支持私有执行。 网络安全边界配置 控制支持的公共端点访问,而不是私有执行。

  3. 确认生成的索引器 parameters.configuration.executionEnvironment 为 private.

  4. 确认每个必需的共享专用链接都已获得批准、预配并针对正确的依赖项。 仅凭成功创建并不能确认链接已获批准或定向设置已生效。 如果门户检查无法解析跨订阅资源,请手动验证目标资源和 Foundry IQ 服务的审批和准备情况。

  5. 轮询知识源状态,直到 lastSynchronizationState.endTime 具有值。 确认 itemsUpdatesFailed 为 0,然后验证特定于连接器的源内容。 如果无法访问依赖项,同步将失败。

检查摄取状态

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

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

参考: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))

参考:SearchIndexClient

### Check knowledge source ingestion status
GET {{search-url}}/knowledgesources/{{knowledge-source-name}}/status?api-version={{api-version}}
Authorization: Bearer {{token}}
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 中的新增字段。

查看生成的对象

创建此知识源时,Foundry IQ(Azure AI 搜索)会自动生成数据源、索引器和索引,并在引入管道需要时生成技能集。 创建响应将列出下 createdResources的每个对象。

这些对象根据固定模板生成,其名称基于知识源的名称。 无法更改对象名称。 避免直接编辑这些对象,因为更改可能会引入中断索引器管道的错误或不兼容。

对于符合条件的 Blob、ADLS Gen2 和Azure SQL源,临时网络替代允许更改生成的索引器的执行环境。 此异常不适用于索引SharePoint或 OneLake,并且不允许其他生成的对象更改。 后续的知识源更新或重新生成可能会覆盖该覆盖项。

可以使用Azure门户验证对象创建。 工作流为:

  1. 检查索引器是否有成功或失败的消息。 这里会显示连接错误或配额错误。

  2. 检查数据源以验证与数据存储的连接。 该连接使用连接字符串或托管标识,具体取决于你如何配置知识源。

  3. 如果生成技能集,请检查其扩充和矢量化设置。 仅当指定 embeddingColumns时,SQL 知识源才会生成技能集。

  4. 检查索引以了解您的内容是如何被编制索引和公开以供检索的,包括哪些字段可供搜索和筛选,以及哪些字段存储用于相似性搜索的向量。 使用搜索资源管理器针对生成的索引运行查询。

分配给知识库

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

查询知识库

配置知识库后, 调用检索操作或 MCP 终结点 以查询知识源。

删除知识源

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

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

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

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

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

    参考: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);
    

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

    参考:SearchIndexClient

  4. 删除知识源。

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

    参考:SearchIndexClient

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

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

    参考: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)
    

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

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

    参考:SearchIndexClient

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

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

    参考:知识源 - 删除