@@ -53,7 +53,7 @@ class PGOpsSyncKVStorage(BaseKVStorage):
5353
5454 async def initialize (self ):
5555 """Initialize storage."""
56- logger .info (f"PGOpsSyncKVStorage initialized for workspace '{ self .workspace } '" )
56+ logger .debug (f"PGOpsSyncKVStorage initialized for workspace '{ self .workspace } '" )
5757
5858 async def finalize (self ):
5959 """Clean up resources."""
@@ -240,12 +240,74 @@ class PGOpsSyncVectorStorage(BaseVectorStorage):
240240
241241 async def initialize (self ):
242242 """Initialize storage."""
243- logger .info (f"PGOpsSyncVectorStorage initialized for workspace '{ self .workspace } '" )
243+ logger .debug (f"PGOpsSyncVectorStorage initialized for workspace '{ self .workspace } '" )
244244
245245 async def finalize (self ):
246246 """Clean up resources."""
247247 logger .debug (f"PGOpsSyncVectorStorage finalized for workspace '{ self .workspace } '" )
248248
249+ async def get_all (self ) -> dict [str , Any ]:
250+ """Get all data from vector storage"""
251+
252+ def _sync_get_all ():
253+ # Import here to avoid circular imports
254+ from aperag .db .ops import db_ops
255+ from aperag .graph .lightrag .namespace import NameSpace , is_namespace
256+
257+ # Determine which table to query based on namespace
258+ if is_namespace (self .namespace , NameSpace .VECTOR_STORE_CHUNKS ):
259+ models = db_ops .query_lightrag_doc_chunks_all (self .workspace )
260+ return {
261+ chunk_id : {
262+ "id" : chunk_id ,
263+ "tokens" : model .tokens ,
264+ "content" : model .content or "" ,
265+ "chunk_order_index" : model .chunk_order_index ,
266+ "full_doc_id" : model .full_doc_id ,
267+ "content_vector" : model .content_vector ,
268+ "file_path" : model .file_path ,
269+ "created_at" : int (model .create_time .timestamp ()) if model .create_time else None ,
270+ }
271+ for chunk_id , model in models .items ()
272+ }
273+ elif is_namespace (self .namespace , NameSpace .VECTOR_STORE_ENTITIES ):
274+ models = db_ops .query_lightrag_vdb_entity_all (self .workspace )
275+ return {
276+ entity_id : {
277+ "id" : entity_id ,
278+ "entity_name" : model .entity_name ,
279+ "content" : model .content or "" ,
280+ "content_vector" : model .content_vector ,
281+ "chunk_ids" : model .chunk_ids or [],
282+ "file_path" : model .file_path ,
283+ "created_at" : int (model .create_time .timestamp ()) if model .create_time else None ,
284+ }
285+ for entity_id , model in models .items ()
286+ }
287+ elif is_namespace (self .namespace , NameSpace .VECTOR_STORE_RELATIONSHIPS ):
288+ models = db_ops .query_lightrag_vdb_relation_all (self .workspace )
289+ return {
290+ relation_id : {
291+ "id" : relation_id ,
292+ "source_id" : model .source_id ,
293+ "target_id" : model .target_id ,
294+ "content" : model .content or "" ,
295+ "content_vector" : model .content_vector ,
296+ "chunk_ids" : model .chunk_ids or [],
297+ "file_path" : model .file_path ,
298+ "created_at" : int (model .create_time .timestamp ()) if model .create_time else None ,
299+ # Add additional fields that might be expected
300+ "src_id" : model .source_id ,
301+ "tgt_id" : model .target_id ,
302+ }
303+ for relation_id , model in models .items ()
304+ }
305+ else :
306+ logger .error (f"Unknown namespace for get_all: { self .namespace } " )
307+ return {}
308+
309+ return await asyncio .to_thread (_sync_get_all )
310+
249311 def _prepare_vector_data (self , item : dict [str , Any ], current_time : datetime .datetime ) -> dict [str , Any ]:
250312 """Prepare vector data based on namespace."""
251313 from aperag .graph .lightrag .namespace import NameSpace , is_namespace
0 commit comments