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
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import asyncio
|
|
from typing import List
|
|
|
|
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
|
from cognee.shared.data_models import KnowledgeGraph
|
|
from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
|
|
from cognee.tasks.graph.cascade_extract.utils.extract_nodes import extract_nodes
|
|
from cognee.tasks.graph.cascade_extract.utils.extract_content_nodes_and_relationship_names import (
|
|
extract_content_nodes_and_relationship_names,
|
|
)
|
|
from cognee.tasks.graph.cascade_extract.utils.extract_edge_triplets import (
|
|
extract_edge_triplets,
|
|
)
|
|
from cognee.tasks.graph.extract_graph_from_data import integrate_chunk_graphs
|
|
|
|
|
|
from cognee.modules.pipelines.tasks.task import task_summary
|
|
|
|
|
|
@task_summary("Extracted graph from {n} chunk(s)")
|
|
async def extract_graph_from_data(
|
|
data_chunks: List[DocumentChunk],
|
|
n_rounds: int = 2,
|
|
ontology_resolver: BaseOntologyResolver = None,
|
|
) -> List[DocumentChunk]:
|
|
"""Extract and update graph data from document chunks using cascade extraction.
|
|
|
|
This function performs multi-step graph extraction from document chunks,
|
|
using cascade extraction techniques to build comprehensive knowledge graphs.
|
|
|
|
Args:
|
|
data_chunks: List of document chunks to process
|
|
n_rounds: Number of extraction rounds to perform (default: 2)
|
|
ontology_resolver: Resolver for validating entities against ontology
|
|
|
|
Returns:
|
|
List of updated DocumentChunk objects with extracted graph data
|
|
"""
|
|
chunk_nodes = await asyncio.gather(
|
|
*[extract_nodes(chunk.text, n_rounds) for chunk in data_chunks]
|
|
)
|
|
|
|
chunk_results = await asyncio.gather(
|
|
*[
|
|
extract_content_nodes_and_relationship_names(chunk.text, nodes, n_rounds)
|
|
for chunk, nodes in zip(data_chunks, chunk_nodes)
|
|
]
|
|
)
|
|
|
|
updated_nodes, relationships = zip(*chunk_results)
|
|
|
|
chunk_graphs = await asyncio.gather(
|
|
*[
|
|
extract_edge_triplets(chunk.text, nodes, rels, n_rounds)
|
|
for chunk, nodes, rels in zip(data_chunks, updated_nodes, relationships)
|
|
]
|
|
)
|
|
|
|
return await integrate_chunk_graphs(
|
|
data_chunks=data_chunks,
|
|
chunk_graphs=chunk_graphs,
|
|
graph_model=KnowledgeGraph,
|
|
ontology_resolver=ontology_resolver,
|
|
)
|