Asynchronously exports all entities, relations, and relationships to various formats. Args: chunk_entity_relation_graph: Graph storage instance for entities and relations entities_vdb: Vector database storage for entities relationships_vdb: Vector database storage f
(
chunk_entity_relation_graph,
entities_vdb,
relationships_vdb,
output_path: str,
file_format: str = "csv",
include_vector_data: bool = False,
)
| 3046 | |
| 3047 | |
| 3048 | async def aexport_data( |
| 3049 | chunk_entity_relation_graph, |
| 3050 | entities_vdb, |
| 3051 | relationships_vdb, |
| 3052 | output_path: str, |
| 3053 | file_format: str = "csv", |
| 3054 | include_vector_data: bool = False, |
| 3055 | ) -> None: |
| 3056 | """ |
| 3057 | Asynchronously exports all entities, relations, and relationships to various formats. |
| 3058 | |
| 3059 | Args: |
| 3060 | chunk_entity_relation_graph: Graph storage instance for entities and relations |
| 3061 | entities_vdb: Vector database storage for entities |
| 3062 | relationships_vdb: Vector database storage for relationships |
| 3063 | output_path: The path to the output file (including extension). |
| 3064 | file_format: Output format - "csv", "excel", "md", "txt". |
| 3065 | - csv: Comma-separated values file |
| 3066 | - excel: Microsoft Excel file with multiple sheets |
| 3067 | - md: Markdown tables |
| 3068 | - txt: Plain text formatted output |
| 3069 | include_vector_data: Whether to include data from the vector database. |
| 3070 | """ |
| 3071 | # Collect data |
| 3072 | entities_data = [] |
| 3073 | relations_data = [] |
| 3074 | relationships_data = [] |
| 3075 | |
| 3076 | # --- Entities --- |
| 3077 | all_entities = await chunk_entity_relation_graph.get_all_labels() |
| 3078 | for entity_name in all_entities: |
| 3079 | # Get entity information from graph |
| 3080 | node_data = await chunk_entity_relation_graph.get_node(entity_name) |
| 3081 | source_id = node_data.get("source_id") if node_data else None |
| 3082 | |
| 3083 | entity_info = { |
| 3084 | "graph_data": node_data, |
| 3085 | "source_id": source_id, |
| 3086 | } |
| 3087 | |
| 3088 | # Optional: Get vector database information |
| 3089 | if include_vector_data: |
| 3090 | entity_id = compute_mdhash_id(entity_name, prefix="ent-") |
| 3091 | vector_data = await entities_vdb.get_by_id(entity_id) |
| 3092 | entity_info["vector_data"] = vector_data |
| 3093 | |
| 3094 | entity_row = { |
| 3095 | "entity_name": entity_name, |
| 3096 | "source_id": source_id, |
| 3097 | "graph_data": str( |
| 3098 | entity_info["graph_data"] |
| 3099 | ), # Convert to string to ensure compatibility |
| 3100 | } |
| 3101 | if include_vector_data and "vector_data" in entity_info: |
| 3102 | entity_row["vector_data"] = str(entity_info["vector_data"]) |
| 3103 | entities_data.append(entity_row) |
| 3104 | |
| 3105 | # --- Relations --- |
no test coverage detected