Files
NexQuant/rdagent/core/knowledge_base.py
T
Xu Yang c095e4992f feat(kaggle): several update in kaggle scenarios (#476)
* udpate plot

* log and reduce token

* trace tag

* add simple_background parameter to get_scenario_all_desc

* update trace

* update first version code

* chat model map

* add annotation for stack index

* add annotation

* reformatted by black

* several update on kaggle scenarios

* update some new change

* fix CI

* fix CI

* fix a bug

* fix bugs in graph RAG

---------

Co-authored-by: Tim <illking@foxmail.com>
2024-11-06 13:14:35 +08:00

28 lines
998 B
Python

from pathlib import Path
import dill as pickle # type: ignore[import-untyped]
from rdagent.log import rdagent_logger as logger
class KnowledgeBase:
def __init__(self, path: str | Path | None = None) -> None:
self.path = Path(path) if path else None
self.load()
def load(self) -> None:
if self.path is not None and self.path.exists():
with self.path.open("rb") as f:
loaded = pickle.load(f)
if isinstance(loaded, dict):
self.__dict__.update({k: v for k, v in loaded.items() if not k == "path"})
else:
self.__dict__.update({k: v for k, v in loaded.__dict__.items() if not k == "path"})
def dump(self) -> None:
if self.path is not None:
self.path.parent.mkdir(parents=True, exist_ok=True)
pickle.dump(self.__dict__, self.path.open("wb"))
else:
logger.warning("KnowledgeBase path is not set, dump failed.")