2024-09-17 10:32:25 -07:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
|
2025-01-06 10:58:59 -08:00
|
|
|
from graphrag.callbacks.noop_workflow_callbacks import NoopWorkflowCallbacks
|
2025-01-03 13:59:26 -08:00
|
|
|
from graphrag.config.create_graphrag_config import create_graphrag_config
|
|
|
|
from graphrag.index.workflows.create_final_text_units import (
|
|
|
|
run_workflow,
|
2024-09-17 10:32:25 -07:00
|
|
|
workflow_name,
|
|
|
|
)
|
2025-01-03 13:59:26 -08:00
|
|
|
from graphrag.utils.storage import load_table_from_storage
|
2024-09-17 10:32:25 -07:00
|
|
|
|
|
|
|
from .util import (
|
2025-01-21 15:52:06 -08:00
|
|
|
DEFAULT_MODEL_CONFIG,
|
2024-09-17 10:32:25 -07:00
|
|
|
compare_outputs,
|
2025-01-03 13:59:26 -08:00
|
|
|
create_test_context,
|
2024-12-05 09:57:26 -08:00
|
|
|
load_test_table,
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_text_units():
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
|
|
|
storage=[
|
|
|
|
"create_base_text_units",
|
|
|
|
"create_final_entities",
|
|
|
|
"create_final_relationships",
|
|
|
|
"create_final_covariates",
|
|
|
|
],
|
2024-10-24 10:20:03 -07:00
|
|
|
)
|
|
|
|
|
2025-01-21 15:52:06 -08:00
|
|
|
config = create_graphrag_config({"models": DEFAULT_MODEL_CONFIG})
|
2025-01-03 13:59:26 -08:00
|
|
|
config.claim_extraction.enabled = True
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
await run_workflow(
|
|
|
|
config,
|
|
|
|
context,
|
2025-01-06 10:58:59 -08:00
|
|
|
NoopWorkflowCallbacks(),
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
actual = await load_table_from_storage(workflow_name, context.storage)
|
|
|
|
|
2024-09-17 10:32:25 -07:00
|
|
|
compare_outputs(actual, expected)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_text_units_no_covariates():
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
|
|
|
storage=[
|
|
|
|
"create_base_text_units",
|
|
|
|
"create_final_entities",
|
|
|
|
"create_final_relationships",
|
|
|
|
"create_final_covariates",
|
|
|
|
],
|
2024-10-24 10:20:03 -07:00
|
|
|
)
|
|
|
|
|
2025-01-21 15:52:06 -08:00
|
|
|
config = create_graphrag_config({"models": DEFAULT_MODEL_CONFIG})
|
2025-01-03 13:59:26 -08:00
|
|
|
config.claim_extraction.enabled = False
|
2024-09-17 10:32:25 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
await run_workflow(
|
|
|
|
config,
|
|
|
|
context,
|
2025-01-06 10:58:59 -08:00
|
|
|
NoopWorkflowCallbacks(),
|
2024-09-17 10:32:25 -07:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
actual = await load_table_from_storage(workflow_name, context.storage)
|
|
|
|
|
2024-09-17 17:04:42 -07:00
|
|
|
# we're short a covariate_ids column
|
2024-11-13 15:11:19 -08:00
|
|
|
columns = list(expected.columns.values)
|
|
|
|
columns.remove("covariate_ids")
|
2024-09-17 17:04:42 -07:00
|
|
|
compare_outputs(
|
|
|
|
actual,
|
|
|
|
expected,
|
2024-11-13 15:11:19 -08:00
|
|
|
columns=columns,
|
2024-09-17 17:04:42 -07:00
|
|
|
)
|