Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
458eeac
Count the number of tokens in documents
alekszievr Jan 28, 2025
51eadef
Merge branch 'COG-970-refactor-tokenizing' into feat/cog-1071-input-t…
alekszievr Jan 28, 2025
ba608a4
Merge branch 'COG-970-refactor-tokenizing' into feat/cog-1071-input-t…
alekszievr Jan 28, 2025
f6663ab
save token count to relational db
alekszievr Jan 28, 2025
9182be8
Merge branch 'COG-970-refactor-tokenizing' into feat/cog-1132-add-num…
alekszievr Jan 28, 2025
72dfec4
Add metrics to metric table
alekszievr Jan 28, 2025
9bd5917
Merge branch 'dev' into feat/cog-1071-input-token-counting
dexters1 Jan 29, 2025
227d94e
Merge branch 'feat/cog-1071-input-token-counting' into feat/cog-1132-…
alekszievr Jan 29, 2025
22b6459
Store list as json instead of array in relational db table
alekszievr Jan 29, 2025
9764441
Merge branch 'dev' into feat/cog-1132-add-num-tokens-to-metric-table
alekszievr Jan 29, 2025
100e7d7
Sum in sql instead of python
alekszievr Jan 29, 2025
c182d47
Unify naming
alekszievr Jan 29, 2025
44fa2cd
Return data_points in descriptive metric calculation task
alekszievr Jan 29, 2025
06030ff
Graph metrics getter template in graph db interface and adapters
alekszievr Jan 29, 2025
48a51a3
Merge branch 'dev' into feat/cog-1082-metrics-in-graphdb-interface
alekszievr Jan 30, 2025
9a94db8
remove _table from table name
alekszievr Jan 30, 2025
57fb338
Merge branch 'dev' into feat/cog-1082-metrics-in-graphdb-interface
alekszievr Jan 31, 2025
e8dcef1
Merge branch 'dev' into feat/cog-1082-metrics-in-graphdb-interface
alekszievr Feb 1, 2025
b0f6ba7
Merge branch 'dev' into feat/cog-1082-metrics-in-graphdb-interface
alekszievr Feb 3, 2025
268d778
Use modules for adding to db instead of infrastructure
alekszievr Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Graph metrics getter template in graph db interface and adapters
  • Loading branch information
alekszievr committed Jan 29, 2025
commit 06030ff768f6e214cd5c826ec38c209932e08946
4 changes: 4 additions & 0 deletions cognee/infrastructure/databases/graph/graph_db_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ async def delete_graph(
@abstractmethod
async def get_graph_data(self):
raise NotImplementedError

@abstractmethod
async def get_graph_metrics(self):
raise NotImplementedError
14 changes: 14 additions & 0 deletions cognee/infrastructure/databases/graph/neo4j_driver/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,17 @@ async def get_filtered_graph_data(self, attribute_filters):
]

return (nodes, edges)

async def get_graph_metrics(self):
return {
"num_nodes": -1,
"num_edges": -1,
"mean_degree": -1,
"edge_density": -1,
"num_connected_components": -1,
"sizes_of_connected_components": -1,
"num_selfloops": -1,
"diameter": -1,
"avg_shortest_path_length": -1,
"avg_clustering": -1,
}
14 changes: 14 additions & 0 deletions cognee/infrastructure/databases/graph/networkx/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,17 @@ async def get_filtered_graph_data(
]

return filtered_nodes, filtered_edges

async def get_graph_metrics(self):
return {
"num_nodes": -1,
"num_edges": -1,
"mean_degree": -1,
"edge_density": -1,
"num_connected_components": -1,
"sizes_of_connected_components": -1,
"num_selfloops": -1,
"diameter": -1,
"avg_shortest_path_length": -1,
"avg_clustering": -1,
}
12 changes: 1 addition & 11 deletions cognee/tasks/storage/descriptive_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@ async def fetch_token_count(db_engine) -> int:
return token_count_sum


async def calculate_graph_metrics(graph_data):
nodes, edges = graph_data
graph_metrics = {
"num_nodes": len(nodes),
"num_edges": len(edges),
}
return graph_metrics


async def store_descriptive_metrics(data_points: list[DataPoint]):
db_engine = get_relational_engine()
graph_engine = await get_graph_engine()
graph_data = await graph_engine.get_graph_data()

token_count_sum = await fetch_token_count(db_engine)
graph_metrics = await calculate_graph_metrics(graph_data)
graph_metrics = await graph_engine.get_graph_metrics()

table_name = "graph_metrics_table"
metrics_dict = {"id": uuid.uuid4(), "num_tokens": token_count_sum} | graph_metrics
Expand Down
Loading