NVIDIA Ingest 项目使用教程
1. 项目目录结构及介绍
NVIDIA Ingest 是一个用于解析 PDF 和其他文档内容,提取元数据和文本的开源项目。以下是项目的目录结构及其简单介绍:
nv-ingest/
├── .devcontainer/
├── .github/
├── api/ # 包含API相关代码
├── ci/ # 包含持续集成相关脚本和配置
├── client/ # 客户端相关代码
├── conda/ # Conda环境配置和依赖
├── config/ # 配置文件和脚本
├── data/ # 示例数据和测试文件
├── deploy/ # 部署脚本和文档
├── docker/ # Docker配置文件和脚本
├── docs/ # 文档资料
├── evaluation/ # 评估和测试代码
├── examples/ # 使用示例
├── helm/ # Kubernetes的helm配置
├── skaffold/ # Skaffold配置
├── src/ # 源代码
├── tests/ # 测试代码
├── .gitignore # Git忽略文件
├── .pre-commit-config.yaml # pre-commit钩子配置
├── CHANGELOG.md # 更改日志
├── CITATION.md # 引用指南
├── CODE_OF_CONDUCT.md # 行为准则
├── CONTRIBUTING.md # 贡献指南
├── Dockerfile # Docker构建文件
├── LICENSE # 开源许可证
├── README.md # 项目描述
├── SECURITY.md # 安全协议
├── docker-compose.yaml # Docker Compose配置
├── print_env.sh # 打印环境变量的脚本
├── pyproject.toml # Python项目配置
└── pytest.ini # Pytest配置
2. 项目的启动文件介绍
项目的启动主要通过 src
目录下的 Python 脚本进行。以下是一个简单的启动脚本示例:
# your_ingestion_script.py
import logging
import os
import time
import sys
from nv_ingest.util.pipeline.pipeline_runners import start_pipeline_subprocess
from nv_ingest_client.client import Ingestor, NvIngestClient
from nv_ingest_client.util.process_json_files import ingest_json_results_to_blob
# 其他必要的import
# 配置并启动 pipeline 子进程
config = PipelineCreationSchema()
pipeline_process = start_pipeline_subprocess(config)
# 设置客户端
client = NvIngestClient(message_client_allocator=SimpleClient, message_client_port=7671, message_client_hostname="localhost")
# 执行内容提取操作
ingestor = Ingestor(client=client).files("data/multimodal_test.pdf").extract(...).embed().vdb_upload(...)
results = ingestor.ingest(show_progress=True)
# 输出结果
print(ingest_json_results_to_blob(results[0]))
这个脚本会启动 NVIDIA Ingest 的处理流程,并提取指定 PDF 文件的内容。
3. 项目的配置文件介绍
配置文件通常位于 config
目录中。这些文件用于定义项目运行时需要的参数和设置。例如,可能存在一个配置文件 config.json
,它可能包含以下内容:
{
"api_endpoint": "http://localhost:5000",
"database_connection": "mysql://user:password@localhost/dbname",
"other_settings": {
"key1": "value1",
"key2": "value2"
}
}
这个文件定义了 API 端点、数据库连接和其他必要的设置,项目在运行时会加载这些配置来初始化环境。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考