Skip to main content
Open In ColabOpen on GitHub

Azure AI 数据

Azure AI Studio provides the capability to upload data assets to cloud storage and register existing data assets from the following sources:

  • Microsoft OneLake
  • Azure Blob Storage
  • Azure Data Lake gen 2

这种方法相较于 AzureBlobStorageContainerLoaderAzureBlobStorageFileLoader 的优势在于,身份验证可无缝处理云存储。您可以使用基于身份的数据访问控制,或使用基于凭据(例如 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)]

指定通配符模式

您还可以指定通配符模式,以更精细地控制要加载的文件。在下面的示例中,仅会加载扩展名为 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)]