生成式人工智能/大语言模型

使用一个 GPU 运行多模态提取以实现更高效的 AI 工作流

随着企业生成和使用越来越多的多样化数据,从 PDF 和演示文稿等多模态文档中提取见解已成为一项重大挑战。传统的纯文本提取和基本的检索增强生成 (RAG) 流程存在缺陷,无法充分发挥这些复杂文档的价值。结果如何?见解缺失、工作流程效率低下以及运营成本上升。

在本博文中,我们将通过使用 NVIDIA NeMo Retriever 微服务的代码示例和一个 GPU,深入探讨构建有效的多模态提取工作流的关键组件。

NVIDIA NeMo Retriever 提取工作流

NeMo Retriever Retriever 是多模态文档处理工作流的示例架构。它使用微服务从数百万文档的不同文件类型中高效提取信息。它与 NeMo Retriever 嵌入和重排序模型搭配使用,形成了完整的可扩展 RAG 解决方案,如适用于 RAG 的 NVIDIA AI Blueprint 所示 (如图 1 所示) 。

 A diagram showing the multimodal extraction pipeline and retrieval pipeline of NVIDIA NeMo Retriever.
图 1。提取流程图,作为构建企业 RAG NVIDIA AI Blueprint 的一部分

在下一节中,我们将介绍一个简单的用例,其中展示了分步 NeMo Retriever 提取工作流以及其他 NeMo Retriever 组件,以使用提取的数据。

借助多模态文档理解完成业务任务

为此,我们将考虑一个组织共享文件夹,其中包含有关 NVIDIA Blackwell GPU 的产品资源。这些文件包括不同类型(例如 PDF、PPTX 和 JPEG)的文本、图像、图表和表格。

在本示例中,客户支持工程师要求比较 NVIDIA Blackwell 的性能,以便为合作伙伴提供支持。

此类请求可以通过任何应用程序发送,例如聊天用户界面或自动内容生成器。在这里,我们将使用pipeline的 Python 客户端的直接提示来演示它。

第 1 步:使用一个 GPU 加速管道

在本地或云计算机上使用 Docker 部署蓝图。请参阅 NVIDIA 文档中的 NeMo Retriever 提取快速入门指南中的部署指南。

在本示例中,整个工作流部署在 AWS g6e.xlarge 计算机 (L40S GPU,48 GB) 上。验证所需配置文件的所有已部署服务是否正常运行。

An image of deployed services of NeMo Retriever Extraction, which includes all pipeline models, serving, and observability tools.
图 2。NVIDIA NeMo Retriever 提取部署服务

工作流服务包括视觉元素识别和 OCR (光学字符识别) 模型、嵌入模型、Milvus DB 以及可观察性工具 (Prometheus 和 Grafana、Attu、Zipkin 等) 。

注意:出于原型设计目的,可以在蓝图页面 Build an Enterprise RAG pipeline 中访问pipeline源代码。

第 2 步:提交存储中文件的 ingestion 作业

所有服务启动后,我们可以通过 Python 客户端或 CLI (Command Line Interface) 提交提取作业。

我们将展示 Python 客户端的用法。

在本示例中,我们传递集合中文件的路径,并定义要包含在作业中的任务 (即extract、split和embed) 。我们将extract任务设置为包含所有modalities类型,并将split任务设置为将文本分块为1,024个token。

from nv_ingest_client.client import Ingestor

demo_files = "demo_files/*"

ingestor = (
    Ingestor(message_client_hostname="localhost")
    .files(demo_files)
    .extract(
        extract_text=True,
        extract_tables=True,
        extract_charts=True,
        extract_images=True,
        text_depth="page",
    )
    .dedup()
    .split(
        tokenizer="meta-llama/Llama-3.2-1B",
        chunk_size=1024,
    )
    .embed()
    .vdb_upload()
)

result = ingestor.ingest()

第 3 步:分析 Job 结果

完成提取作业后,我们可以分析结果结构 (Figure 3):

import pandas as pd

df = pd.DataFrame([])
for doc in result:
    for obj in doc:
        df = pd.concat([df,pd.json_normalize(obj)])

display(df)
A screenshot showing extraction job results structure.
图 3。Extraction job 结果

作业提取为我们的每个文档生成了来自不同模式的多个对象。其中包括文本、图像和结构化对象,指的是charts和tables。

例如,我们可以看到提取的文本对象 Text Object:

# print a random text object that was extracted. 

print(df[df['document_type']=='text'].sample(1)['metadata.content'][0])

# Output:
# NVIDIA GB200 NVL72 | Datasheet | 1
# NVIDIA GB200 NVL72
# Powering the new era of computing.
# Unlocking Real-Time Trillion-Parameter Models
# NVIDIA GB200 NVL72 connects 36 Grace CPUs and 72 Blackwell GPUs in an NVIDIA®
# NVLink®-connected, liquid-cooled, rack-scale design. Acting as a single, massive GPU, it
# delivers 30X faster real-time trillion-parameter large language model (LLM) inference.
# The GB200 Grace Blackwell Superchip is a key component of the NVIDIA GB200
# NVL72, connecting two high-performance NVIDIA Blackwell GPUs and an NVIDIA...

还可以将文本分割成较小的块。我们可以在 Ingestor 的拆分配置中控制分块策略。

以下是提取的随机表例:

# detected chart
from base64 import b64decode
from IPython import display

rand_extracted_object = df[df['document_type']=='structured'].sample(1)

display.Image(b64decode(rand_extracted_object['metadata.content'][0]))
An image of a table object that was extracted by the ingestion job, aligned and bounded correctly.
图 4。一个由 ingestion job 提取的表格

除了视觉对象提取之外,还保存了其中的文本内容:

# table textual content
rand_extracted_object['metadata.table_metadata.table_content'][0]

# Output:
# " | Product Specifications' |\n| The NVIDIA GB200 Grace Blackwell Superchip comes in two configurations: GB200 NVL72 and GB200 NVL2 |\n| Feature | GB200 NVL72 | GB200NVL2 | GB200 Grace Blackwell | Superchip |\n| Configuration | 36 Grace CPUs, | 2 Grace CPUs, | 1 Grace CPU, |\n| 72 Blackwell GPUs, | 2 Blackwell GPUs | 2 Blackwell GPUs ....

这些对象被作业自动分块和嵌入。我们可以通过 Milvus 客户端或 Attu ( Milvus 的 Web 用户界面) 服务 (在第 1 步中与服务包的其余部分一起部署) ,追踪流程自动创建的 Milvus 集合中的向量嵌入。

A screenshot of an Attu dashboard showing the created Milvus collection.
图 5。Milvus 集合由 NVIDIA NeMo Retriever 提取管道自动创建

第 4 步:检索

我们将演示如何基于 NeMo Retriever 提取工作流、提取的数据和 NeMo Retriever 嵌入构建检索组件。首先,为嵌入和生成器 LLM 微服务定义 NVIDIA 客户端。

from openai import OpenAI

nvidia_client = OpenAI(
  api_key="...",
  base_url="https://integrate.api.nvidia.com/v1"
)

嵌入用户查询 (使用提取中使用的相同嵌入模型)

user_query = "I am a customer support engineering asking for my client - What is the main difference between the two configurations of grace blackwell?"

# embed user query
response = nvidia_client.embeddings.create(
    input=user_query,
    model="nvidia/nv-embedqa-e5-v5",
    encoding_format="float",
    extra_body={"input_type": "query", "truncate": "NONE"}
)
user_query_vector=response.data[0].embedding

使用 NeMo Retriever 提取 Python 客户端检索器获取与用户查询最相似的结果:

from nv_ingest_client.util.milvus import nvingest_retrieval

query_results = nvingest_retrieval(
    [user_query],
    "nv_ingest_collection",
    hybrid=False,
    embedding_endpoint="http://localhost:8012/v1",
    model_name="nvidia/llama-3.2-nv-embedqa-1b-v2",
    top_k=1,
    gpu_search=True,
)

top_result = query_results[0][0]['entity']['text']

为生成器 LLM 创建相关提示并获取响应:

prompt = """Based on the following context answer the user query:

context:
{}

user query:
{}

""".format(top_result, user_query)

completion = nvidia_client.chat.completions.create(
  model="meta/llama-3.2-3b-instruct",
  messages=[{"role":"user","content":prompt}],
  temperature=0.2,
  top_p=0.7,
  max_tokens=200,
  stream=True
)

for chunk in completion:
  if chunk.choices[0].delta.content is not None:
    print(chunk.choices[0].delta.content, end="")


# Output:
# Based on the provided context, the main difference between the two configurations of the NVIDIA GB200 Grace Blackwell Superchip is the number of Grace CPUs and Blackwell GPUs.
#
# The two configurations are:
# 1. GB200 NVL72: 36 Grace CPUs, 72 Blackwell GPUs
# 2. GB200 NVL2: 2 Grace CPUs, 2 Blackwell GPUs
#
# This difference affects the overall performance and capabilities of the system, with the NVL72 configuration having more processing power and memory bandwidth due to the higher number of Grace CPUs and Blackwell GPUs.

我们检索了高度相关的数据块,无需对原始文件进行任何直接搜索和审查。

这个简单的用例展示了如何通过快速部署设置来自动理解多模态企业源文件的上下文。

总结

NeMo Retriever 提取工作流通过自动处理不同的文件类型 (例如 PDF、演示文稿和电子表格) 来解决多模态文档处理的挑战。从文本、图像、表格和图表中提取有意义的内容,将以前孤立的信息更改为可访问的结构化数据。这使组织能够从现有知识库中获得更深入的见解。

此解决方案背后的架构整合了 Object Detection、Chart Parsing 和 Vector Embeddings 等高级组件,可实现高效的上下文感知检索。通过保留跨模态的关系并通过 Semantic Search 将其表面化,该工作流提供了一种全面的文档理解方法。使用 NeMo Retriever 实施这种端到端流程标志着企业知识管理的重大进步,它将未被充分利用的静态文档转化为高价值资产,从而推动生成式 AI 应用和更智能的决策制定。

通过不断提取和使用新数据,NeMo Retriever 还可以帮助组织创建数据飞轮,通过提高数据质量,生成更好的 AI 模型,进而生成更有价值的数据。

使用适用于 RAG 的 NVIDIA AI 蓝图开始使用 NeMo Retriever 提取工作流,或在 build.nvidia.com 上试用单个 NeMo Retriever 微服务,以进行提取、嵌入和重新排序。

 

标签