Skip to content

Commit 40b9533

Browse files
committed
Refactor neuron connectivity query to use DISTINCT for improved accuracy in results
1 parent 1255c9f commit 40b9533

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ def get_neuron_neuron_connectivity(short_form: str, return_dataframe=True, limit
28632863
# for 'both', no additional WHERE
28642864

28652865
cypher = base_cypher + direction_filter + """
2866-
RETURN
2866+
RETURN DISTINCT
28672867
oi.short_form AS id,
28682868
oi.label AS label,
28692869
coalesce(down.weight[0], 0) AS outputs,
@@ -2880,7 +2880,15 @@ def get_neuron_neuron_connectivity(short_form: str, return_dataframe=True, limit
28802880

28812881
# Get total count if limit was applied
28822882
if limit != -1:
2883-
count_query = base_cypher + direction_filter + " RETURN count(DISTINCT oi) AS total_count"
2883+
count_query = base_cypher + direction_filter + """
2884+
WITH DISTINCT
2885+
oi.short_form AS id,
2886+
oi.label AS label,
2887+
coalesce(down.weight[0], 0) AS outputs,
2888+
coalesce(up.weight[0], 0) AS inputs,
2889+
oi.uniqueFacets AS tags
2890+
RETURN count(*) AS total_count
2891+
"""
28842892
count_results = vc.nc.commit_list([count_query])
28852893
count_rows = get_dict_cursor()(count_results)
28862894
total_count = count_rows[0].get('total_count', 0) if count_rows else 0

0 commit comments

Comments
 (0)