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.config.create_graphrag_config import create_graphrag_config
|
2025-02-27 09:31:46 -08:00
|
|
|
from graphrag.data_model.schemas import DOCUMENTS_FINAL_COLUMNS
|
2025-01-03 13:59:26 -08:00
|
|
|
from graphrag.index.workflows.create_final_documents import (
|
|
|
|
run_workflow,
|
2024-09-25 15:50:46 -07:00
|
|
|
)
|
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 (
|
2025-01-21 15:52:06 -08:00
|
|
|
DEFAULT_MODEL_CONFIG,
|
2024-09-25 15:50:46 -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,
|
2025-02-13 17:03:51 -08:00
|
|
|
update_document_metadata,
|
2024-09-25 15:50:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_create_final_documents():
|
2025-02-07 11:11:03 -08:00
|
|
|
expected = load_test_table("documents")
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
2025-02-07 11:11:03 -08:00
|
|
|
storage=["text_units"],
|
2024-11-13 15:11:19 -08:00
|
|
|
)
|
|
|
|
|
2025-01-21 15:52:06 -08:00
|
|
|
config = create_graphrag_config({"models": DEFAULT_MODEL_CONFIG})
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-02-28 09:31:48 -08:00
|
|
|
await run_workflow(config, context)
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-06-12 16:14:39 -07:00
|
|
|
actual = await load_table_from_storage("documents", context.output_storage)
|
2025-01-03 13:59:26 -08:00
|
|
|
|
2024-09-25 15:50:46 -07:00
|
|
|
compare_outputs(actual, expected)
|
|
|
|
|
2025-02-27 09:31:46 -08:00
|
|
|
for column in DOCUMENTS_FINAL_COLUMNS:
|
|
|
|
assert column in actual.columns
|
|
|
|
|
2024-09-25 15:50:46 -07:00
|
|
|
|
2025-02-12 14:38:03 -03:00
|
|
|
async def test_create_final_documents_with_metadata_column():
|
2025-01-03 13:59:26 -08:00
|
|
|
context = await create_test_context(
|
2025-02-07 11:11:03 -08:00
|
|
|
storage=["text_units"],
|
2024-11-13 15:11:19 -08:00
|
|
|
)
|
|
|
|
|
2025-01-21 15:52:06 -08:00
|
|
|
config = create_graphrag_config({"models": DEFAULT_MODEL_CONFIG})
|
2025-02-03 14:37:06 -03:00
|
|
|
config.input.metadata = ["title"]
|
2024-10-15 12:58:58 -07:00
|
|
|
|
2025-02-13 17:03:51 -08:00
|
|
|
# simulate the metadata construction during initial input loading
|
|
|
|
await update_document_metadata(config.input.metadata, context)
|
|
|
|
|
2025-06-12 16:14:39 -07:00
|
|
|
expected = await load_table_from_storage("documents", context.output_storage)
|
2025-02-13 17:03:51 -08:00
|
|
|
|
2025-02-28 09:31:48 -08:00
|
|
|
await run_workflow(config, context)
|
2024-10-15 12:58:58 -07:00
|
|
|
|
2025-06-12 16:14:39 -07:00
|
|
|
actual = await load_table_from_storage("documents", context.output_storage)
|
2025-01-03 13:59:26 -08:00
|
|
|
|
2025-02-27 09:31:46 -08:00
|
|
|
compare_outputs(actual, expected)
|
|
|
|
|
|
|
|
for column in DOCUMENTS_FINAL_COLUMNS:
|
|
|
|
assert column in actual.columns
|