Skip to main content

graphrag api 调用

Project description

GraphRag-API

GraphRag-API 在 GraphRag 库的基础上扩展,提供了 API 调用功能,用于执行本地和全局搜索。此扩展允许用户通过 RESTful API 调用,轻松地将 GraphRag 的强大搜索功能集成到他们的应用程序中。

功能

  • 本地搜索:在指定的本地数据集内进行搜索。
  • 全局搜索:在更广泛的全球数据集中进行搜索。
  • 可配置参数:通过配置文件或 API 调用自定义搜索参数。
  • RESTful API:通过 HTTP 请求轻松与其他应用程序和服务集成。

安装

先决条件

确保已安装 Python 3.8+。

通过 pip 安装

使用 pip 安装 GraphRag-API:

pip install graphrag_api

从源码安装

  1. 克隆源码库:
git clone https://github.com/nightzjp/graphrag_api
  1. 进入项目目录并安装依赖:
cd graphrag_api
pip install -r requirements.txt

使用

初始化

  1. 命令行初始化
python -m graphrag.index --init --root ./rag  # graphrag初始化
python index_test.py --init --root rag  # graphrag_api初始化

2代码初始化

from graphrag_api.index import GraphRagIndexer


indexer = GraphRagIndexer(root="rag", init=True)

indexer.run()

索引创建

  1. 命令行初始化(会生成rag目录)
python -m graphrag.index --root rag  # graphrag初始化
python index_test.py --root rag  # graphrag_api初始化
  1. 代码初始化
from graphrag_api.index import GraphRagIndexer


indexer = GraphRagIndexer(root="rag")

indexer.run()
  1. 修改配置文件(自动生成,需要修改相应配置)

.env文件

GRAPHRAG_API_KEY=<API_KEY>

settings.yaml文件

encoding_model: cl100k_base
skip_workflows: []
llm:
  api_key: ${GRAPHRAG_API_KEY}
  type: openai_chat # or azure_openai_chat
  model: gpt-4o-mini  # mini性价比比较高
  model_supports_json: true # recommended if this is available for your model.

embeddings:
  ## parallelization: override the global parallelization settings for embeddings
  async_mode: threaded # or asyncio
  llm:
    api_key: ${GRAPHRAG_API_KEY}
    type: openai_embedding # or azure_openai_embedding
    model: text-embedding-3-small
    
input:
  type: file # or blob
  file_type: csv # or text  这里以csv为例
  base_dir: "input"
  file_encoding: utf-8
  file_pattern: ".*\\.csv$"
  source_column: "question"  # csv-key
  text_column: "answer"  # csv-key

q.csv文件示例

question,answer
"你是谁","你猜啊"

搜索

  1. 命令行初始化
python -m graphrag.query \
--root ./ragtest \
--method global(local) \
"What are the top themes in this story?"  # graphrag初始化

python search_test.py --root rag --method global(local) "What are the top themes in this story?"  # graphrag初始化

2代码初始化

from graphrag_api.search import SearchRunner

search_runner = SearchRunner(root_dir="rag")

search_runner.run_local_search(query="What are the top themes in this story?", streaming=False)
search_runner.run_global_search(query="What are the top themes in this story?", streaming=False)

# 对于输出的结果可能带有一些特殊字符,可以采用以下函数去除特殊字符或自行处理。
search_runner.remove_sources(search_runner.run_local_search(query="What are the top themes in this story?")[0])

报告问题

如果遇到任何问题,请在 GitHub 上提交 issue。

许可证

此项目依据 MIT 许可证授权。有关详细信息,请参阅 LICENSE 文件。

致谢

此项目基于 GraphRag 库。特别感谢原项目的贡献者。


如果有任何需要进一步调整的地方,请告诉我!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphrag_api-0.3.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphrag_api-0.3.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file graphrag_api-0.3.2.tar.gz.

File metadata

  • Download URL: graphrag_api-0.3.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for graphrag_api-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6e35365d8d96b4970fe4bfeebbf33b88918d383b2d7a1c29b6e8e9502cfad6b6
MD5 e8a3d785f149a5d6d3e21c875f915533
BLAKE2b-256 2f62ffd79400f47c58b8f35ab3609a48cbcfbe3dde35ede96aa0c5d2d1edbc70

See more details on using hashes here.

File details

Details for the file graphrag_api-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: graphrag_api-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for graphrag_api-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17c2706370978b2cb21c69a419c179d55ecda263274b623f06dd0ec4574b4ee9
MD5 ef461bf7f1ebef3c7eaa3dd284137717
BLAKE2b-256 22fd5f0b39edf13a6cbbdaf8f733fe5f33788767859df648e72609d7e6aaea4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page