topologicpy.GraphRAG module

class topologicpy.GraphRAG.GraphRAG

Bases: object

A minimal graph-native retrieval-augmented generation workflow.

The class follows the TopologicPy static-method style. Create a GraphRAG object with GraphRAG.ByParameters(…), then pass that object to the other static methods:

grag = GraphRAG.ByParameters(graphdb=graphdb, llm=llm) result = GraphRAG.Generate(grag, graph, description=”…”)

Methods

ActionSchema()

Returns the JSON schema for graph-edit actions.

ApplyAction(grag, graph, action[, silent])

Applies one action to the input graph.

ApproveAction(action[, approvalFunction, silent])

Requests approval for an action.

ByParameters([graphdb, llm, promptContext, ...])

Creates and returns a lightweight GraphRAG configuration object.

Evidence(grag, graphSummary[, silent])

Retrieves compact corpus evidence from GraphDB for the current graph state.

ExpandableNodes(graphSummary[, evidence, silent])

Returns nodes whose current degree is lower than the maximum found in the corpus.

Generate(grag, graph[, description, ...])

Iteratively grows or edits the input graph using corpus evidence and an LLM.

Generate_old(grag, graph[, description, ...])

Iteratively grows or edits the input graph using corpus evidence and an LLM.

NormalizeAction(action)

Normalizes common action aliases and field aliases.

PickAction(grag, graphSummary[, evidence, ...])

Asks the configured LLM to select the next graph-edit action.

Prompt(grag, graphSummary[, evidence, ...])

Builds the prompt used for graph-edit action selection.

SummarizeGraph(grag, graph[, silent])

Summarises the current working graph as JSON-friendly nodes and edges.

list_working_nodes_edges(grag, graph[, silent])

Returns the current graph nodes and edges.

unique_id([graph, prefix, key, silent])

Returns a unique vertex ID for the input graph.

static ActionSchema() Dict[str, Any]

Returns the JSON schema for graph-edit actions.

static ApplyAction(grag, graph, action: Dict[str, Any], silent: bool = False) Dict[str, Any]

Applies one action to the input graph.

static ApproveAction(action: Dict[str, Any], approvalFunction: Callable[[Dict[str, Any], str], str] = None, silent: bool = False) str

Requests approval for an action.

static ByParameters(graphdb=None, llm=None, promptContext: str = None, vertexIDKey: str = 'id', vertexLabelKey: str = 'label', edgeLabelKey: str = 'label', ontology: bool = True, ontologyClassKey: str = 'ontology_class', categoryKey: str = 'category', uriKey: str = 'uri', sourceKey: str = 'source', generatedByKey: str = 'generated_by', derivedFromKey: str = 'derived_from', defaultGraphOntologyClass: str = 'top:KnowledgeGraph', defaultVertexOntologyClass: str = 'top:Node', defaultEdgeOntologyClass: str = 'top:Relationship', defaultVertexCategory: str = 'node', defaultEdgeCategory: str = 'relationship', defaultGeneratedBy: str = 'GraphRAG.Generate', defaultEdgeLabel: str = 'suggested', tolerance: float = 0.0001, maxCandidates: int = 12, maxPairs: int = 40, silent: bool = False)

Creates and returns a lightweight GraphRAG configuration object.

static Evidence(grag, graphSummary: Dict[str, Any], silent: bool = False) Dict[str, Any]

Retrieves compact corpus evidence from GraphDB for the current graph state.

static ExpandableNodes(graphSummary: Dict[str, Any], evidence: Dict[str, Any] = None, silent: bool = False) List[Dict[str, Any]]

Returns nodes whose current degree is lower than the maximum found in the corpus.

static Generate(grag, graph, description: str = '', maxSteps: int = 10, patience: int = 4, automatic: bool = False, approvalFunction: Callable[[Dict[str, Any], str], str] = None, verbose: bool = True, silent: bool = False) Dict[str, Any]

Iteratively grows or edits the input graph using corpus evidence and an LLM.

This implementation edits a temporary Python adjacency-matrix state and materialises a TopologicPy graph only once, at the end of generation. This avoids allowing geometric coincidence or core graph mutation behaviour to block the intended topological edits.

static Generate_old(grag, graph, description: str = '', maxSteps: int = 10, patience: int = 4, automatic: bool = False, approvalFunction: Callable[[Dict[str, Any], str], str] = None, verbose: bool = True, silent: bool = False) Dict[str, Any]

Iteratively grows or edits the input graph using corpus evidence and an LLM.

static NormalizeAction(action: Dict[str, Any]) Dict[str, Any]

Normalizes common action aliases and field aliases.

static PickAction(grag, graphSummary, evidence=None, description: str = '', silent: bool = False)

Asks the configured LLM to select the next graph-edit action.

static Prompt(grag, graphSummary: Dict[str, Any], evidence: Dict[str, Any] = None, description: str = '', silent: bool = False) str

Builds the prompt used for graph-edit action selection.

static SummarizeGraph(grag, graph, silent: bool = False) Dict[str, Any]

Summarises the current working graph as JSON-friendly nodes and edges.

static list_working_nodes_edges(grag, graph, silent: bool = False) Dict[str, Any]

Returns the current graph nodes and edges.

static unique_id(graph=None, prefix: str = 'n', key: str = 'id', silent: bool = False) str

Returns a unique vertex ID for the input graph.