GraphRAG Export Functions

These functions export GraphRAG knowledge-graph data from pg_ripple to Parquet files compatible with the Microsoft GraphRAG pipeline.

All functions require superuser and return the number of rows written.


export_graphrag_entities

pg_ripple.export_graphrag_entities(
    graph_iri  TEXT,   -- named graph IRI, or '' for the default graph
    output_path TEXT   -- absolute path to the output .parquet file
) RETURNS BIGINT

Exports all gr:Entity instances.

Output columns:

ColumnTypeDescription
idBYTE_ARRAYEntity IRI
titleBYTE_ARRAYgr:title value
typeBYTE_ARRAYgr:type value
descriptionBYTE_ARRAYgr:description value
text_unit_idsBYTE_ARRAYJSON array placeholder (always "[]")
frequencyINT64gr:frequency value, default 0
degreeINT64gr:degree value, default 0

Example:

SELECT pg_ripple.export_graphrag_entities(
    'https://myapp.org/graphs/graphrag',
    '/var/data/entities.parquet'
);

export_graphrag_relationships

pg_ripple.export_graphrag_relationships(
    graph_iri  TEXT,
    output_path TEXT
) RETURNS BIGINT

Exports all gr:Relationship instances.

Output columns:

ColumnTypeDescription
idBYTE_ARRAYRelationship IRI
sourceBYTE_ARRAYgr:source entity IRI
targetBYTE_ARRAYgr:target entity IRI
descriptionBYTE_ARRAYgr:description value
weightDOUBLEgr:weight value, default 0.0
combined_degreeINT64Placeholder, always 0
text_unit_idsBYTE_ARRAYJSON array placeholder

export_graphrag_text_units

pg_ripple.export_graphrag_text_units(
    graph_iri  TEXT,
    output_path TEXT
) RETURNS BIGINT

Exports all gr:TextUnit instances.

Output columns:

ColumnTypeDescription
idBYTE_ARRAYText unit IRI
textBYTE_ARRAYgr:text value
n_tokensINT64gr:tokenCount value, default 0
document_idBYTE_ARRAYgr:documentId value
entity_idsBYTE_ARRAYJSON array placeholder
relationship_idsBYTE_ARRAYJSON array placeholder

Notes

  • Graph IRI: Pass '' (empty string) to query the default graph (all triples without a named-graph assignment). Pass a full IRI to restrict to a named graph.
  • Path security: The output path must not contain .. components or null bytes. The directory must already exist.
  • Parquet encoding: Uses Snappy compression. Columns are REQUIRED BYTE_ARRAY for mandatory fields and OPTIONAL BYTE_ARRAY / INT64 / DOUBLE for optional ones.
  • Superuser required: Because the function writes to the filesystem.

See also