2024-09-25 15:50:46 -07:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
from graphrag.callbacks.noop_verb_callbacks import NoopVerbCallbacks
|
|
|
|
from graphrag.config.create_graphrag_config import create_graphrag_config
|
|
|
|
from graphrag.index.workflows.create_final_documents import (
|
|
|
|
run_workflow,
|
2024-09-25 15:50:46 -07:00
|
|
|
workflow_name,
|
|
|
|
)
|
2025-01-03 13:59:26 -08:00
|
|
|
from graphrag.utils.storage import load_table_from_storage
|
2024-09-25 15:50:46 -07:00
|
|
|
|
|
|
|
from .util import (
|
|
|
|
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-25 15:50:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_documents():
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
|
|
|
storage=["create_base_text_units"],
|
2024-11-13 15:11:19 -08:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
config = create_graphrag_config()
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
await run_workflow(
|
|
|
|
config,
|
|
|
|
context,
|
|
|
|
NoopVerbCallbacks(),
|
2024-09-25 15:50:46 -07:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
actual = await load_table_from_storage(workflow_name, context.storage)
|
|
|
|
|
2024-09-25 15:50:46 -07:00
|
|
|
compare_outputs(actual, expected)
|
|
|
|
|
|
|
|
|
2024-10-15 12:58:58 -07:00
|
|
|
async def test_create_final_documents_with_attribute_columns():
|
2024-12-05 09:57:26 -08:00
|
|
|
expected = load_test_table(workflow_name)
|
2024-10-15 12:58:58 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
|
|
|
storage=["create_base_text_units"],
|
2024-11-13 15:11:19 -08:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
config = create_graphrag_config()
|
|
|
|
config.input.document_attribute_columns = ["title"]
|
2024-10-15 12:58:58 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
await run_workflow(
|
|
|
|
config,
|
|
|
|
context,
|
|
|
|
NoopVerbCallbacks(),
|
2024-10-15 12:58:58 -07:00
|
|
|
)
|
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
actual = await load_table_from_storage(workflow_name, context.storage)
|
|
|
|
|
2024-10-15 12:58:58 -07:00
|
|
|
# we should have dropped "title" and added "attributes"
|
|
|
|
# our test dataframe does not have attributes, so we'll assert without it
|
|
|
|
# and separately confirm it is in the output
|
2024-11-13 15:11:19 -08:00
|
|
|
compare_outputs(
|
|
|
|
actual, expected, columns=["id", "human_readable_id", "text", "text_unit_ids"]
|
|
|
|
)
|
|
|
|
assert len(actual.columns) == 5
|
|
|
|
assert "title" not in actual.columns
|
2024-10-15 12:58:58 -07:00
|
|
|
assert "attributes" in actual.columns
|