mirror of
https://github.com/microsoft/graphrag.git
synced 2026-02-06 19:22:35 +08:00
* Remove "strategy" from community reports config/workflow * Remove extraction strategy from extract_graph * Remove summarization strategy from extract_graph * Remove strategy from claim extraction * Strongly type prompt templates * Remove strategy from embed_text * Push hydrated params into community report workflows * Push hyrdated params into extract covariates * Push hydrated params into extract graph NLP * Push hydrated params into extract graph * Push hydrated params into text embeddings * Remove a few more low-level defaults * Semver * Remove configurable prompt delimiters * Update smoke tests
76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
# Copyright (c) 2024 Microsoft Corporation.
|
|
# Licensed under the MIT License
|
|
|
|
from graphrag.config.create_graphrag_config import create_graphrag_config
|
|
from graphrag.config.enums import ModelType
|
|
from graphrag.index.workflows.extract_graph import (
|
|
run_workflow,
|
|
)
|
|
from graphrag.utils.storage import load_table_from_storage
|
|
|
|
from .util import (
|
|
DEFAULT_CHAT_MODEL_CONFIG,
|
|
DEFAULT_EMBEDDING_MODEL_CONFIG,
|
|
create_test_context,
|
|
)
|
|
|
|
MOCK_LLM_ENTITY_RESPONSES = [
|
|
"""
|
|
("entity"<|>COMPANY_A<|>COMPANY<|>Company_A is a test company)
|
|
##
|
|
("entity"<|>COMPANY_B<|>COMPANY<|>Company_B owns Company_A and also shares an address with Company_A)
|
|
##
|
|
("entity"<|>PERSON_C<|>PERSON<|>Person_C is director of Company_A)
|
|
##
|
|
("relationship"<|>COMPANY_A<|>COMPANY_B<|>Company_A and Company_B are related because Company_A is 100% owned by Company_B and the two companies also share the same address)<|>2)
|
|
##
|
|
("relationship"<|>COMPANY_A<|>PERSON_C<|>Company_A and Person_C are related because Person_C is director of Company_A<|>1))
|
|
""".strip()
|
|
]
|
|
|
|
MOCK_LLM_SUMMARIZATION_RESPONSES = [
|
|
"""
|
|
This is a MOCK response for the LLM. It is summarized!
|
|
""".strip()
|
|
]
|
|
|
|
|
|
async def test_extract_graph():
|
|
context = await create_test_context(
|
|
storage=["text_units"],
|
|
)
|
|
|
|
extraction_model = DEFAULT_CHAT_MODEL_CONFIG.copy()
|
|
extraction_model["type"] = ModelType.MockChat
|
|
extraction_model["responses"] = MOCK_LLM_ENTITY_RESPONSES # type: ignore
|
|
config = create_graphrag_config({
|
|
"models": {
|
|
"default_chat_model": extraction_model,
|
|
"default_embedding_model": DEFAULT_EMBEDDING_MODEL_CONFIG,
|
|
}
|
|
})
|
|
|
|
summarize_llm_settings = config.get_language_model_config(
|
|
config.summarize_descriptions.model_id
|
|
).model_dump()
|
|
summarize_llm_settings["type"] = ModelType.MockChat
|
|
summarize_llm_settings["responses"] = MOCK_LLM_SUMMARIZATION_RESPONSES
|
|
config.summarize_descriptions.max_input_tokens = 1000
|
|
config.summarize_descriptions.max_length = 100
|
|
|
|
await run_workflow(config, context)
|
|
|
|
nodes_actual = await load_table_from_storage("entities", context.output_storage)
|
|
edges_actual = await load_table_from_storage(
|
|
"relationships", context.output_storage
|
|
)
|
|
|
|
assert len(nodes_actual.columns) == 5
|
|
assert len(edges_actual.columns) == 5
|
|
|
|
# TODO: with the combined verb we can't force summarization
|
|
# this is because the mock responses always result in a single description, which is returned verbatim rather than summarized
|
|
# we need to update the mocking to provide somewhat unique graphs so a true merge happens
|
|
# the assertion should grab a node and ensure the description matches the mock description, not the original as we are doing below
|
|
assert nodes_actual["description"].to_numpy()[0] == "Company_A is a test company"
|