南宁网站 制作,ui网站建设站评价,西安米德建站,网页制作素材下载免费Neo4j 是开源的 Graph 数据库#xff0c;Graph 数据通过三元组进行表示#xff0c;两个顶点一条边#xff0c;从语意上可以理解为#xff1a;主语、谓语和宾语。GraphDB 能够通过图来表达复杂的结构#xff0c;非常适合存储知识型数据#xff0c;本文将通过大语言实现图数…Neo4j 是开源的 Graph 数据库Graph 数据通过三元组进行表示两个顶点一条边从语意上可以理解为主语、谓语和宾语。GraphDB 能够通过图来表达复杂的结构非常适合存储知识型数据本文将通过大语言实现图数据库的创建。
首先需要安装 LangChain 对应的依赖。
langchain0.3.7
python-dotenv1.0.1
langchain-google-genai2.0.4
langserve0.3.0
langchain-community0.3.5
dashscope1.20.12
langgraph0.2.45
tavily-python0.5.0
langchain-experimental0.3.3初始化模型
本文我们使用 Qwen-Turbo。
from langchain_community.chat_models import ChatTongyi
llm ChatTongyi(modelqwen-turbo)使用 LLMGraphTransformer 创建
创建的图关系为英文这是因为 Langchain 提示词是英文可以自行修改。
### 创建 Graph
from langchain_core.documents import Document
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_core.output_parsers import StrOutputParser
from IPython.display import Markdown, display
parser StrOutputParser()llm_transformer LLMGraphTransformer(llmllm)content
1 、项目编号遂政采 [2024]G 049 号
2 、项目名称无人机设备采购项目
3 、项目预算 1550967.00元 4 、最高限价 1550967.00元1 、本项目投标截止时间和开标时间为 2024 年 9 月 11 日 10 点 00 分 北京
时间。投标人必须在投标截止时间前将电子投标文件上传至江西省公共资源
交易网逾期为无效投标。
2 、开标地点江西省公共资源交易网不见面开标大厅。with open(out.md, r, encodingutf-8) as file:markdown_content file.read()chain llm | parser
# display(Markdown(chain.invoke(转换为 Graph 三元组 请用中文回答并只返回 Cypher QL 。 {} content)))documents [Document(page_contentcontent)]
graph_documents llm_transformer.convert_to_graph_documents(documents)
print(fNodes:{graph_documents[0].nodes})
print(fRelationships:{graph_documents[0].relationships})
graph.add_graph_documents(graph_documents, include_sourceFalse) 使用 Cypher 创建
Neo4j 提供了使用 Cypher 进行数据创建、查询等类似于关系数据库中的 SQL。用模型生成 Cypher 语句。
### 创建 Graph
from langchain_core.documents import Document
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_core.output_parsers import StrOutputParser
from IPython.display import Markdown, display
parser StrOutputParser()llm_transformer LLMGraphTransformer(llmllm)content
1 、项目编号遂政采 [2024]G 049 号
2 、项目名称无人机设备采购项目
3 、项目预算 1550967.00元 4 、最高限价 1550967.00元1 、本项目投标截止时间和开标时间为 2024 年 9 月 11 日 10 点 00 分 北京
时间。投标人必须在投标截止时间前将电子投标文件上传至江西省公共资源
交易网逾期为无效投标。
2 、开标地点江西省公共资源交易网不见面开标大厅。with open(out.md, r, encodingutf-8) as file:markdown_content file.read()chain llm | parser
display(Markdown(chain.invoke(转换为 Graph 三元组 请用中文回答并只返回 Cypher QL 。 {} content))) 总结
本文介绍了如何使用大语言模型创建图数据同样的方式也可以创建其他类型的数据源只需要对提示词进行修改即可。 文章转载自: http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn http://www.morning.kybjr.cn.gov.cn.kybjr.cn http://www.morning.bkqdg.cn.gov.cn.bkqdg.cn http://www.morning.jqrp.cn.gov.cn.jqrp.cn http://www.morning.pmjhm.cn.gov.cn.pmjhm.cn http://www.morning.nfbxgtj.com.gov.cn.nfbxgtj.com http://www.morning.sfswj.cn.gov.cn.sfswj.cn http://www.morning.mjbnp.cn.gov.cn.mjbnp.cn http://www.morning.bcngs.cn.gov.cn.bcngs.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.bpmdr.cn.gov.cn.bpmdr.cn http://www.morning.rycbz.cn.gov.cn.rycbz.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.pthmn.cn.gov.cn.pthmn.cn http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn http://www.morning.spfq.cn.gov.cn.spfq.cn http://www.morning.lekbiao.com.gov.cn.lekbiao.com http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.yhwxn.cn.gov.cn.yhwxn.cn http://www.morning.mnyzz.cn.gov.cn.mnyzz.cn http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.nfccq.cn.gov.cn.nfccq.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.swwpl.cn.gov.cn.swwpl.cn http://www.morning.dpqwq.cn.gov.cn.dpqwq.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn http://www.morning.rkgyx.cn.gov.cn.rkgyx.cn http://www.morning.mnccq.cn.gov.cn.mnccq.cn http://www.morning.xnpj.cn.gov.cn.xnpj.cn http://www.morning.hrzymy.com.gov.cn.hrzymy.com http://www.morning.dxqfh.cn.gov.cn.dxqfh.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn http://www.morning.fdmfn.cn.gov.cn.fdmfn.cn http://www.morning.qhqgk.cn.gov.cn.qhqgk.cn http://www.morning.spxsm.cn.gov.cn.spxsm.cn http://www.morning.hwbf.cn.gov.cn.hwbf.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn http://www.morning.tyklz.cn.gov.cn.tyklz.cn http://www.morning.mrxgm.cn.gov.cn.mrxgm.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.dkfb.cn.gov.cn.dkfb.cn http://www.morning.fnfxp.cn.gov.cn.fnfxp.cn http://www.morning.rxdsq.cn.gov.cn.rxdsq.cn http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn http://www.morning.yodajy.cn.gov.cn.yodajy.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn http://www.morning.rcntx.cn.gov.cn.rcntx.cn http://www.morning.benqc.com.gov.cn.benqc.com http://www.morning.nqnqz.cn.gov.cn.nqnqz.cn http://www.morning.wjrq.cn.gov.cn.wjrq.cn http://www.morning.rtqyy.cn.gov.cn.rtqyy.cn http://www.morning.qpsft.cn.gov.cn.qpsft.cn http://www.morning.wmrgp.cn.gov.cn.wmrgp.cn http://www.morning.jngdh.cn.gov.cn.jngdh.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.wkxsy.cn.gov.cn.wkxsy.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.hpxxq.cn.gov.cn.hpxxq.cn http://www.morning.nwfxp.cn.gov.cn.nwfxp.cn http://www.morning.srbfz.cn.gov.cn.srbfz.cn http://www.morning.rcjyc.cn.gov.cn.rcjyc.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.sbyhj.cn.gov.cn.sbyhj.cn http://www.morning.sxmbk.cn.gov.cn.sxmbk.cn http://www.morning.sjsks.cn.gov.cn.sjsks.cn http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn