持久化索引到磁盘
(self)
| 137 | return [doc for _, doc in scored[:top_k]] |
| 138 | |
| 139 | def save(self): |
| 140 | """持久化索引到磁盘""" |
| 141 | self.index_path.parent.mkdir(parents=True, exist_ok=True) |
| 142 | |
| 143 | if self._index is not None: |
| 144 | faiss.write_index(self._index, str(self.index_path)) |
| 145 | |
| 146 | metadata_path = self.index_path.with_suffix(".meta.json") |
| 147 | with open(metadata_path, "w", encoding="utf-8") as f: |
| 148 | json.dump(self._documents, f, ensure_ascii=False, indent=2) |
| 149 | |
| 150 | def load_knowledge_base(self, kb_dir: str) -> int: |
| 151 | """从目录批量加载知识库文档""" |
nothing calls this directly
no outgoing calls
no test coverage detected