Repository: topoteretes/cognee
File: cognee/modules/retrieval/utils/brute_force_triplet_search.py (Python)

Code before:
    )

    try:
        graph_engine = await get_graph_engine()
        logger.debug("Successfully obtained graph engine")

        memory_fragment = CogneeGraph()
        logger.debug("Initialized empty CogneeGraph memory fragment")

        import time

        start_time = time.time()

        await memory_fragment.project_graph_from_db(
            graph_engine,
            node_properties_to_project=properties_to_project,
            edge_properties_to_project=["relationship_name"],
            node_type=node_type,
            node_name=node_name,
        )

        projection_time = time.time() - start_time
        node_count = len(memory_fragment.nodes)
        edge_count = len(memory_fragment.edges)

        logger.info(f"Memory fragment projection completed in {projection_time:.2f} seconds")
        logger.info(f"Memory fragment contains {node_count} nodes and {edge_count} edges")

        if node_count == 0:
            logger.warning("Memory fragment projection resulted in empty graph - no nodes found")
        if edge_count == 0 and node_count > 0:
            logger.warning(f"Memory fragment has {node_count} nodes but no edges - isolated nodes")

    except EntityNotFoundError as e:
        logger.warning(f"EntityNotFoundError during memory fragment creation: {str(e)}")
        logger.info("Continuing with empty memory fragment due to EntityNotFoundError")
        # This is expected behavior - continue with empty fragment
        pass
    except Exception as e:
        logger.error(f"Unexpected error during memory fragment creation: {str(e)}")
        logger.debug(f"Error type: {type(e).__name__}")
        # Still return the fragment even if projection failed
        pass

    final_node_count = len(memory_fragment.nodes)
    final_edge_count = len(memory_fragment.edges)
    logger.debug(
        f"Returning memory fragment with {final_node_count} nodes and {final_edge_count} edges"
    )

    return memory_fragment

Review comment (suggestion):
We log this twice, once its:

 Graph projection completed successfully in 0.08 seconds [CogneeGraph]
2025-07-22T10:18:13.349345 [info     ] Final graph stats: 82 nodes, 113 edges [CogneeGraph]

other time its here:

Memory fragment projection completed in 0.08 seconds [cognee.shared.logging_utils]
2025-07-22T10:18:13.349526 [info     ] Memory fragment contains 82 nodes and 113 edges [cognee.shared.logging_utils]

Code after:
            graph_engine,
            node_properties_to_project=properties_to_project,
            edge_properties_to_project=["relationship_name"],
            node_type=node_type,
            node_name=node_name,
        )

    except EntityNotFoundError:
        # This is expected behavior - continue with empty fragment
        pass
    except Exception as e:
        logger.error(f"Error during memory fragment creation: {str(e)}")
        # Still return the fragment even if projection failed
        pass

    return memory_fragment


async def brute_force_triplet_search(
    query: str,
    user: User = None,
    top_k: int = 5,
    collections: List[str] = None,
    properties_to_project: List[str] = None,
    memory_fragment: Optional[CogneeGraph] = None,
    node_type: Optional[Type] = None,
    node_name: Optional[List[str]] = None,
) -> list:
    if user is None:
        user = await get_default_user()

    retrieved_results = await brute_force_search(
        query,
        user,
        top_k,
        collections=collections,
        properties_to_project=properties_to_project,
        memory_fragment=memory_fragment,
        node_type=node_type,
        node_name=node_name,
    )
    return retrieved_results


async def brute_force_search(
    query: str,
    user: User,
    top_k: int,
    collections: List[str] = None,
    properties_to_project: List[str] = None,
    memory_fragment: Optional[CogneeGraph] = None,