Skip to main content
Open In ColabOpen on GitHub

Nuclia 理解

Nuclia automatically indexes your unstructured data from any internal and external source, providing optimized search results and generative answers. It can handle video and audio transcription, image content extraction, and document parsing.

Nuclia Understanding API 支持处理非结构化数据,包括文本、网页、文档以及音频/视频内容。它会提取所有位置的文本(必要时使用语音转文字或光学字符识别),识别实体,并提取元数据、嵌入文件(如 PDF 中的图片)和网页链接。它还提供内容摘要。

要使用Nuclia Understanding API,您需要拥有一个Nuclia账户。您可以在https://nuclia.cloud免费创建一个账户,然后创建 NUA 密钥

%pip install --upgrade --quiet  protobuf
%pip install --upgrade --quiet nucliadb-protos
import os

os.environ["NUCLIA_ZONE"] = "<YOUR_ZONE>" # e.g. europe-1
os.environ["NUCLIA_NUA_KEY"] = "<YOUR_API_KEY>"
from langchain_community.tools.nuclia import NucliaUnderstandingAPI

nua = NucliaUnderstandingAPI(enable_ml=False)

您可以使用push操作将文件推送到 Nuclia Understanding API。由于处理是异步进行的,结果的返回顺序可能与文件推送的顺序不同。因此,您需要提供一个id,以便将结果与相应的文件进行匹配。

nua.run({"action": "push", "id": "1", "path": "./report.docx"})
nua.run({"action": "push", "id": "2", "path": "./interview.mp4"})

您现在可以在循环中调用 pull 操作,直到获得 JSON 格式的结果。

import time

pending = True
data = None
while pending:
time.sleep(15)
data = nua.run({"action": "pull", "id": "1", "path": None})
if data:
print(data)
pending = False
else:
print("waiting...")

您也可以在 async 模式中一步完成,只需执行推送操作,系统将等待直到结果被拉取:

import asyncio


async def process():
data = await nua.arun(
{"action": "push", "id": "1", "path": "./talk.mp4", "text": None}
)
print(data)


asyncio.run(process())

检索到的信息

Nuclia 返回以下信息:

  • 文件元数据
  • 提取的文本
  • 嵌套文本(如嵌入图像中的文本)
  • 摘要(仅当 enable_ml 设置为 True 时)
  • 段落和句子拆分(由其首尾字符的位置定义,对于视频或音频文件还包括开始时间和结束时间)
  • 命名实体:人物、日期、地点、组织等(仅当 enable_ml 设置为 True 时)
  • 链接
  • 缩略图
  • 嵌入文件
  • 文本的向量表示(仅当 enable_ml 设置为 True 时)

Note:

生成的文件(缩略图、提取的嵌入文件等)以令牌形式提供。您可以使用 /processing/download 端点 下载它们。

此外,在任何层级,如果某个属性超过特定大小,它将被放入可下载文件中,并在文档中由文件指针替换。这将由 {"file": {"uri": "JWT_TOKEN"}} 组成。规则是:如果消息大小大于 1000000 个字符,最大的部分将被移至可下载文件。首先,压缩过程将针对向量;如果仍不足,则将针对大型字段元数据,最后针对提取的文本。