Buckets:

download
raw
1.78 kB
from cognee.shared.data_models import KnowledgeGraph
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
from cognee.modules.engine.models import Entity, EntityType
def extract_relationships(
document_chunk: DocumentChunk, graph: KnowledgeGraph, cache: dict | None = None
):
if cache is None:
cache = {}
relationships = []
for edge in graph.edges:
edge_id = f"{edge.source_node_id}_{edge.relationship_name}_{edge.target_node_id}"
if edge_id not in cache:
relationship = (
Entity.id_for(edge.source_node_id),
Entity.id_for(edge.target_node_id),
edge.relationship_name,
)
cache[edge_id] = relationship
else:
relationship = cache[edge_id]
relationships.append(relationship)
for node in graph.nodes:
node_id = Entity.id_for(node.id)
type_node_id = EntityType.id_for(node.type)
type_edge_id = f"{str(node_id)}_is_a_{str(type_node_id)}"
if type_edge_id not in cache:
relationship = (
node_id,
type_node_id,
"is_a",
)
cache[type_edge_id] = relationship
else:
relationship = cache[type_edge_id]
relationships.append(relationship)
chunk_edge_id = f"{str(document_chunk.id)}_contains_{str(node_id)}"
if chunk_edge_id not in cache:
relationship = (
document_chunk.id,
node_id,
"contains",
)
cache[chunk_edge_id] = relationship
else:
relationship = cache[chunk_edge_id]
relationships.append(relationship)
return relationships

Xet Storage Details

Size:
1.78 kB
·
Xet hash:
7bfa37c0b57f2883b83bf0199d7d911c228c75d49411670a9a3228f644fd8b13

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.