初始化检索系统
(self, chunks: List[Document])
| 50 | self.graph_indexed = False |
| 51 | |
| 52 | def initialize(self, chunks: List[Document]): |
| 53 | """初始化检索系统""" |
| 54 | logger.info("初始化混合检索模块...") |
| 55 | |
| 56 | # 连接Neo4j |
| 57 | self.driver = GraphDatabase.driver( |
| 58 | self.config.neo4j_uri, |
| 59 | auth=(self.config.neo4j_user, self.config.neo4j_password) |
| 60 | ) |
| 61 | |
| 62 | # 初始化BM25检索器 |
| 63 | if chunks: |
| 64 | self.bm25_retriever = BM25Retriever.from_documents(chunks) |
| 65 | logger.info(f"BM25检索器初始化完成,文档数量: {len(chunks)}") |
| 66 | |
| 67 | # 初始化图索引 |
| 68 | self._build_graph_index() |
| 69 | |
| 70 | def _build_graph_index(self): |
| 71 | """构建图索引""" |
nothing calls this directly
no test coverage detected