Files
topoteretes--cognee/cognee/tests/utils/assert_edges_vector_index_present.py
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

79 lines
2.9 KiB
Python

from uuid import UUID
from typing import Dict, List, Tuple
from cognee.infrastructure.databases.graph import get_graph_engine
from cognee.infrastructure.databases.vector import get_vector_engine_async
from cognee.modules.engine.utils import generate_node_name
from cognee.modules.graph.models.EdgeType import EdgeType
from cognee.modules.graph.utils.prepare_edges_for_storage import get_edge_retrieval_text
from cognee.tests.utils.get_contains_edge_text import get_contains_edge_text
def format_relationship(
relationship: Tuple[UUID, UUID, str, Dict],
node: Dict,
graph_edges_by_key: Dict[Tuple[str, str, str], Dict],
):
edge_properties = graph_edges_by_key.get(
(str(relationship[0]), str(relationship[1]), relationship[2]),
{},
)
relationship_name = get_edge_retrieval_text(
edge_properties.get("edge_text"),
edge_properties.get("relationship_name") or relationship[2],
)
if relationship[2] == "contains":
if not relationship_name or relationship_name == "contains":
relationship_name = get_contains_edge_text(
generate_node_name(node["name"]),
node["description"],
)
return {str(EdgeType.id_for(relationship_name)): relationship_name}
async def assert_edges_vector_index_present(
relationships: List[Tuple[UUID, UUID, str, Dict]], convert_to_new_format: bool = True
):
vector_engine = await get_vector_engine_async()
graph_engine = await get_graph_engine()
nodes, graph_edges = await graph_engine.get_graph_data()
nodes_by_id = {str(node[0]): node[1] for node in nodes}
graph_edges_by_key = {
(str(edge[0]), str(edge[1]), edge[2]): edge[3] or {} for edge in graph_edges
}
query_edge_ids = {}
for relationship in relationships:
query_edge_ids = {
**query_edge_ids,
**(
format_relationship(
relationship,
nodes_by_id[str(relationship[1])],
graph_edges_by_key,
)
if convert_to_new_format
else {str(EdgeType.id_for(relationship[2])): relationship[2]}
),
}
vector_items = await vector_engine.retrieve(
"EdgeType_relationship_name", list(query_edge_ids.keys())
)
vector_items_by_id = {str(vector_item.id): vector_item for vector_item in vector_items}
for relationship_id, relationship_name in query_edge_ids.items():
assert relationship_id in vector_items_by_id, (
f"Relationship '{relationship_name}' not found in vector store."
)
vector_relationship = vector_items_by_id[relationship_id]
assert vector_relationship.payload["text"] == relationship_name, (
f"Vectorized edge '{vector_relationship.payload['text']}' does not match the relationship text '{relationship_name}'."
)