第一次运行 GraphRAG
第一次运行 GraphRAG
第一次运行时使用少量公开文本。确认配置、费用和输出都符合预期后,再处理自己的数据。
1. 初始化项目
graphrag init命令会生成 .env、settings.yaml 和 input/。不要把 .env 提交到 Git。
2. 准备小型样本
curl https://www.gutenberg.org/cache/epub/24022/pg24022.txt \
-o ./input/book.txt将 .env 中的 GRAPHRAG_API_KEY=<API_KEY> 替换为有效密钥。如果使用 Azure OpenAI,还要在 settings.yaml 的 models: 下配置 Provider、部署名、端点和 API 版本。
3. 先校验,再索引
graphrag index --dry-run
graphrag index索引成功后,output/ 中会出现 Parquet 文件。若 --dry-run 已失败,不要直接开始付费索引;先修正模型、密钥或路径配置。
4. 执行查询
graphrag query "What are the top themes in this story?"
graphrag query "Who is Scrooge and what are his main relationships?" --method local完成预检、生成索引,并让 Global 与 Local 至少各返回一个与样本文本相关的答案,才算首次运行成功。