main
HuangHai 2 weeks ago
parent b932e6fafa
commit 53411abcc2

@ -1,12 +1,12 @@
# 大模型 【DeepSeek深度求索官方】
#LLM_API_KEY = "sk-44ae895eeb614aa1a9c6460579e322f1"
#LLM_BASE_URL = "https://api.deepseek.com"
#LLM_MODEL_NAME = "deepseek-chat"
# LLM_API_KEY = "sk-44ae895eeb614aa1a9c6460579e322f1"
# LLM_BASE_URL = "https://api.deepseek.com"
# LLM_MODEL_NAME = "deepseek-chat"
# 阿里云提供的大模型服务
LLM_API_KEY="sk-f6da0c787eff4b0389e4ad03a35a911f"
LLM_API_KEY = "sk-f6da0c787eff4b0389e4ad03a35a911f"
LLM_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
#LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确!
# LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确!
LLM_MODEL_NAME = "deepseek-v3"
EMBED_MODEL_NAME = "BAAI/bge-m3"
@ -15,7 +15,7 @@ EMBED_BASE_URL = "https://api.siliconflow.cn/v1"
EMBED_DIM = 1024
EMBED_MAX_TOKEN_SIZE = 8192
NEO4J_URI = "bolt://localhost:7687"
NEO4J_USERNAME = "neo4j"
NEO4J_PASSWORD = "DsideaL147258369"
NEO4J_PASSWORD = "DsideaL147258369"
NEO4J_AUTH = (NEO4J_USERNAME, NEO4J_PASSWORD)

@ -5,6 +5,8 @@ from Util.DocxUtil import get_docx_content_by_pandoc
from Util.LightRagUtil import configure_logging, initialize_rag
import os
from Util.Neo4jExecutor import Neo4jExecutor
# 数学
KEMU = 'Chemistry' # Chinese,Math,Chemistry
@ -18,6 +20,11 @@ async def main():
os.environ["NEO4J_USERNAME"] = NEO4J_USERNAME
os.environ["NEO4J_PASSWORD"] = NEO4J_PASSWORD
# 清库
executor = Neo4jExecutor.create_default()
executor.graph.run("MATCH (n) DETACH DELETE n")
print("清库成功")
# 注释掉或删除以下清理代码
files_to_delete = [
"graph_chunk_entity_relation.graphml",

@ -1,12 +0,0 @@
{
"doc-38dc4759f21281aec253bbbfd5249836": {
"status": "processed",
"chunks_count": 1,
"content": "硝酸光照分解的方程式\n$$4HNO_{3}overset{overset{}{{Delta}}}{=}4NO_{2} uparrow + O_{2} uparrow + 2HO_{2}$$\n氧化铁与硝酸的加热反应方程式\n$$FeO + 4HNO_{3}overset{overset{}{{Delta}}}{=}Fe(NO_{3})_{3} + 2H_{2} uparrow + NO_{2} uparrow$$\n氢气与氧气燃烧的现象如下图所示\n$$2H_{2} + O_{2}overset{overset{}{text{燃烧}}}{=}2H_{2}O$$\n![](./Images/4826f1dfc6ce4ba5a294167a016b736f/media/image1.png)",
"content_summary": "硝酸光照分解的方程式\n$$4HNO_{3}overset{overset{}{{Delta}}}{=}4NO_{2} uparrow + O_{2} uparrow + 2HO_{2}$$\n氧化铁与硝酸的加热反应方程式\n$$FeO + 4HNO_{3}overset{overset{}{{Delta}}}{=}Fe(NO_{3})_{3} + 2H_{2} uparrow + NO_{2} uparrow$$\n氢气与氧气燃烧的现象如下图所示\n$$2H_{2} + O_{2}overset{ov...",
"content_length": 344,
"created_at": "2025-07-11T00:25:57.391796+00:00",
"updated_at": "2025-07-11T00:26:52.778188+00:00",
"file_path": "unknown_source"
}
}

@ -1,5 +0,0 @@
{
"doc-38dc4759f21281aec253bbbfd5249836": {
"content": "硝酸光照分解的方程式\n$$4HNO_{3}overset{overset{}{{Delta}}}{=}4NO_{2} uparrow + O_{2} uparrow + 2HO_{2}$$\n氧化铁与硝酸的加热反应方程式\n$$FeO + 4HNO_{3}overset{overset{}{{Delta}}}{=}Fe(NO_{3})_{3} + 2H_{2} uparrow + NO_{2} uparrow$$\n氢气与氧气燃烧的现象如下图所示\n$$2H_{2} + O_{2}overset{overset{}{text{燃烧}}}{=}2H_{2}O$$\n![](./Images/4826f1dfc6ce4ba5a294167a016b736f/media/image1.png)"
}
}

@ -1,9 +0,0 @@
{
"chunk-38dc4759f21281aec253bbbfd5249836": {
"tokens": 198,
"content": "硝酸光照分解的方程式\n$$4HNO_{3}overset{overset{}{{Delta}}}{=}4NO_{2} uparrow + O_{2} uparrow + 2HO_{2}$$\n氧化铁与硝酸的加热反应方程式\n$$FeO + 4HNO_{3}overset{overset{}{{Delta}}}{=}Fe(NO_{3})_{3} + 2H_{2} uparrow + NO_{2} uparrow$$\n氢气与氧气燃烧的现象如下图所示\n$$2H_{2} + O_{2}overset{overset{}{text{燃烧}}}{=}2H_{2}O$$\n![](./Images/4826f1dfc6ce4ba5a294167a016b736f/media/image1.png)",
"chunk_order_index": 0,
"full_doc_id": "doc-38dc4759f21281aec253bbbfd5249836",
"file_path": "unknown_source"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,109 @@
import re
from typing import List, Tuple
from py2neo import Graph, Node, Relationship, Subgraph
from Config import Config
def clear(db):
# 清空数据
db.run("MATCH (n) DETACH DELETE n")
# 分步删除约束和索引
try:
# 删除约束
constraints = db.run("SHOW CONSTRAINTS YIELD name").data()
for constr in constraints:
db.run(f"DROP CONSTRAINT `{constr['name']}`")
# 删除索引
indexes = db.run("SHOW INDEXES YIELD name, type WHERE type <> 'LOOKUP'").data()
for idx in indexes:
db.run(f"DROP INDEX `{idx['name']}`")
except Exception as e:
print(f"删除操作失败: {e}")
def create_subgraph(db: Graph, nodes: List[Node], relations: List[Tuple[Node, str, Node]]) -> None:
"""统一创建子图"""
subgraph = Subgraph(
nodes=nodes,
relationships=[Relationship(start, rel_type, end) for start, rel_type, end in relations]
)
db.create(subgraph)
def tx_create(db: Graph, nodes: List[Node], relations: List[Tuple[Node, str, Node]]) -> None:
"""事务方式创建数据"""
try:
tx = db.begin()
subgraph = Subgraph(
nodes=nodes,
relationships=[Relationship(start, rel_type, end) for start, rel_type, end in relations]
)
tx.create(subgraph)
db.commit(tx)
except Exception as e:
db.rollback(tx)
print(f"事务操作失败: {str(e)}")
raise
class Neo4jExecutor:
# 添加类变量存储连接配置
NEO4J_URI = Config.NEO4J_URI
NEO4J_AUTH = Config.NEO4J_AUTH
def __init__(self, uri=None, auth=None):
# 使用默认配置或传入参数
self.graph = Graph(uri or self.NEO4J_URI,
auth=auth or self.NEO4J_AUTH)
@classmethod
def create_default(cls):
"""使用默认配置创建执行器"""
return cls(cls.NEO4J_URI, cls.NEO4J_AUTH)
# 新增文本执行方法
def execute_cypher_text(self, cypher_text: str) -> dict:
"""直接执行Cypher文本"""
stats = {'total': 0, 'success': 0, 'failed': 0}
try:
statements = re.split(r';\s*\n', cypher_text)
statements = [s.strip() for s in statements if s.strip()]
stats['total'] = len(statements)
for stmt in statements:
try:
self.graph.run(stmt)
stats['success'] += 1
except Exception as e:
stats['failed'] += 1
print(f"执行失败: {stmt[:50]}... \n错误: {str(e)[:100]}")
return stats
except Exception as e:
print(f"执行失败: {stmt[:100]}... \n完整错误: {str(e)}") # 原为str(e)[:100]
return stats
def execute_cypher_file(self, file_path: str) -> dict: # 确保方法名称正确
"""执行Cypher文件"""
stats = {'total': 0, 'success': 0, 'failed': 0}
try:
with open(file_path, 'r', encoding='utf-8') as f:
cypher_script = f.read()
statements = re.split(r';\s*\n', cypher_script)
statements = [s.strip() for s in statements if s.strip()]
stats['total'] = len(statements)
for stmt in statements:
try:
self.graph.run(stmt)
stats['success'] += 1
except Exception as e:
stats['failed'] += 1
print(f"执行失败: {stmt[:50]}... \n错误: {str(e)[:100]}")
return stats
except Exception as e:
print(f"文件错误: {str(e)}")
return stats

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

@ -4,4 +4,4 @@ $$4HNO_{3}\overset{\overset{}{{\Delta}}}{=}4NO_{2} \uparrow + O_{2} \uparrow + 2
$$FeO + 4HNO_{3}\overset{\overset{}{{\Delta}}}{=}Fe(NO_{3})_{3} + 2H_{2} \uparrow + NO_{2} \uparrow$$
氢气与氧气燃烧的现象如下图所示:
$$2H_{2} + O_{2}\overset{\overset{}{\text{燃烧}}}{=}2H_{2}O$$
![](./Images/4826f1dfc6ce4ba5a294167a016b736f/media/image1.png)
![](./Images/5009542d74a24d00b5ae62f5cdc0f048/media/image1.png)

Loading…
Cancel
Save