基于GraphRAG+Ollama驗證知識圖譜和檢索增強融合

之前介紹了知識圖譜與檢索增強的融合探索GraphRAG。

https://blog.csdn.net/liliang199/article/details/151189579

這里嘗試在CPU環境,基于GraphRAG+Ollama,驗證GraphRAG構建知識圖譜和檢索增強查詢過程。

1 環境安裝

1.1 GraphRAG安裝

在本地cpu環境,基于linux conda安裝python,pip安裝graphrag,過程如下。

conda create -n graphrag python=3.10

conda activate graphrag

pip install graphrag==0.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

安裝graphrag 0.5.0(之后版本可能和ollama有兼容問題)

1.2 Ollama LLM安裝

假設ollama已安裝,具體安裝過程參考

https://blog.csdn.net/liliang199/article/details/149267372

這里ollama下載llm模型mistral和embedding模型nomic-embed-text

ollama pull nomic-embed-text

ollama pull mistral

默認ollama模型上下文長度為2048,不能有效支持GraphRAG,需要對上下文長度進行修改。

導出現有llm模型配置,配置文件為Modelfile

ollama show --modelfile mistral:latest > Modelfile?

修改Modelfile,在PARAMETER區域添加如下配置,支持10k上下文,可依據具體情況設定。

PARAMETER num_ctx 10000

修改后示例如下

基于修改后的Modelfile,創建新的ollama模型,指令如下。

ollama create mistral:10k -f Modelfile

查看新創建模型

ollama list

2 GraphRAG圖譜構建驗證

2.1 測試數據準備

首先創建工作目錄

mkdir ragtest/input -p

輸入為如下小1000行的文本,獲取命令如下。

https://www.gutenberg.org/cache/epub/7785/pg7785.txt

wget https://www.gutenberg.org/cache/epub/7785/pg7785.txt -O ragtest/input/Transformers_intro.txt

此時,./ragtest包含測試數據,初始化指令如下。

graphrag init --root ./ragtest

生成參數配置文件ragtest/settings.yaml

2.2 環境變量設置

設置GRAPHRAG_API_KEY和GRAPHRAG_CLAIM_EXTRACTION_ENABLED

export GRAPHRAG_API_KEY=ollama
export GRAPHRAG_CLAIM_EXTRACTION_ENABLED=True

設置參數GRAPHRAG_CLAIM_EXTRACTION_ENABLED=True,否則無法生成協變量,Local Search出錯。

2.3 模型參數配置

模型參數配置文件ragtest/settings.yaml

修改llm model為mistral:10k,embedding model為nomic-embed-text

調用本地ollama llm服務,所以設置api_base: http://localhost:11434/v1

本地cpu部署,計算很慢,所以設置一個很長的request_timeout: 18000

沒有GPU,過大concurrent_requests沒效果,反而導致超時,設置concurrent_requests: 1

### This config file contains required core defaults that must be set, along with a handful of common optional settings.
### For a full list of available settings, see https://microsoft.github.io/graphrag/config/yaml/

### LLM settings ###
## There are a number of settings to tune the threading and token limits for LLM calls - check the docs.

encoding_model: cl100k_base # this needs to be matched to your model!

llm:
? api_key: ${GRAPHRAG_API_KEY} # set this in the generated .env file
? type: openai_chat # or azure_openai_chat
? model: mistral:10k

? api_base: http://localhost:11434/v1

? request_timeout: 18000

??concurrent_requests: 1
? model_supports_json: true # recommended if this is available for your model.
? # audience: "https://cognitiveservices.azure.com/.default"
? # api_base: https://<instance>.openai.azure.com
? # api_version: 2024-02-15-preview
? # organization: <organization_id>
? # deployment_name: <azure_model_deployment_name>

parallelization:
? stagger: 0.3
? # num_threads: 50

async_mode: threaded # or asyncio

embeddings:
? async_mode: threaded # or asyncio
? vector_store:
? ? type: lancedb
? ? db_uri: 'output/lancedb'
? ? container_name: default
? ? overwrite: true
? llm:
? ? api_key: ${GRAPHRAG_API_KEY}
? ? type: openai_embedding # or azure_openai_embedding
? ? model: nomic-embed-text
? ? api_base: http://localhost:11434/v1

? ? request_timeout: 18000

? ??concurrent_requests: 1
? ? # api_base: https://<instance>.openai.azure.com
? ? # api_version: 2024-02-15-preview
? ? # audience: "https://cognitiveservices.azure.com/.default"
? ? # organization: <organization_id>
? ? # deployment_name: <azure_model_deployment_name>

### Input settings ###

input:
? type: file # or blob
? file_type: text # or csv
? base_dir: "input"
? file_encoding: utf-8
? file_pattern: ".*\\.txt$"

chunks:
? size: 1200
? overlap: 100
? group_by_columns: [id]

### Storage settings ###
## If blob storage is specified in the following four sections,
## connection_string and container_name must be provided

cache:
? type: file # or blob
? base_dir: "cache"

reporting:
? type: file # or console, blob
? base_dir: "logs"

storage:
? type: file # or blob
? base_dir: "output"

## only turn this on if running `graphrag index` with custom settings
## we normally use `graphrag update` with the defaults
update_index_storage:
? # type: file # or blob
? # base_dir: "update_output"

### Workflow settings ###

skip_workflows: []

entity_extraction:
? prompt: "prompts/entity_extraction.txt"
? entity_types: [organization,person,geo,event]
? max_gleanings: 1

summarize_descriptions:
? prompt: "prompts/summarize_descriptions.txt"
? max_length: 500

claim_extraction:
? enabled: false
? prompt: "prompts/claim_extraction.txt"
? description: "Any claims or facts that could be relevant to information discovery."
? max_gleanings: 1

community_reports:
? prompt: "prompts/community_report.txt"
? max_length: 2000
? max_input_length: 8000

cluster_graph:
? max_cluster_size: 10

embed_graph:
? enabled: false # if true, will generate node2vec embeddings for nodes

umap:
? enabled: false # if true, will generate UMAP embeddings for nodes

snapshots:
? graphml: false
? raw_entities: false
? top_level_nodes: false
? embeddings: false
? transient: false

### Query settings ###
## The prompt locations are required here, but each search method has a number of optional knobs that can be tuned.
## See the config docs: https://microsoft.github.io/graphrag/config/yaml/#query

local_search:
? prompt: "prompts/local_search_system_prompt.txt"

global_search:
? map_prompt: "prompts/global_search_map_system_prompt.txt"
? reduce_prompt: "prompts/global_search_reduce_system_prompt.txt"
? knowledge_prompt: "prompts/global_search_knowledge_system_prompt.txt"

drift_search:
? prompt: "prompts/drift_search_system_prompt.txt"

2.4?數據索引構建

然后就是構建索引,這里需要設置--reporter "rich",不設置會報錯。

nohup graphrag index --root ./ragtest --reporter "rich" > run.log &

本地CPU運行ollama其實不太有效,耗時太長,導致各種奇怪超時和報錯,所以最好有GPU。

另外,雖然可以調用外部LLM服務,但GraphRAG索引會消耗大量tokens,這需要不差錢。

附錄

問題1:?Invalid value for '--reporter'

Invalid value for '--reporter' (env var: 'None'): <ReporterType.RICH: 'rich'> is not one of 'rich', 'print', 'none'. ? ? ? ? ? ? ? ? ? ? ? ? ? │

補全輸出參數"none"/"print"/"rich",比如?--reporter "rich"

reference

---

GraphRAG

https://github.com/msolhab/graphrag

Project Gutenberg

https://www.gutenberg.org/

Global Search Notebook

https://microsoft.github.io/graphrag/examples_notebooks/global_search/

GraphRAG-知識圖譜與檢索增強的融合探索

https://blog.csdn.net/liliang199/article/details/151189579

GraphTest - 直接使用阿里API,總體費用相對可控。

https://github.com/NanGePlus/GraphragTest

GraphRAG(最新版)+Ollama本地部署,以及中英文示例

https://juejin.cn/post/7439046849883226146

傻瓜操作:GraphRAG、Ollama 本地部署及踩坑記錄

https://blog.csdn.net/weixin_42107217/article/details/141649920

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/96148.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/96148.shtml
英文地址,請注明出處:http://en.pswp.cn/web/96148.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

36頁可編輯PPT | 某制造集團燈塔工廠解決方案

制造業企業訂單種類多&#xff0c;傳統產線換型慢&#xff0c;庫存高&#xff0c;財務壓力大。工人年齡大&#xff0c;招工難&#xff0c;工資漲&#xff0c;效率低。海外對手用低價和柔性產線搶單&#xff0c;國內同行用數字化縮短交期。企業想擴產&#xff0c;又怕投資重、回…

Redis 非緩存核心場景及實例說明

Redis 非緩存核心場景及實例說明 一、分布式鎖 分布式鎖用于解決分布式系統中多節點競爭同一資源的問題&#xff0c;確保操作原子性。Redis 實現分布式鎖的核心思路是利用鍵的唯一性和原子命令&#xff0c;通常基于 Redisson 框架簡化實現&#xff08;底層依賴 Redis 命令&…

【技術教程】如何將ONLYOFFICE文檔集成到使用Spring Boot框架編寫的Java Web應用程序中

在現代協作辦公環境中&#xff0c;將功能強大的文檔編輯器無縫集成到自有業務系統中&#xff0c;已成為提升工作效率和用戶體驗的關鍵需求。ONLYOFFICE 文檔服務器提供了一套成熟的在線文檔編輯解決方案&#xff0c;而 Java Spring Boot 則是構建高效、模塊化 Web 應用的熱門框…

openharmony之AV_CodeC音視頻編解碼模塊詳解(二)

1. 音頻解碼器函數調用流程 1.1 音頻解碼器架構概覽 decoder:解碼器 encoder:編碼器 前面文章介紹了關于openHarmony的AV_CodeC模塊,這篇文章將詳細講解編解碼時函數的調用流程 音頻解碼器采用插件化架構,核心實現位于: services/engine/codec/audio/decoder/audio_ffmpeg…

PDF24 Creator:免費的多功能PDF工具

在處理PDF文件時&#xff0c;一個功能強大且免費的PDF工具是許多用戶的首選。PDF24 Creator作為一款免費的PDF工具&#xff0c;提供了豐富的功能&#xff0c;幫助用戶創建、編輯和轉換PDF文件&#xff0c;滿足從初學者到專業用戶的各種需求。它不僅支持PDF與Word、Excel等15種以…

VBA 中使用 ADODB 操作 SQLite 插入中文亂碼問題

問題 使用 VBA 的 ADODB 對象的 command 對象、parameter 對象&#xff0c;插入的中文數據為亂碼 驅動下載、安裝、引用 驅動網址(下載路徑) 使用的 ODBC 驅動&#xff08;需要梯子才能下載&#xff0c;感謝大佬開源&#xff09; http://www.ch-werner.de/sqliteodbc/ 版本…

執行select * from a where rownum<1;,數據庫子進程崩潰,業務中斷。

文章目錄環境癥狀觸發條件解決方案環境 系統平臺&#xff1a;Linux x86-64 Red Hat Enterprise Linux 7 版本&#xff1a;4.5.2 癥狀 執行select * from a where rownum<1;&#xff0c;數據庫子進程崩潰&#xff0c;業務中斷。 觸發條件 select 和 where條件帶有rownum…

python庫 Py2app 的詳細使用(將 Python 腳本變為 MacOS 獨立軟件包)

更多內容請見: python3案例和總結-專欄介紹和目錄 文章目錄 一、Py2app 概述 1.1 Py2app 介紹 1.2 安裝 1.3 替代工具推薦 二、基礎使用 2.1 最簡單的 setup.py 文件 2.2 完整示例 2.3 配置選項詳解 2.4 完整項目案例 2.5 打包為單文件應用(可選) 三、高級配置 3.1 處理特定…

NTP配置為客戶端廣播監聽模式

前言 項目需求&#xff1a; 使能ntp為客戶端模式&#xff0c;能監服務端廣播模式發出的ntp報文&#xff0c;計算出服務端的時間與客戶端的時間偏差并上報。 開發狀況&#xff1a; 交叉編譯ntp源碼&#xff0c;將修改后的ntpd進程部署到設備上作為客戶端完成項目需求 如何操作&a…

Claude-Flow 使用指南

Claude-Flow 不僅僅是一個工具&#xff0c;更是一個強大的AI驅動開發編排平臺。本問初步帶您深入了解 Claude-Flow v2.0.0 Alpha 的強大功能&#xff0c;助您在AI開發領域如虎添翼。1. 簡介&#xff1a;什么是 Claude-Flow&#xff1f; Claude-Flow v2 Alpha 是一個企業級的AI編…

系統梳理 Test-Time Compute 的主要實現路徑

編者按&#xff1a; AI 真的在“思考”嗎&#xff1f;當模型面對數學推理、代碼生成或復雜決策時&#xff0c;它是如何一步步推演出答案的&#xff1f;如果你曾困惑于大模型在關鍵任務中表現不穩定、缺乏可解釋性&#xff0c;甚至生成結果難以驗證&#xff0c;那么你并不孤單。…

vue 經常寫的echarts圖表模塊結構抽取

vue 經常寫的echarts圖表模塊結構抽取將項目中經常寫的結構抽取一下, 方便以后用 表頭包含標題和右側操作部分下面為圖表 <div class"chartBox"><div class"chartheadbox"><div class"chartheadleft">這是圖表標題</div>…

主流的開源協議(MIT,Apache,GPL v2/v3)

文章目錄1. MIT 協議 (MIT License)2. Apache 2.0 協議 (Apache License 2.0)3. GPL v2 協議 (GNU General Public License v2)“開源協議選擇指南”的流程圖 flowchart TDA[開始選擇開源協議] --> B{是否要求修改后必須開源?<br>(是否具有 傳染性?)};B -- 是&…

CameraService筆記

cameraservicecamera 結構圖1. 啟動CameraServer1.1 注冊media.camera服務1.2 構造CameraService1.3 CameraService::onFirstRef1.4 CameraService::enumerateProviders&#xff1a;前置準備知識1.4 CameraService::enumerateProviders&#xff1a;Provider和Device初始化1.4.1…

MacOS 15.6 編譯SDL3 Android平臺多架構so庫

成功編譯輸出: 編譯: Android平臺多架構編譯腳本: sdl3_android_build.sh #!/bin/bash# 設置變量 macos 其他系統需要更改路徑 SDL_SOURCE_DIR=$(pwd)/SDL BUILD_DIR=${SDL_SOURCE_DIR}/../sdl3_build_android NDK_PATH=$HOME/Library/Android/Sdk/Ndk/25.2.9519653 CMAKE…

Real-IAD D3: A Real-World 2D/Pseudo-3D/3D Dataset for Industrial Anomaly

Real-IAD D: A Real-World 2D/Pseudo-3D/3D Dataset for Industrial Anomaly Detection Paper Github 摘要 隨著工業異常檢測&#xff08;Industrial Anomaly Detection, IAD&#xff09;復雜程度的不斷提升&#xff0c;多模態檢測方法已成為機器視覺領域的研究焦點。然而&a…

IT需求提示未讀信息查詢:深度技術解析與性能優化指南【類似:釘釘已讀 功能】

IT需求提示未讀信息查詢&#xff1a;深度技術解析與性能優化指南【類似&#xff1a;釘釘已讀 功能】 DROP TABLE IF EXISTS rs_kpi_it_need_tip; CREATE TABLE IF NOT EXISTS rs_kpi_it_need_tip (id bigint NOT NULL AUTO_INCREMENT COMMENT 主鍵ID&#xff…

Django中的軟刪除

軟刪除&#xff08;Soft Delete&#xff09;是一種數據刪除策略&#xff0c;它并不真正從數據庫中刪除記錄&#xff0c;而是通過標記&#xff08;如 is_deleted 字段&#xff09;來表示記錄已被刪除。 這樣做的好處是可以保留數據歷史&#xff0c;支持數據恢復和審計。 在 Djan…

JavaEE 進階第四期:開啟前端入門之旅(四)

專欄&#xff1a;JavaEE 進階躍遷營 個人主頁&#xff1a;手握風云 目錄 一、常用CSS 1.1. border 1.2. width/height 1.3. padding&#xff1a;內邊距 1.4. margin&#xff1a;外邊距 二、初始JavaScript 2.1. JavaScript是什么 2.2. 發展歷史 2.3. JavaScript 和 HT…

學習日記-SpringMVC-day49-9.4

知識點&#xff1a;1.RequestMapping&#xff08;3&#xff09;知識點核心內容重點RequestMapping注解的parameters屬性通過parameters指定請求參數條件&#xff08;如bookID&#xff09;&#xff0c;控制請求匹配規則&#xff08;必須包含/排除特定參數或值&#xff09;參數存…