初始化图RAG检索系统
(self)
| 74 | self.subgraph_cache = {} |
| 75 | |
| 76 | def initialize(self): |
| 77 | """初始化图RAG检索系统""" |
| 78 | logger.info("初始化图RAG检索系统...") |
| 79 | |
| 80 | # 连接Neo4j |
| 81 | try: |
| 82 | self.driver = GraphDatabase.driver( |
| 83 | self.config.neo4j_uri, |
| 84 | auth=(self.config.neo4j_user, self.config.neo4j_password) |
| 85 | ) |
| 86 | # 测试连接 |
| 87 | with self.driver.session() as session: |
| 88 | session.run("RETURN 1") |
| 89 | logger.info("Neo4j连接成功") |
| 90 | except Exception as e: |
| 91 | logger.error(f"Neo4j连接失败: {e}") |
| 92 | return |
| 93 | |
| 94 | # 预热:构建实体和关系索引 |
| 95 | self._build_graph_index() |
| 96 | |
| 97 | def _build_graph_index(self): |
| 98 | """构建图索引以加速查询""" |
no test coverage detected