Skip to main content
Azure AI Foundry(前身为 Azure AI Studio)提供了将数据资产上传到云存储的功能,并支持从以下来源注册现有数据资产:
  • Microsoft OneLake
  • Azure Blob Storage
  • Azure Data Lake gen 2
AzureBlobStorageContainerLoaderAzureBlobStorageFileLoader 相比,此方法的优势在于可以无缝处理云存储的身份验证。您可以使用基于身份的数据访问控制或基于凭证的访问控制(例如 SAS token、账户密钥)。对于基于凭证的数据访问,您无需在代码中指定密钥或设置密钥库,系统会自动处理。 本笔记本介绍如何从 AI Studio 中的数据资产加载文档对象。
pip install -qU azureml-fsspec azure-ai-generative
from azure.ai.resources.client import AIClient
from azure.identity import DefaultAzureCredential
from langchain_community.document_loaders import 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)]