GraphRag-API
0.3.x 版本以后graphrag官方有好几个bug,提了pr之后一直没人审核。只能等官方bug解决了。
不建议升级!!!
新版本不止是bug!!
GraphRag-API 在 GraphRag 库的基础上扩展,提供了 API 调用功能,用于执行本地和全局搜索。此扩展允许用户通过 RESTful API 调用,轻松地将 GraphRag 的强大搜索功能集成到他们的应用程序中。
功能
- 本地搜索:在指定的本地数据集内进行搜索。
- 全局搜索:在更广泛的全球数据集中进行搜索。
- 可配置参数:通过配置文件或 API 调用自定义搜索参数。
- RESTful API:通过 HTTP 请求轻松与其他应用程序和服务集成。
安装
先决条件
确保已安装 Python 3.8+。
通过 pip 安装
使用 pip 安装 GraphRag-API:
pip install graphrag_api
从源码安装
- 克隆源码库:
git clone https://github.com/nightzjp/graphrag_api
- 进入项目目录并安装依赖:
cd graphrag_api
pip install -r requirements.txt
使用
初始化
- 命令行初始化
graphrag 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()
索引创建
- 命令行初始化(会生成rag目录)
graphrag index --root ./rag # graphrag初始化
python index_test.py --root rag # graphrag_api初始化
- 代码初始化
from graphrag_api.index import GraphRagIndexer
indexer = GraphRagIndexer(root="rag")
indexer.run()
- 修改配置文件(自动生成,需要修改相应配置)
.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
"你是谁","你猜啊"
搜索
- 命令行初始化
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 库。特别感谢原项目的贡献者。
如果有任何需要进一步调整的地方,请告诉我!
Metadata
Release files for graphrag-api 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphrag_api-1.0.1.tar.gz | 13.3 kB | Without provenance | Details for graphrag_api-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphrag_api-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for graphrag_api-1.0.1-py3-none-any.whl |
Total release size: 25.8 kB
Release files / graphrag_api-1.0.1.tar.gz
| Download URL | graphrag_api-1.0.1.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b0c7eb611285a3b9beb867aa2e60f1a6f82d18a9b98de8c7d8a5fd917a1f857
|
|
BLAKE2b-256 checksum How to use checksums |
bf1f262ac5829630ae44109afac05cfb75437a324e1ca7257f1af0d213b32959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Release files / graphrag_api-1.0.1-py3-none-any.whl
| Download URL | graphrag_api-1.0.1-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db60446bc9103375aaaf5ee2bdc10fd6848cff8b66c3b00faf4c8c694f4f8f64
|
|
BLAKE2b-256 checksum How to use checksums |
f310fe79ceaa14118d6536697611a73ba4065f2ad319a61f0e36547e2066b941
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Security for graphrag-api 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.