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
178 lines
5.6 KiB
Python
178 lines
5.6 KiB
Python
"""
|
|
End-to-end integration test for edge-centered payload and triplet embeddings.
|
|
|
|
"""
|
|
|
|
import os
|
|
import pathlib
|
|
import cognee
|
|
from cognee.infrastructure.databases.graph import get_graph_engine
|
|
from cognee.infrastructure.databases.vector import get_vector_engine_async
|
|
from cognee.modules.search.types import SearchType
|
|
from cognee.shared.logging_utils import get_logger
|
|
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
from cognee.modules.ontology.ontology_config import Config
|
|
|
|
logger = get_logger()
|
|
|
|
text_data = """
|
|
Apple is a technology company that produces the iPhone, iPad, and Mac computers.
|
|
The company is known for its innovative products and ecosystem integration.
|
|
|
|
Microsoft develops the Windows operating system and Office productivity suite.
|
|
They are also major players in cloud computing with Azure.
|
|
|
|
Google created the Android operating system and provides search engine services.
|
|
The company is a leader in artificial intelligence and machine learning.
|
|
"""
|
|
|
|
ontology_content = """<?xml version="1.0"?>
|
|
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
|
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
|
xmlns="http://example.org/tech#"
|
|
xml:base="http://example.org/tech">
|
|
|
|
<owl:Ontology rdf:about="http://example.org/tech"/>
|
|
|
|
<!-- Classes -->
|
|
<owl:Class rdf:ID="Company"/>
|
|
<owl:Class rdf:ID="TechnologyCompany"/>
|
|
<owl:Class rdf:ID="Product"/>
|
|
<owl:Class rdf:ID="Software"/>
|
|
<owl:Class rdf:ID="Hardware"/>
|
|
<owl:Class rdf:ID="Service"/>
|
|
|
|
<rdf:Description rdf:about="#TechnologyCompany">
|
|
<rdfs:subClassOf rdf:resource="#Company"/>
|
|
<rdfs:comment>A company operating in the technology sector.</rdfs:comment>
|
|
</rdf:Description>
|
|
|
|
<rdf:Description rdf:about="#Software">
|
|
<rdfs:subClassOf rdf:resource="#Product"/>
|
|
<rdfs:comment>Software products and applications.</rdfs:comment>
|
|
</rdf:Description>
|
|
|
|
<rdf:Description rdf:about="#Hardware">
|
|
<rdfs:subClassOf rdf:resource="#Product"/>
|
|
<rdfs:comment>Physical hardware products.</rdfs:comment>
|
|
</rdf:Description>
|
|
|
|
<!-- Individuals -->
|
|
<TechnologyCompany rdf:ID="apple">
|
|
<rdfs:label>Apple</rdfs:label>
|
|
</TechnologyCompany>
|
|
|
|
<TechnologyCompany rdf:ID="microsoft">
|
|
<rdfs:label>Microsoft</rdfs:label>
|
|
</TechnologyCompany>
|
|
|
|
<TechnologyCompany rdf:ID="google">
|
|
<rdfs:label>Google</rdfs:label>
|
|
</TechnologyCompany>
|
|
|
|
<Hardware rdf:ID="iphone">
|
|
<rdfs:label>iPhone</rdfs:label>
|
|
</Hardware>
|
|
|
|
<Software rdf:ID="windows">
|
|
<rdfs:label>Windows</rdfs:label>
|
|
</Software>
|
|
|
|
<Software rdf:ID="android">
|
|
<rdfs:label>Android</rdfs:label>
|
|
</Software>
|
|
|
|
</rdf:RDF>"""
|
|
|
|
|
|
async def main():
|
|
data_directory_path = str(
|
|
pathlib.Path(
|
|
os.path.join(
|
|
pathlib.Path(__file__).parent,
|
|
".data_storage/test_edge_centered_payload",
|
|
)
|
|
).resolve()
|
|
)
|
|
cognee_directory_path = str(
|
|
pathlib.Path(
|
|
os.path.join(
|
|
pathlib.Path(__file__).parent,
|
|
".cognee_system/test_edge_centered_payload",
|
|
)
|
|
).resolve()
|
|
)
|
|
|
|
cognee.config.data_root_directory(data_directory_path)
|
|
cognee.config.system_root_directory(cognee_directory_path)
|
|
|
|
# Enable triplet embedding for this test
|
|
os.environ["TRIPLET_EMBEDDING"] = "true"
|
|
|
|
dataset_name = "tech_companies"
|
|
|
|
await cognee.prune.prune_data()
|
|
await cognee.prune.prune_system(metadata=True)
|
|
|
|
await cognee.add(data=text_data, dataset_name=dataset_name)
|
|
|
|
import tempfile
|
|
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".owl", delete=False) as f:
|
|
f.write(ontology_content)
|
|
ontology_file_path = f.name
|
|
|
|
try:
|
|
logger.info(f"Loading ontology from: {ontology_file_path}")
|
|
config: Config = {
|
|
"ontology_config": {
|
|
"ontology_resolver": RDFLibOntologyResolver(ontology_file=ontology_file_path)
|
|
}
|
|
}
|
|
|
|
await cognee.cognify(datasets=[dataset_name], config=config)
|
|
graph_engine = await get_graph_engine()
|
|
nodes_phase2, edges_phase2 = await graph_engine.get_graph_data()
|
|
|
|
vector_engine = await get_vector_engine_async()
|
|
triplets_phase2 = await vector_engine.search(
|
|
query_text="technology", limit=None, collection_name="Triplet_text"
|
|
)
|
|
|
|
assert len(triplets_phase2) > 0, (
|
|
"Expected triplet embeddings to be created, but found none."
|
|
)
|
|
assert len(triplets_phase2) == len(edges_phase2), (
|
|
f"Triplet count ({len(triplets_phase2)}) should be equal to edge count: ({len(edges_phase2)})."
|
|
)
|
|
logger.info(f"Created {len(triplets_phase2)} triplets from {len(edges_phase2)} edges")
|
|
|
|
search_results_phase2 = await cognee.search(
|
|
query_type=SearchType.TRIPLET_COMPLETION,
|
|
query_text="What products does Apple make?",
|
|
)
|
|
|
|
assert search_results_phase2 is not None, (
|
|
"Search should return results for triplet embeddings in simple ontology use case."
|
|
)
|
|
|
|
finally:
|
|
if os.path.exists(ontology_file_path):
|
|
os.unlink(ontology_file_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import asyncio
|
|
from cognee.shared.logging_utils import setup_logging
|
|
|
|
setup_logging()
|
|
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
try:
|
|
loop.run_until_complete(main())
|
|
finally:
|
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
loop.close()
|