共用方式為


資料來源 - Pinecone (預覽)

使用 Azure OpenAI On Your Data 時,Pinecone 的可設定選項。 API 版本 2024-02-15-preview支援此資料來源。

名稱 類型​​ 必要 描述
parameters 參數 True 設定 Pinecone 時要使用的參數。
type string True 必須是 pinecone

參數

姓名 類型​​ 必要 描述
environment string True Pinecone 的環境名稱。
index_name string True Pinecone 資料庫索引的名稱。
fields_mapping FieldsMappingOptions True 與搜尋索引互動時要使用的自定義欄位對應行為。
authentication ApiKeyAuthenticationOptions True 存取已定義數據源時要使用的驗證方法。
embedding_dependency DeploymentNameVectorizationSource True 向量搜尋的內嵌相依性。
in_scope boolean False 查詢是否應該限制為使用索引數據。 預設值為 True
role_information string False 提供模型關於其行為方式的指示,以及產生回應時應該參考的任何內容。 您可以描述助理的個性,並告知其如何格式化回應。
strictness 整數 False 已設定的搜尋相關性篩選嚴格性。 嚴格程度越高,精確度越高,但對答案的召回率較低。 預設值為 3
top_n_documents 整數 False 設定的檔數目已設定為已設定查詢的功能。 預設值為 5

API 金鑰驗證選項

使用 API 金鑰時,Azure OpenAI On Your Data 的驗證選項。

名稱 類型​​ 必要 描述
key string True 要用於驗證的 API 金鑰。
type string True 必須是 api_key

部署名稱向量化來源

套用向量搜尋時,Azure OpenAI On Your Data 所使用的向量化來源詳細數據。 此向量化來源是以相同 Azure OpenAI 資源中的內部內嵌模型部署名稱為基礎。 此向量化來源可讓您在沒有 Azure OpenAI API 金鑰的情況下使用向量搜尋,而不需要 Azure OpenAI 公用網路存取。

名稱 類型​​ 必要 描述
deployment_name string True 相同 Azure OpenAI 資源內的內嵌模型部署名稱。
type string True 必須是 deployment_name

欄位對應選項

控制欄位處理方式的設定。

名稱 類型​​ 必要 描述
content_fields string[] True 應視為內容的索引欄位名稱。
content_fields_separator string False 內容欄位應該使用的分隔符模式。 預設值為 \n
filepath_field string False 要當做檔案路徑使用的索引字段名稱。
title_field string False 要當做標題使用的索引字段名稱。
url_field string False 要當做 URL 使用的索引欄位名稱。

範例

先決條件:

  • 設定從使用者到 Azure OpenAI 資源的角色指派。 必要角色: Cognitive Services OpenAI User
  • 安裝 Az CLI 並執行 az login
  • 定義下列環境變數:AzureOpenAIEndpointEnvironmentChatCompletionsDeploymentName、、、IndexNameKeyEmbeddingDeploymentName
export AzureOpenAIEndpoint=https://example.openai.azure.com/
export ChatCompletionsDeploymentName=turbo
export Environment=testenvironment
export Key=***
export IndexName=pinecone-test-index
export EmbeddingDeploymentName=ada

安裝最新的 pip 套件 openaiazure-identity

import os
from openai import AzureOpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

endpoint = os.environ.get("AzureOpenAIEndpoint")
deployment = os.environ.get("ChatCompletionsDeploymentName")
environment = os.environ.get("Environment")
key = os.environ.get("Key")
index_name = os.environ.get("IndexName")
embedding_deployment_name = os.environ.get("EmbeddingDeploymentName")

token_provider = get_bearer_token_provider(
    DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")

client = AzureOpenAI(
    azure_endpoint=endpoint,
    azure_ad_token_provider=token_provider,
    api_version="2024-02-15-preview",
)

completion = client.chat.completions.create(
    model=deployment,
    messages=[
        {
            "role": "user",
            "content": "Who is DRI?",
        },
    ],
    extra_body={
        "data_sources": [
            {
                "type": "pinecone",
                "parameters": {
                    "environment": environment,
                    "authentication": {
                        "type": "api_key",
                        "key": key
                    },
                    "index_name": index_name,
                    "fields_mapping": {
                        "content_fields": [
                            "content"
                        ]
                    },
                    "embedding_dependency": {
                        "type": "deployment_name",
                        "deployment_name": embedding_deployment_name
                    }
                }}
        ],
    }
)

print(completion.model_dump_json(indent=2))