跳到主要内容
Azure AI Foundry(以前称为 Azure AI Studio)提供将数据资产上传到云存储以及注册来自以下来源的现有数据资产的功能:
  • Microsoft OneLake
  • Azure Blob 存储
  • Azure Data Lake Gen 2
AzureBlobStorageContainerLoaderAzureBlobStorageFileLoader 相比,这种方法的优势在于可以无缝处理云存储的身份验证。您可以将数据访问控制方式设为“基于身份”或“基于凭据”(例如 SAS 令牌、账户密钥)。在基于凭据的数据访问情况下,您无需在代码中指定密钥或设置密钥保管库——系统会为您处理这些。 本笔记本介绍了如何从 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)]

指定通配符模式

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

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.