Azure AI Data
Azure AI Studio 提供將資料資產上傳至雲端儲存空間,以及從以下來源註冊現有資料資產的功能:
Microsoft OneLake
Azure Blob Storage
Azure Data Lake gen 2
相較於 AzureBlobStorageContainerLoader
和 AzureBlobStorageFileLoader
,這種方法的優點是身份驗證可以無縫地處理到雲端儲存空間。 您可以使用基於身分的資料存取控制來存取資料,或使用基於認證的(例如,SAS 權杖、帳戶金鑰)。 如果是基於認證的資料存取,您不需要在程式碼中指定密碼或設定金鑰保存庫 - 系統會為您處理。
本筆記本涵蓋了如何從 AI Studio 中的資料資產載入文件物件。
%pip install --upgrade --quiet azureml-fsspec, azure-ai-generative
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential
from langchain_community.document_loaders import AzureAIDataLoader
API 參考:AzureAIDataLoader
# Create a connection to your project
client = AIClient(
credential=DefaultAzureCredential(),
subscription_id="<subscription_id>",
resource_group_name="<resource_group_name>",
project_name="<project_name>",
)
# get the latest version of your data asset
data_asset = client.data.get(name="<data_asset_name>", label="latest")
# load the data asset
loader = AzureAIDataLoader(url=data_asset.path)
loader.load()
[Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': '/var/folders/y6/8_bzdg295ld6s1_97_12m4lr0000gn/T/tmpaa9xl6ch/fake.docx'}, lookup_index=0)]
指定 glob 模式
您還可以指定 glob 模式,以便更精細地控制要載入哪些檔案。 在下面的範例中,只會載入副檔名為 pdf
的檔案。
loader = AzureAIDataLoader(url=data_asset.path, glob="*.pdf")
loader.load()
[Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': '/var/folders/y6/8_bzdg295ld6s1_97_12m4lr0000gn/T/tmpujbkzf_l/fake.docx'}, lookup_index=0)]