chore: adds and updates docstrings
This commit is contained in:
parent
28942a20ef
commit
7c33418ae9
4 changed files with 43 additions and 12 deletions
|
|
@ -298,7 +298,7 @@ def expand_with_nodes_and_edges(
|
||||||
chunk_graphs (list[KnowledgeGraph]): List of knowledge graphs corresponding to each
|
chunk_graphs (list[KnowledgeGraph]): List of knowledge graphs corresponding to each
|
||||||
data chunk. Each graph contains nodes (entities) and edges (relationships) extracted
|
data chunk. Each graph contains nodes (entities) and edges (relationships) extracted
|
||||||
from the chunk content.
|
from the chunk content.
|
||||||
ontology_resolver (RDFLibOntologyResolver, optional): Resolver for validating entities and
|
ontology_resolver (BaseOntologyResolver, optional): Resolver for validating entities and
|
||||||
types against an ontology. If None, a default RDFLibOntologyResolver is created.
|
types against an ontology. If None, a default RDFLibOntologyResolver is created.
|
||||||
Defaults to None.
|
Defaults to None.
|
||||||
existing_edges_map (dict[str, bool], optional): Mapping of existing edge keys to prevent
|
existing_edges_map (dict[str, bool], optional): Mapping of existing edge keys to prevent
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from cognee.infrastructure.databases.graph import get_graph_engine
|
||||||
from cognee.tasks.storage.add_data_points import add_data_points
|
from cognee.tasks.storage.add_data_points import add_data_points
|
||||||
from cognee.modules.ontology.ontology_config import Config
|
from cognee.modules.ontology.ontology_config import Config
|
||||||
from cognee.modules.ontology.get_default_ontology_resolver import get_default_ontology_resolver
|
from cognee.modules.ontology.get_default_ontology_resolver import get_default_ontology_resolver
|
||||||
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
|
||||||
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
||||||
from cognee.modules.graph.utils import (
|
from cognee.modules.graph.utils import (
|
||||||
expand_with_nodes_and_edges,
|
expand_with_nodes_and_edges,
|
||||||
|
|
@ -26,9 +26,28 @@ async def integrate_chunk_graphs(
|
||||||
data_chunks: list[DocumentChunk],
|
data_chunks: list[DocumentChunk],
|
||||||
chunk_graphs: list,
|
chunk_graphs: list,
|
||||||
graph_model: Type[BaseModel],
|
graph_model: Type[BaseModel],
|
||||||
ontology_resolver: RDFLibOntologyResolver,
|
ontology_resolver: BaseOntologyResolver,
|
||||||
) -> List[DocumentChunk]:
|
) -> List[DocumentChunk]:
|
||||||
"""Updates DocumentChunk objects, integrates data points and edges into databases."""
|
"""Integrate chunk graphs with ontology validation and store in databases.
|
||||||
|
|
||||||
|
This function processes document chunks and their associated knowledge graphs,
|
||||||
|
validates entities against an ontology resolver, and stores the integrated
|
||||||
|
data points and edges in the configured databases.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data_chunks: List of document chunks containing source data
|
||||||
|
chunk_graphs: List of knowledge graphs corresponding to each chunk
|
||||||
|
graph_model: Pydantic model class for graph data validation
|
||||||
|
ontology_resolver: Resolver for validating entities against ontology
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of updated DocumentChunk objects with integrated data
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
InvalidChunkGraphInputError: If input validation fails
|
||||||
|
InvalidGraphModelError: If graph model validation fails
|
||||||
|
InvalidOntologyAdapterError: If ontology resolver validation fails
|
||||||
|
"""
|
||||||
|
|
||||||
if not isinstance(data_chunks, list) or not isinstance(chunk_graphs, list):
|
if not isinstance(data_chunks, list) or not isinstance(chunk_graphs, list):
|
||||||
raise InvalidChunkGraphInputError("data_chunks and chunk_graphs must be lists.")
|
raise InvalidChunkGraphInputError("data_chunks and chunk_graphs must be lists.")
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from typing import List
|
||||||
|
|
||||||
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
||||||
from cognee.shared.data_models import KnowledgeGraph
|
from cognee.shared.data_models import KnowledgeGraph
|
||||||
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
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_nodes import extract_nodes
|
||||||
from cognee.tasks.graph.cascade_extract.utils.extract_content_nodes_and_relationship_names import (
|
from cognee.tasks.graph.cascade_extract.utils.extract_content_nodes_and_relationship_names import (
|
||||||
extract_content_nodes_and_relationship_names,
|
extract_content_nodes_and_relationship_names,
|
||||||
|
|
@ -17,9 +17,21 @@ from cognee.tasks.graph.extract_graph_from_data import integrate_chunk_graphs
|
||||||
async def extract_graph_from_data(
|
async def extract_graph_from_data(
|
||||||
data_chunks: List[DocumentChunk],
|
data_chunks: List[DocumentChunk],
|
||||||
n_rounds: int = 2,
|
n_rounds: int = 2,
|
||||||
ontology_adapter: RDFLibOntologyResolver = None,
|
ontology_adapter: BaseOntologyResolver = None,
|
||||||
) -> List[DocumentChunk]:
|
) -> List[DocumentChunk]:
|
||||||
"""Extract and update graph data from document chunks in multiple steps."""
|
"""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_adapter: Resolver for validating entities against ontology
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of updated DocumentChunk objects with extracted graph data
|
||||||
|
"""
|
||||||
chunk_nodes = await asyncio.gather(
|
chunk_nodes = await asyncio.gather(
|
||||||
*[extract_nodes(chunk.text, n_rounds) for chunk in data_chunks]
|
*[extract_nodes(chunk.text, n_rounds) for chunk in data_chunks]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from cognee.modules.ontology.get_default_ontology_resolver import get_default_on
|
||||||
|
|
||||||
|
|
||||||
def test_ontology_adapter_initialization_success():
|
def test_ontology_adapter_initialization_success():
|
||||||
"""Test successful initialization of OntologyAdapter."""
|
"""Test successful initialization of RDFLibOntologyResolver from get_default_ontology_resolver."""
|
||||||
|
|
||||||
adapter = get_default_ontology_resolver()
|
adapter = get_default_ontology_resolver()
|
||||||
adapter.build_lookup()
|
adapter.build_lookup()
|
||||||
|
|
@ -104,7 +104,7 @@ def test_find_closest_match_no_match():
|
||||||
|
|
||||||
|
|
||||||
def test_get_subgraph_no_match_rdflib():
|
def test_get_subgraph_no_match_rdflib():
|
||||||
"""Test get_subgraph returns empty results for a non-existent node."""
|
"""Test get_subgraph returns empty results for a non-existent node using RDFLibOntologyResolver."""
|
||||||
g = Graph()
|
g = Graph()
|
||||||
|
|
||||||
resolver = get_default_ontology_resolver()
|
resolver = get_default_ontology_resolver()
|
||||||
|
|
@ -162,7 +162,7 @@ def test_get_subgraph_success_rdflib():
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_lookup_rdflib():
|
def test_refresh_lookup_rdflib():
|
||||||
"""Test that refresh_lookup rebuilds the lookup dict into a new object."""
|
"""Test that refresh_lookup rebuilds the lookup dict into a new object using RDFLibOntologyResolver."""
|
||||||
g = Graph()
|
g = Graph()
|
||||||
|
|
||||||
resolver = get_default_ontology_resolver()
|
resolver = get_default_ontology_resolver()
|
||||||
|
|
@ -283,7 +283,7 @@ def test_ontology_config_structure():
|
||||||
|
|
||||||
|
|
||||||
def test_get_ontology_resolver_default():
|
def test_get_ontology_resolver_default():
|
||||||
"""Test get_default_ontology_resolver returns default resolver."""
|
"""Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
|
||||||
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
||||||
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
||||||
|
|
||||||
|
|
@ -294,7 +294,7 @@ def test_get_ontology_resolver_default():
|
||||||
|
|
||||||
|
|
||||||
def test_get_default_ontology_resolver():
|
def test_get_default_ontology_resolver():
|
||||||
"""Test get_default_ontology_resolver returns default resolver."""
|
"""Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
|
||||||
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
||||||
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue