建立索引化的 Azure SQL 知識來源

Note

Foundry IQ(Azure AI 搜尋服務)提供直接的索引與查詢 API,並搭配高階知識來源與知識庫 API 用於受控檢索。 使用 Azure 入口網站、REST API 或 Azure SDK 來設定這些功能,或將代理連線到 Microsoft Foundry 入口網站 中的知識庫。

Important

本文中標示為(預覽)的功能或特性目前處於公開預覽狀態,並受 Microsoft Azure 預覽版補充使用條款的約束。

有關 Foundry IQ(Azure AI 搜尋服務)專屬的預覽條款,請參閱 預覽功能。

已建立索引的 Azure SQL 知識來源會將 Azure SQL Database 或 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 portal Microsoft Foundry 入口網站 .NET SDK Python SDK Java SDK JavaScript SDK REST API
✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

先決條件

  • 任何 提供代理檢索的區域內的 Foundry IQ 服務。

  • 完成Azure SQL索引器先修條件,包括:

    • Azure SQL Database或Azure SQL 受控執行個體,並附有表格或視圖可供匯入。

    • 來源資料表或視圖上的單一值主鍵。

    • 對於檢視,適合用於高水位標記變更偵測的資料行。 我們強烈建議使用 rowversion 欄。

  • 允許建立知識來源。 建議使用分配給你的使用者帳號的搜尋服務貢獻者和搜尋索引資料貢獻者角色來設定無密鑰認證,或使用管理員 API 金鑰。

  • 如果您為 Azure OpenAI 嵌入指定embeddingColumns並使用管理識別,請將認知服務 OpenAI 使用者指派給 Azure OpenAI 或父 Foundry 資源中所resourceUri選的識別,且符合 。 請參閱 「指派角色」。

  • 如果你設定 networkAccessMode 為 private,請完成以下要求:

  • 最新的 Azure.Search.Documents 預覽套件:dotnet add package Azure.Search.Documents --prerelease

  • 對於無鑰匙認證,套件如下 Azure.Identity : dotnet add package Azure.Identity

限制與考量

  • 一個知識來源只能從一個資料表或一個檢視擷取資料。
  • 來源資料表或檢視必須有一個單一值的主鍵。 複合金鑰不支援。
  • 主鍵是自動發現的,無法被覆蓋。
  • contentExtractionMode 僅支援 "minimal"。
  • 圖片擷取和影像語音化都不支援。
  • 不支援即時同步。 產生的索引器是基於排程的。
  • 不支援即時 SQL 檢索。 知識來源是有索引的,不是遠端的。

準備產生的索引器

索引化的 Azure SQL 知識來源會自動建立索引器來推動資料擷取。 在建立知識來源前,請先檢視以下細節。

變更偵測

產生的索引器使用標準的 Azure SQL索引器變更偵測:

Authentication

產生的索引器支援兩種認證選項:

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

建立知識來源

執行以下程式碼建立索引的 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.");

參考資料: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 知識來源,contentExtractionMode必須是"minimal"因為 SQL 的擷取是基於列的,不會從二進位文件中擷取內容。 圖片擷取與影像語音化不支援,因此 chatCompletionModel、 assetStore、 aiServices及影像相關設定均無影響。

預設值設定與驗證規則

當你建立索引化的 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 Database 或 SQL 受管理執行個體 原始碼連線,以及支援的 Azure 相依關係,例如 Azure OpenAI 模型和 Microsoft Foundry 資源。

要配置並驗證私人網路存取:

  1. 完成 私人網路的必要條件。

  2. 在建立知識來源的請求中,將 networkAccessMode 設為 private。 您只能在建立過程中設定此屬性,包括在穩定版 2026-10-01 API 中。 若要稍後變更儲存模式,請刪除並重新建立知識來源。 符合資格的 Blob、ADLS Gen2 和 Azure SQL 來源則可改用臨時生成索引器的網路覆寫。 此例外不適用於已建立索引的 SharePoint 或其他來源類型。

    如果服務層級或執行時不支援私有執行,或沒有所需的共享私有連結,建立可能會失敗。 Serverless 和 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
  }
}

Note

kind屬性和currentSynchronizationState.errors[]陣列提供文件層級錯誤細節,並自 2026-04-01 起於 API 版本中提供。 對於較早期的 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}}
    

    參考資料:知識來源 - 刪除