2024-09-23 16:55:53 -07:00
|
|
|
# Copyright (c) 2024 Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License
|
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
from graphrag.index.run.utils import create_run_context
|
2024-09-23 16:55:53 -07:00
|
|
|
from graphrag.index.workflows.v1.create_base_text_units 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_base_text_units():
|
|
|
|
input_tables = load_input_tables(inputs=[])
|
|
|
|
expected = load_expected(workflow_name)
|
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
context = create_run_context(None, None, None)
|
|
|
|
|
2024-09-23 16:55:53 -07:00
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
# test data was created with 4o, so we need to match the encoding for chunks to be identical
|
|
|
|
config["text_chunk"]["strategy"]["encoding_name"] = "o200k_base"
|
|
|
|
|
|
|
|
steps = build_steps(config)
|
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
await get_workflow_output(
|
2024-09-23 16:55:53 -07:00
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
2024-10-24 10:20:03 -07:00
|
|
|
context,
|
2024-09-23 16:55:53 -07:00
|
|
|
)
|
|
|
|
|
2024-10-24 10:20:03 -07:00
|
|
|
actual = await context.runtime_storage.get("base_text_units")
|
2024-09-23 16:55:53 -07:00
|
|
|
compare_outputs(actual, expected)
|
2024-11-04 17:23:29 -08:00
|
|
|
|
|
|
|
|
|
|
|
async def test_create_base_text_units_with_snapshot():
|
|
|
|
input_tables = load_input_tables(inputs=[])
|
|
|
|
|
|
|
|
context = create_run_context(None, None, None)
|
|
|
|
|
|
|
|
config = get_config_for_workflow(workflow_name)
|
|
|
|
# test data was created with 4o, so we need to match the encoding for chunks to be identical
|
|
|
|
config["text_chunk"]["strategy"]["encoding_name"] = "o200k_base"
|
|
|
|
config["snapshot_transient"] = True
|
|
|
|
|
|
|
|
steps = build_steps(config)
|
|
|
|
|
|
|
|
await get_workflow_output(
|
|
|
|
input_tables,
|
|
|
|
{
|
|
|
|
"steps": steps,
|
|
|
|
},
|
|
|
|
context,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert context.storage.keys() == [
|
|
|
|
"create_base_text_units.parquet"
|
|
|
|
], "Text unit snapshot keys differ"
|