У меня есть учетная запись хранения с настроенным хранилищем контейнеров Azure, состоящая из нескольких файлов pdf/word/excel. Я хотел бы использовать Azure Document Intelligence для семантической разбивки этих файлов.
Есть ли возможность загрузить файлы непосредственно из хранилища контейнеров в Azure Document Intelligence с помощью langchain
? Согласно документации langchain похоже, что либо файл должен быть доступен локально, либо необходимо передать общедоступный URL-адрес.
Пытаться:
# Prerequisite: An Azure AI Document Intelligence resource in one of the 3 preview regions: East US, West US2, West Europe
import os
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader
file_path = "storage-path-to-file"
endpoint = os.getenv("DOCUMENTINTELLIGENCE_ENDPOINT")
key = os.getenv("DOCUMENTINTELLIGENCE_API_KEY")
loader = AzureAIDocumentIntelligenceLoader(
api_endpoint=endpoint, api_key=key, file_path=file_path, api_model = "prebuilt-layout"
)
documents = loader.load()
# Returns:
# Message: Invalid request.
# Inner error: {
# "code": "InvalidManagedIdentity",
# "message": "The managed identity configuration is invalid: Managed identity is not enabled # for the current resource."
# }
с помощью Поиска Azure вы можете встраивать фрагменты, но не выполнять семантическое фрагментирование как таковое. Для семантического фрагментирования вам понадобятся такие вещи, как Azure Document Intelligence.
@ user483161 Проверьте ответ ниже.
Есть ли возможность загрузить файлы непосредственно из хранилища контейнеров в Azure Document Intelligence с помощью
langchain
? Согласно документации langchain похоже, что либо файл должен быть доступен локально, либо необходимо передать общедоступный URL-адрес.
Вы можете использовать приведенный ниже код, который загружает файлы непосредственно из хранилища BLOB-объектов Azure, используя Azure Blob URL + SAS token.
Код:
import os
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader
#bloburl + ?Sastoken
URL = "https://venkat78932.blob.core.windows.net/test/24005356.pdf?sp=r&st=2024-07-09T12:41:41Z&se=2024-07-09T20:41:41Z&spr=https&sv=2022-11-02&sr=b&sig=eupT8WGH5ojQpXYd%2xxxxxD"
endpoint = os.getenv("DOCUMENTINTELLIGENCE_ENDPOINT")
key = os.getenv("DOCUMENTINTELLIGENCE_API_KEY")
loader = AzureAIDocumentIntelligenceLoader(
api_endpoint=endpoint, api_key=key, url_path=URL, api_model = "prebuilt-layout"
)
documents = loader.load()
print(len(documents))
print(documents[0])
Выход:
1
page_content='Word Documents Template\n===\n\n\n## Main heading:\n\nUse the Heading 1 style for primary headings so that screen readers can identify them as such.\n\nIf not already, manually change your heading 1 style to be:\n\n\\- sans serif (e.g. Arial, Verdana, Trebuchet or Calibri),\n\n\\- 16 pt, and\n\n\\- Bold\n\nThen set this formatting as your default for this style.\n\n\n## Sub Headings:\n\nUse Heading 2 style for sub headings.\n\nIf not already, manually change your heading 2 style to be:\n\n\\- sans serif (e.g. Arial, Verdana, Trebuchet or Calibri...................tands out, and does not distort the shape of text as italics and underlining do. Finally, block capitals can be difficult to follow as block capitals remove the natural shape of words, turning them into blocks. Clear layout allows one to focus on the content of visual materials rather than the format.\n\n\n## Furthermore\n\nIf you use headings it makes the creation and upkeep of tables of contents easier (For automatic creation and updating go to: Insert - Reference - Index and Tables - Table of contents).\n'
Вы можете получить Azure Blob URL + SAS token
на портале.
Портал -> Учетная запись хранения -> Контейнер -> ваш файл -> Создать токен Sas -> нажмите «Создать токен Sas и URL-адрес».
Портал:
Ссылка: Анализ документов Azure AI | 🦜️🔗 ЛангЧейн
Есть ли также возможность использовать ключ хранения учетной записи хранения напрямую вместо создания токена SAS?
Нет, если вам нужно пройти аутентификацию с помощью ключа доступа, вам нужно загрузить большой двоичный объект на локальный компьютер и загрузить его по локальному пути.
Похоже, вы можете подключиться напрямую через этот блокнот: https://github.com/jbernec/rag-orchestrations/blob/main/azure-ai-document-intelligence/rag_document_extraction.ipynb
не можете ли вы просто использовать Azure AI Search + индексатор Azure AI Search?