graphrag/tests/verbs/test_generate_text_embeddings.py
Nathan Evans c02ab0984a
Streamline workflows (#1674)
* Remove create_final_nodes

* Rename final entity output to "entities"

* Remove duplicate code from graph extraction

* Rename create_final_relationships output to "relationships"

* Rename create_final_communities output to "communities"

* Combine compute_communities and create_final_communities

* Rename create_final_covariates output to "covariates"

* Rename create_final_community_reports output to "community_reports"

* Rename create_final_text_units output to "text_units"

* Rename create_final_documents output to "documents"

* Remove transient snapshots config

* Move create_final_entities to finalize_entities operation

* Move create_final_relationships flow to finalize_relationships operation

* Reuse some community report functions

* Collapse most of graph and text unit-based report generation

* Unify schemas files

* Move community reports extractor

* Move NLP report prompt to prompts folder

* Fix a few pandas warnings

* Rename embeddings config to embed_text

* Rename claim_extraction config to extract_claims

* Remove nltk from standard graph extraction

* Fix verb tests

* Fix extract graph config naming

* Fix moved file reference

* Create v1-to-v2 migration notebook

* Semver

* Fix smoke test artifact count

* Raise tpm/rpm on smoke tests

* Update drift settings for smoke tests

* Reuse project directory var in api notebook

* Format

* Format
2025-02-07 11:11:03 -08:00

72 lines
2.1 KiB
Python

# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag.callbacks.noop_workflow_callbacks import NoopWorkflowCallbacks
from graphrag.config.create_graphrag_config import create_graphrag_config
from graphrag.config.embeddings import (
all_embeddings,
)
from graphrag.config.enums import TextEmbeddingTarget
from graphrag.index.workflows.generate_text_embeddings import (
run_workflow,
)
from graphrag.utils.storage import load_table_from_storage
from .util import (
DEFAULT_MODEL_CONFIG,
create_test_context,
)
async def test_generate_text_embeddings():
context = await create_test_context(
storage=[
"documents",
"relationships",
"text_units",
"entities",
"community_reports",
]
)
config = create_graphrag_config({"models": DEFAULT_MODEL_CONFIG})
llm_settings = config.get_language_model_config(
config.embed_text.model_id
).model_dump()
config.embed_text.strategy = {
"type": "mock",
"llm": llm_settings,
}
config.embed_text.target = TextEmbeddingTarget.all
config.snapshots.embeddings = True
await run_workflow(
config,
context,
NoopWorkflowCallbacks(),
)
parquet_files = context.storage.keys()
for field in all_embeddings:
assert f"embeddings.{field}.parquet" in parquet_files
# entity description should always be here, let's assert its format
entity_description_embeddings = await load_table_from_storage(
"embeddings.entity.description", context.storage
)
assert len(entity_description_embeddings.columns) == 2
assert "id" in entity_description_embeddings.columns
assert "embedding" in entity_description_embeddings.columns
# every other embedding is optional but we've turned them all on, so check a random one
document_text_embeddings = await load_table_from_storage(
"embeddings.document.text", context.storage
)
assert len(document_text_embeddings.columns) == 2
assert "id" in document_text_embeddings.columns
assert "embedding" in document_text_embeddings.columns