Nuclia 理解
Nuclia 自动化地从任何内部和外部源对您的非结构化数据进行索引,提供优化的搜索结果和生成的答案。它可以处理视频和音频转录、图像内容提取以及文档解析。
The Nuclia Understanding API 支持结构化和非结构化数据的处理,包括文本、网页、文档以及音频/视频内容。它会提取文本中的所有信息(在需要时使用语音转文字或OCR),识别实体,并抽取元数据、嵌入文件(例如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 返回以下信息:<br>
- 文件元数据
- 提取的文本
- 嵌套文本(如嵌入图像中的文本)
- a summary (只有当
enable_ml设置为True时显示) - 段落和句子分割(由其首尾字符位置定义,加上视频或音频文件的开始时间和结束时间)
- 命名实体:人物、日期、地点、组织等(仅当
enable_ml设置为True时) - links
- a thumbnail
- embedded files
- 文本的向量表示(仅在将
enable_ml设置为True时)
注意:
Generated files (thumbnail, extracted embedded files, etc.) are provided as a token. You can download them with the /processing/download endpoint.
Also at any level, if an attribute exceeds a certain size, it will be put in a downloadable file and will be replaced in the document by a file pointer. This will consist of {"file": {"uri": "JWT_TOKEN"}}. The rule is that if the size of the message is greater than 1000000 characters, the biggest parts will be moved to downloadable files. First, the compression process will target vectors. If that is not enough, it will target large field metadata, and finally it will target extracted text.