2024-09-20 13:48:56 -07:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
|
2024-10-02 08:57:08 -07:00
|
|
|
from graphrag.index.storage.memory_pipeline_storage import MemoryPipelineStorage
|
2024-09-20 13:48:56 -07:00
|
|
|
from graphrag.index.workflows.v1.create_final_nodes import (
|
|
|
|
build_steps,
|
|
|
|
workflow_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
from .util import (
|
|
|
|
compare_outputs,
|
|
|
|
get_config_for_workflow,
|
|
|
|
get_workflow_output,
|
|
|
|
load_expected,
|
|
|
|
load_input_tables,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_nodes():
|
|
|
|
input_tables = load_input_tables([
|
|
|
|
"workflow:create_base_entity_graph",
|
|
|
|
])
|
|
|
|
expected = load_expected(workflow_name)
|
|
|
|
|
2024-10-02 08:57:08 -07:00
|
|
|
storage = MemoryPipelineStorage()
|
|
|
|
|
2024-09-20 13:48:56 -07:00
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
|
|
|
|
# default config turns UMAP off, which translates into false for layout
|
|
|
|
# we don't have graph embeddings in the test data, so this will fail if True
|
|
|
|
config["layout_graph_enabled"] = False
|
|
|
|
|
2024-10-02 08:57:08 -07:00
|
|
|
steps = build_steps(config)
|
2024-09-20 13:48:56 -07:00
|
|
|
|
|
|
|
actual = await get_workflow_output(
|
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
2024-10-02 08:57:08 -07:00
|
|
|
storage=storage,
|
2024-09-20 13:48:56 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
compare_outputs(actual, expected)
|
2024-10-02 08:57:08 -07:00
|
|
|
|
|
|
|
assert len(storage.keys()) == 0, "Storage should be empty"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_nodes_with_snapshot():
|
|
|
|
input_tables = load_input_tables([
|
|
|
|
"workflow:create_base_entity_graph",
|
|
|
|
])
|
|
|
|
expected = load_expected(workflow_name)
|
|
|
|
|
|
|
|
storage = MemoryPipelineStorage()
|
|
|
|
|
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
|
|
|
|
# default config turns UMAP off, which translates into false for layout
|
|
|
|
# we don't have graph embeddings in the test data, so this will fail if True
|
|
|
|
config["layout_graph_enabled"] = False
|
|
|
|
config["snapshot_top_level_nodes"] = True
|
|
|
|
|
|
|
|
steps = build_steps(config)
|
|
|
|
|
|
|
|
actual = await get_workflow_output(
|
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
|
|
|
storage=storage,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert actual.shape == expected.shape, "Graph dataframe shapes differ"
|
|
|
|
|
|
|
|
assert storage.keys() == [
|
|
|
|
"top_level_nodes.json",
|
|
|
|
], "Graph snapshot keys differ"
|