From bdaea6e67c581090e416aaa9383bf4dd3d2a4960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=20=E4=B8=9C?= <540953132@qq.com> Date: Thu, 17 Apr 2025 11:17:01 +0800 Subject: [PATCH] feat: PGKVStorage add get_all() --- lightrag/kg/postgres_impl.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index 97d3316c..45010682 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -297,6 +297,36 @@ class PGKVStorage(BaseKVStorage): self.db = None ################ QUERY METHODS ################ + async def get_all(self) -> dict[str, Any]: + """Get all data from storage + + Returns: + Dictionary containing all stored data + """ + table_name = namespace_to_table_name(self.namespace) + if not table_name: + logger.error(f"Unknown namespace for get_all: {self.namespace}") + return {} + + sql = f"SELECT * FROM {table_name} WHERE workspace=$1" + params = {"workspace": self.db.workspace} + + try: + results = await self.db.query(sql, params, multirows=True) + + if is_namespace(self.namespace, NameSpace.KV_STORE_LLM_RESPONSE_CACHE): + result_dict = {} + for row in results: + mode = row["mode"] + if mode not in result_dict: + result_dict[mode] = {} + result_dict[mode][row["id"]] = row + return result_dict + else: + return {row["id"]: row for row in results} + except Exception as e: + logger.error(f"Error retrieving all data from {self.namespace}: {e}") + return {} async def get_by_id(self, id: str) -> dict[str, Any] | None: """Get doc_full data by id."""