当前位置: 首页 > news >正文

【大模型理解消化的搅碎机】基于6000种商品CSV表格的知识图谱构建

1. graphRAG前菜:

Graph RAG 即图增强检索生成(Graph - Augmented Retrieval Augmented Generation),它是在检索增强生成(RAG)基础上结合图数据库的一种技术。

1.2 检索增强生成(RAG):

RAG 是一种将外部知识源与大语言模型(LLM)相结合的技术。传统的大语言模型依赖于预训练时学到的知识,可能存在知识过时或不完整的问题。RAG 通过在生成回答之前,先从外部知识源(如文档数据库)中检索相关信息,然后将这些信息与用户的问题一起输入到语言模型中,从而生成更准确、更具时效性的回答。

1.3 图增强检索生成(Graph RAG):

Graph RAG 在 RAG 的基础上引入了图数据库。图数据库以图的结构来存储数据,包含节点(代表实体)和边(代表实体之间的关系),能够更自然地表示复杂的关系数据。Graph RAG 利用图数据库的特性,更好地挖掘和利用数据之间的关系,为大语言模型提供更丰富、更具关联性的上下文信息。

2. 工具与所需文档

  1. neo4j 和 数据库表格文档

3. 代码:

from py2neo import Node, Relationship, Graph, NodeMatcher, RelationshipMatcher
import webbrowser
import csv
def read_csv_line_by_line(file_path):res = []with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:reader = csv.reader(csvfile)for i, row in enumerate(reader):if i != 0:special = ['```json\n', '```']for _ in special:if _ in row[1]:row[1] = row[1].replace(_, "")res.append(eval(row[1]))return resres = read_csv_line_by_line('/www/reconstruction_res.csv')graph = Graph('http://localhost:7474/', user='test', password="****************", name='product-details')
for i, product in enumerate(res):product_name, product_features, product_details, product_strengths, product_fit_person = "", [], [], [], []if '商品名称' in product.keys():product_name = product['商品名称']if '商品特征' in product.keys():product_features = product['商品特征'].split(",")if '商品注意详情' in product.keys():product_details = product['商品注意详情'].split(",")if '商品优势' in product.keys():product_strengths = product['商品优势'].split(",")if '适合人群' in product.keys():product_fit_person = product['适合人群'].split(",")if product_name != "":product = Node('商品名称', name=product_name)graph.create(product)if product_features != []:for _ in product_features:feature = Node('商品特征', name=_)graph.create(feature)relationship = Relationship(product, "特征", feature)graph.create(relationship)if product_details != []:for _ in product_details:details = Node('商品注意详情', name=_)graph.create(details)relationship = Relationship(product, "商品详情", details)graph.create(relationship)if product_strengths != []:for _ in product_strengths:strengths = Node('商品优势', name=_)graph.create(strengths)relationship = Relationship(product, "优点", strengths)graph.create(relationship)if product_fit_person != []:for _ in product_fit_person:fit_person = Node('商品优势', name=_)graph.create(fit_person)relationship = Relationship(product, "面向人群", fit_person)graph.create(relationship)
matcher = NodeMatcher(graph)
match1 = matcher.match("商品名称") # 查询结点
for _ in match1:print(_)

4. 结果展示

在这里插入图片描述
在这里插入图片描述

http://www.xdnf.cn/news/146269.html

相关文章:

  • 计组1.2.4——计算机系统的层次结构
  • Allegro23.1新功能之OrcadX平台使用操作指导
  • (三) Trae 调试C++ 基本概念
  • 【虚拟机安装Ubuntu 24 LTS】 MobaXterm 连接Access denied错误-安装进度卡“正在传输文件”-固定内网ip
  • 反爬虫机制中的验证码识别:类型、技术难点与应对策略
  • 艾德文·卡特姆:将画布变成屏幕,开启CGI时代
  • ‌CDGP|企业数据安全治理:制定落地战略,护航数字经济高质量发展
  • 求职意向商务/BD简历模板
  • DPIN河内AI+DePIN峰会:共绘蓝图,加速构建去中心化AI基础设施新生态
  • 算法中的数学:gcd与lcm
  • 诗词大会竞赛主持稿串词(二)
  • CKESC SKY 6S 50A_4S 60A 电调专业测评
  • 常见网络安全攻击类型深度剖析(一):恶意软件攻击——病毒、蠕虫、木马的原理与防范
  • 51单片机中断
  • 【补题】Codeforces Round 789 (Div. 1)C. Tokitsukaze and Two Colorful Tapes
  • 智慧党建解决方案-1PPT(40页)
  • ThreadLocal详解与实战指南
  • LabVIEW老旧设备控制
  • Apache Spark 源码解析
  • 线程池配置实现多线程快速处理批量数据
  • 动态ip与静态ip的概念、区别、应用场景
  • 统计文件中单词出现的次数并累计
  • 【玩泰山派】7、玩linux桌面环境xfce - (4)使用gstreamer
  • 点云从入门到精通技术详解100篇-基于二次误差和高斯混合模型的点云配准算法
  • 【DE-III】基于细节增强的模态内和模态间交互的视听情感识别
  • LabVIEW轨道交通动力系统性能监控
  • Spring 与 ActiveMQ 的深度集成实践(一)
  • 佳博票据和标签打印:Web网页端与打印机通信 | iOS
  • freecad参数化三维模型装配体解析至web端,切换参数组或修改参数
  • 【维护窗口内最值+单调队列/优先队列】Leetcode 239. 滑动窗口最大值