你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
注释
此功能目前处于公开预览状态。 此预览版未随附服务级别协议,建议不要用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款。
搜索索引知识源指定与 Azure AI 搜索索引的连接,该索引在代理检索管道中提供可搜索内容。 知识源 是独立创建的,在 知识代理中引用,并在代理或聊天机器人在查询时调用 检索 作时用作基础数据。
知识来源是 2025-08-01-preview 版本中的新增功能。
先决条件
需要一个搜索索引,其中包含具有语义配置的纯文本或矢量内容。 查看用于代理检索的索引条件。 索引必须与知识代理位于同一搜索服务上。
若要尝试本文中的示例,建议将 Visual Studio Code 与 REST 客户端扩展 配合使用,以便向 Azure AI 搜索发送预览版 REST API 调用。 目前没有门户支持。
检查现有知识来源
知识来源是顶级可重用对象。 所有知识来源在知识来源集合中必须具有唯一命名。 了解现有知识源有助于重复使用或命名新对象。
使用 知识源 - 获取(REST API) 按名称和类型列出知识源。
### List knowledge sources by name and type
GET {{search-url}}/knowledgeSources?api-version=2025-08-01-preview&$select=name,kind
api-key: {{api-key}}
Content-Type: application/json
还可以按名称返回单个知识来源以查看其 JSON 定义。
### Get a knowledge source definition
GET {{search-url}}/knowledgeSources/{{knowledge-source-name}}?api-version=2025-08-01-preview
api-key: {{api-key}}
Content-Type: application/json
以下 JSON 是 searchIndex 知识来源的示例响应。 请注意,知识来源指定单个索引名称以及要包含在查询中的索引中的字段。
{
"name": "earth-at-night-ks",
"kind": "searchIndex",
"description": "Earth at night e-book knowledge source",
"encryptionKey": null,
"searchIndexParameters": {
"searchIndexName": "earth_at_night",
"sourceDataSelect": "page_chunk,page_number"
},
"azureBlobParameters": null,
"webParameters": null
}
注释
该 webParameters 属性在此预览版中不起作用,并保留供将来使用。
创建知识来源
若要创建 searchIndex 知识来源,请执行以下操作:
在文件顶部设置环境变量。
@search-url = <YOUR SEARCH SERVICE URL> @api-key = <YOUR ADMIN API KEY> @ks-name = <YOUR KNOWLEDGE SOURCE NAME> @index-name = <YOUR INDEX NAME>使用 2025-08-01-preview 版本的 知识源 - 创建或更新(REST API) 或提供等效功能的 Azure SDK 预览包来构建请求。
POST {{search-url}}/knowledgeSources?api-version=2025-08-01-preview api-key: {{api-key}} Content-Type: application/json { "name" : "{{ks-name}}", "kind" : "searchIndex", "description" : "Earth at night e-book knowledge source", "searchIndexParameters" :{ "searchIndexName" : "{{index-name}}", "sourceDataSelect" : "page_chunk,page_number" } }选择“发送请求”。
要点:
name在知识源集合中必须是唯一的,并遵循 Azure AI 搜索中对象的 命名准则 。对于搜索索引知识来源,
kind必须是searchIndex。searchIndexName是索引的名称,该索引必须 针对智能检索设计。sourceDataSelect是在知识代理定义中指定includeReferenceSourceData时返回的索引字段列表。 这些字段用于引文,应为retrievable。 示例包括文档名称、文件名、页码或章节号。
分配给知识代理
如果对索引感到满意,请继续执行下一步:在知识代理中指定知识来源。
在知识代理中,知识来源上还有更多针对查询操作需要设置的属性。
删除知识来源
如果不再需要知识来源,或者需要在搜索服务上重新生成它,请使用此请求删除当前对象。
在删除知识源之前,必须先删除引用它的任何知识代理,或远程删除更新作中的引用。 从知识源创建的相关索引和任何索引器管道对象都是独立的对象,无需与知识源一起删除或更新。
如果尝试删除未使用的知识来源,操作会失败,并返回受影响的知识智能体列表。
首先获取所有知识代理的列表。 此请求将返回您搜索服务中的所有知识代理程序。
### Get the knowledge agent GET {{search-endpoint}}/agents?api-version=2025-08-01-preview&$select=name api-key: {{api-key}} Content-Type: application/json示例响应可能如下所示:
{ "@odata.context": "https://my-demo-search-service.search.windows.net/$metadata#agents(name)", "value": [ { "name": "earth-blob-ka" }, { "name": "hotels-sample-ka" } ] }获取用于检查知识源引用的单个知识代理定义。
GET {{search-endpoint}}/agents/hotels-sample-ka?api-version=2025-08-01-preview api-key: {{api-key}} Content-Type: application/json示例响应可能如下所示:
{ "name": "hotels-sample-ka", "description": null, "retrievalInstructions": null, "knowledgeSources": [ { "name": "hotels-sample-ks", "alwaysQuerySource": false, "includeReferences": true, "includeReferenceSourceData": false, "maxSubQueries": null, "rerankerThreshold": null } ], "models": [ trimmed for brevity ], "outputConfiguration": { trimmed for brevity }, "requestLimits": { trimmed for brevity}, "encryptionKey": null }如果有多个源,则通过删除知识源来 更新知识代理 ,或删除知识代理。 此示例显示删除。
### Delete knowledge agent DELETE {{search-endpoint}}/agents/hotels-sample-ka?api-version=2025-08-01-preview api-key: {{api-key}} Content-Type: application/json删除知识来源。
### Delete a knowledge source definition GET {{search-endpoint}}/knowledgeSources/hotels-sample-ks?api-version=2025-08-01-preview api-key: {{api-key}} Content-Type: application/json