You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
make circuit browser query work at class level #114
The query runs in the browser. geppetto-vfb/components/configuration/VFBCircuitBrowser/circuitBrowserConfiguration.js builds Cypher that the browser posts straight to pdb. It runs Yen's k-shortest-paths over a stored graph called cb_, which holds individual neurons with path cost 5000 - weight. Both neurons must be in the same connectome.
The stored graphs are built by build_connectome_projections.sh (same folder). They are lost when Neo4j restarts. I confirmed all 8 are loaded on pdb now, e.g. cb_flywire783 has 137k nodes and 7.6M edges.
Classes can't get in. The query starts with MATCH (source:Neuron:has_neuron_connectivity …)-[:database_cross_reference]->(:Connectome), and only individual neurons match that. On top of that, the browser's search box and the Term Info "Add to Circuit Browser" button both require has_neuron_connectivity. I checked: no classes carry that tag, in either Neo4j or Solr. So classes never show up in the first place.
No class-level connectivity graph exists in the KB. VFBquery's class connectivity code (vfb_connectivity.py, _aggregate_class_connectivity) works out one class's partners on request. It is not a graph you can search for paths.
The MCP has query_connectivity but nothing for paths.
Proposed design
Build a class-level graph for each connectome (extend build_connectome_projections.sh)
Store it as a new graph cbc_. Each node is a cell type; each edge is the summed synaptic weight between all neurons of type A and all neurons of type B, plus a neuron-pair count.
Each neuron counts towards one class only, picked by the rule the browser already uses for labels: prefer the class with a symbol. Linking a neuron to all its classes would let broad classes like "adult cholinergic neuron" or lineage classes act as hubs, and the search would route paths through them. My sample of 2,000 FlyWire neurons showed none with more than one symbol-bearing class, so the rule is clear-cut.
Size is small. L1EM gives 564 classes and 12k class pairs, so this is cheap next to the neuron-level graphs.
The cost formula has to change. 5000 - weight breaks once weights are summed. My recommendation is cost = −log(the fraction of B's input that comes from A). Raw sums would favour big populations such as Kenyon cells. The simple fallback is 1/weight.
The script describes itself as a polishing-pipeline step. Worth confirming where it actually runs and adding the class build there too.
Add a VFBquery endpoint GET /circuit_paths (new module src/vfbquery/vfb_circuit.py plus a route in ha_api.py)
Parameters: source, target, paths (1–6), weight, dataset. Each ID can be a VFB_ individual (searched in cb_, the current behaviour) or an FBbt_ class (searched in cbc_).
Choosing a dataset for classes: a class can have neurons in several connectomes. If dataset is not given, run the search in each connectome where both classes have neurons and return results grouped by dataset. Hemibrain and CATMAID FAFB stay excluded by default, as in query_connectivity.
Broad classes: a class like "Kenyon cell" has no neurons typed to it directly. Expand it to its subclasses that are in the graph. Then use one Dijkstra run from each source subclass to all target subclasses, keep the best k paths, and cap the number of subclasses so the call can't blow up.
Return the nodes and links through the existing graph_builder.py, and use the existing cache and Neo4j worker pool.
If a stored graph is missing (e.g. after a restart), return a 503 with a clear messa "no paths".
Add an MCP tool find_circuit_paths (VFB3-MCP src/index.ts and LLM_GUIDANCE.md)
It is a thin wrapper over /circuit_paths, like handleQueryConnectivity.
The tool description should explain when to use it instead of query_connectivity, say that cost is not the same as synapse count, and give dataset defaults.
Also check what VFBchat's answerable-question-surface.md needs.
Circuit Browser UI (geppetto-vfb)
I recommend replacing the inline Cypher with a call to /circuit_paths. That keeps one copy of the logic, the same reasoning VFBquery used when it took over search, where separate copies had drifted
apart.
Accept classes in the search box: change the fq in datasources/SOLRclient.tsx.
Show the Term Info button for classes: change the superType in VFBTermInfoConfiguration.js.
Add a dataset picker or per-dataset view when the inputs are classes.
Tag classes that have data (vfb-pipeline-dumps, optional but cleaner)
Add a SPARQL rule next to construct_has_neuron_connectivity.sparql that tags a neuroass has a neuron with connectivity data. Steps 2 and 4 would use the tag to decidewhich classes to accept.
Suggested order
Build the class graph on one small connectome (L1EM, then BANC) and check that the paths make sense.
Write the VFBquery endpoint and tests.
Add the MCP tool.
Update the Circuit Browser.
Add the pipeline tag.
The MCP part of the issue can ship after steps 1–3, without waiting on the browser work.
Decisions for you
Path cost: input fraction (−log), which I recommend, or simple 1/summed weight?
Class tag: a new tag (e.g. has_connected_instances), or reuse has_neuron_connectivichanges what the existing search filters and MCP guidance mean.
Browser query: switch the browser to the VFBquery endpoint (I recommend this), or keep Cypher in the browser and add a class branch?
Multiple datasets: for classes, show results for each dataset, or make the user pick one?
Implications if we changed cost formula for instances too:
If the neuron level moved to −log(input fraction) too:
At build time, the build script would also need each neuron's total input weight: one extra aggregation per connectome. That makes the build slower but needs little extra memory.
The paths users get in the browser for neurons would change. Strong connections onto neurons with little total input would be favoured, and paths through big hub neurons would count for less.
The browser's minimum-weight filter would keep working, because the raw weight is still stored on each edge.
This replaces the earlier plan in this thread. Measurements are from the PDB on 2026-10-27.
Prerequisites now live
Total input and output per neuron (total_upstream / total_downstream) are on 559k neurons. Every connectome edge's target has a total, and no edge exceeds it, so inprop is always in (0, 1]. total_downstream is missing for the CATMAID datasets.
BANC v888 and hemibrain 1.2.1 are loaded, and every connectivity OWL records its release in the header.
The neuron graphs cb_<Site> are built at pod start by gds_projections.sh (docker-vfb-neo4j-productiondb, branch pdb-k8s). geppetto-vfb's build_connectome_projections.sh is a stale copy that nothing runs.
Scoring (the same at neuron and class level)
Edge weight: inprop = synapses A→B ÷ B's total input. Optional normalise=output uses A's total output instead ("where does A's output go?" rather than "what drives B?"); unavailable for L1EM and FAFB CATMAID until they have output totals.
Class edges: sum over the A neurons, then average over all B neurons, including B neurons that get nothing from A (Connectome Interpreter's rule). With one neuron per class this is exactly the neuron-level inprop. For normalise=output, the mirror image.
Path cost: −log(inprop), searched with Yen's k-shortest paths, so paths are the strongest chains (highest product of inprops). Each path is returned with its score and synapse counts.
Thresholds: the minimum-synapse filter applies to the summed class edge, plus an optional minimum inprop. Only edges of ≥2 synapses are loaded, so class sums miss single-synapse contacts while the totals include them. Class inprop is therefore slightly low where a connection is made of many single synapses (e.g. KC→MBON). This is accepted and will be documented in the API, MCP guidance and docs.
Classes
One class per neuron per connectome, fully typed classes only:
ignore axis classes: transmitter, lineage/hemilineage, primary/secondary neuron and fruitless classes, listed by FBbt ID. Only the classes themselves are dropped, not their descendants, since most cell types sit under a transmitter class;
a dataset's leaf types are the remaining direct types with no subclass also used in that dataset;
a neuron's class is its single leaf type. Neurons with no leaf type, or more than one, are left out of class graphs.
Without step 1, about 9–14k neurons each in FlyWire, BANC and male CNS would have two leaf types (a lineage class plus their cell type). With it, very few do: 395 in L1EM, 292 in male CNS and under 40 elsewhere. These look like annotation problems (e.g. motor neurons typed to all three segments), so they are reported rather than settled by a tie-break. The build writes a per-connectome report of left-out neurons.
Leaf types are used at the ends and in the middle of paths. A class with a subclass used in the same dataset is never a node. There are no "not further typed" remainder nodes. The response reports how many neurons each dataset left out. Follow-up curation is tracked in VirtualFlyBrain/connectome-curation#1 (neurons with no leaf type) and VirtualFlyBrain/connectome-curation#2 (neurons with more than one).
Query terms expand to the fully typed classes beneath them in each dataset (or the term itself, if fully typed). Broad terms just mean more classes are considered.
Search
Class → class: VFBquery holds each connectome's stored class graph in memory (5–10k nodes, 0.5–1M edges each). Per request it adds a temporary start node joined at zero cost to every source class and an end node joined from every target class, then runs Yen's. No cap is needed. Paths that pass through a source or target class partway are dropped.
Neuron → neuron: the cb_ GDS graphs as now, with cost changed from 5000 − weight to −log(inprop).
Neuron ↔ class (mixed): the neuron graph of the neuron's dataset, with the class end expanded to its fully typed classes' neurons.
instance_graph=true: for each of the best class paths, return neuron chains: for each hop take the neuron edges between consecutive classes and run a layered search for the k best chains. Several neurons can sit at each end.
Datasets: each dataset is searched separately with its own fully typed classes, and results come back grouped by dataset. The response lists what each query term expanded to in each dataset, and a summary flags class paths found in more than one dataset. Graphs are not merged across datasets: leaf sets, total-input scope (brain vs brain + VNC) and coverage all differ. Hemibrain and FAFB CATMAID are excluded by default, as in query_connectivity.
Steps, by repo
Class edges, built once per release in the PDB loader (not at pod start; all eight take about 5–6 minutes). Store each neuron's assigned class and the class→class edges (synapses, number of neuron pairs, inprop for input and output). Start with L1EM and FlyWire and check the assignment report.
docker-vfb-neo4j-productiondb gds_projections.sh: switch the cb_ cost to −log(inprop), keeping the raw weight for the browser's filter. Before switching, compare old and new paths on known circuits (olfactory PN→lateral horn, KC→MBON, LC→descending neurons): the answer changes from "fewest hops" to "strongest input chain".
VFBquery GET /circuit_paths (new vfb_circuit.py, route in ha_api.py): parameters for the two ends, k, minimum synapses, minimum inprop, normalise, exclude_dbs and instance_graph. It returns 503 if a graph is missing, uses the cache and worker pool, and has tests.
VFB3-MCP find_circuit_paths: a thin wrapper, plus guidance in LLM_GUIDANCE.md on when to use it rather than query_connectivity and what the score means.
vfb-pipeline-dumps: a has_connected_instances tag so classes can be offered in the browser search.
geppetto-vfb: the circuit browser calls /circuit_paths instead of building Cypher, accepts classes in the search box and in Term Info's "Add to Circuit Browser", shows results per dataset and multi-instance ends, updates the jest tests, and deletes the stale script.
Later, possibly
An effective-connectivity figure (summed over all paths up to n hops), computed with matrix maths outside Neo4j.
Excitatory/inhibitory signs from neurotransmitter predictions.
An opt-in merged class graph for closely comparable datasets (e.g. FlyWire and BANC brain neurons).
@Robbie1977, your view would be useful here, as it affects the pdb pods and the VFBquery deployment.
Where things stand
Neuron graphs (current circuit browser): GDS in-memory projections cb_<connectome>, built on every pdb pod at start by gds_projections.sh (docker-vfb-neo4j-productiondb, pdb-k8s). The eight together hold 37M edges and use about 960 MiB per pod. geppetto-vfb runs Yen's on them via Cypher.
Class graphs: the build is written on branch circuit-class-graph (vfb_circuit_classes.py) and has been run for L1EM and FlyWire. It uses exactly the same neurons and edges as the cb_ graphs. FlyWire comes to 7,318 classes and 874k class edges, built in about 3 minutes from pdb-analytics. It currently writes TSVs; it isn't stored anywhere yet.
I'd like both sets of graphs in the same place. There are two options.
Measured (FlyWire, Yen's, k=5)
GDS in the PDB (as now)
In VFBquery (python-igraph, in memory)
DA1_lPN → MBON01
0.19–0.61 s
0.25 s
LC12 → DNp01
0.41–0.45 s
0.32 s
Memory, FlyWire neuron graph
160 MiB
~300 MB (1.5 GB as first tested, with weights stored as Python floats)
Build
part of the ~4 min pod-start projection
4 s from arrays, plus ~2 min to fetch edges from pdb-analytics
The GDS times were measured over HTTP on pdb-analytics and the igraph times on a laptop. Speed is similar either way, so it doesn't decide this. Male CNS is the largest graph, with about twice FlyWire's edges.
Option 1: both in the PDB (GDS)
Memory: class graphs would add a few hundred MiB per pod to the ~960 MiB already used by cb_. That is negligible on 192 GiB pods.
Build: the loader job builds the class graph once per release and writes it into the golden volume. Pods then project cbc_ graphs at start, adding perhaps 30–60 s to the ~4 min.
Consistency: the class and neuron graphs always come from the same release, with no extra files to publish.
Limitation: GDS can't add temporary nodes per request, so the agreed approach (a temporary start node joined to every source class, and an end node joined from every target class) doesn't work. Broad query terms would need a workaround:
a Dijkstra run from each source to everything;
rank the source–target pairs;
run Yen's on the best pairs only.
That needs a cap for very broad terms. Mixed class → neuron queries would also need a reversed copy of each neuron graph (about +1 GB per pod).
Other costs: a build step in the loader image, and all search load stays on pdb (2–4 pods).
Option 2: both in VFBquery
Memory: about 1.5–2 GB per VFBquery pod for all 16 graphs. VFBquery runs 20 worker processes, so the graphs would sit in one dedicated search process (or be shared by fork), not be loaded 20 times. The memory request would go from 4 GiB to roughly 6–8 GiB; the limit is already 24 GiB. With 2 replicas that's about 4 GB in total.
Start-up: about 20–40 s to load the graph files at each VFBquery restart, returning 503 for circuit queries until they're loaded. Once the browser calls VFBquery instead of Cypher, gds_projections.sh could be retired. pdb pods would then start about 4 minutes faster and use about 1 GB less each.
Features: this fits the agreed design directly. Temporary start and end nodes, broad terms with no cap, mixed neuron ↔ class queries in both directions, and instance_graph are all straightforward. It can also be tested offline in CI.
Costs:
A release step publishes both sets of graphs as files: about 11 MB for FlyWire's class edges, and about 25 MB per large dataset for neuron edges.
VFBquery could serve graphs from a different release than pdb. To prevent that, each file records the PDB release it was built from, and VFBquery refuses files that don't match.
Recommendation
Option 2, mainly because the class search depends on per-request temporary nodes, which only work in memory, and the browser is moving to call VFBquery anyway. Option 1 is better if we want the graphs to stay queryable by Cypher in Neo4j, or if a few extra GB on VFBquery is a problem.
I agree with Option 2: both sets of graphs in VFBquery. The class search needs per-request temporary nodes, and taking the projections out of pdb start-up helps us more than the extra memory in VFBquery costs. The pdb pods now roll one at a time, so a start that is about 4 minutes faster shortens the time live pdb spends on a single pod.
Four changes to how we do it:
Build the graphs in the pipeline, not from live pdb-analytics. Make it a data-release step that writes the files into the run's output, and have vfb-release promote them the way it does the NeuronBridge map. We can then check them on p3 before a release, and the release gets no extra manual step.
Don't refuse files on a release mismatch. During a release two pdb versions are live at once (last week pdb-analytics was on the new run while the main pods were still on the old one for most of a day). A strict match would return 503 for that whole window. Serve the last good graphs and report in the response which release they came from.
Run it as its own small deployment. Same VFBquery image started in a circuit mode, with /circuit_paths routed to it. That keeps the 20 API workers light, stops a graph load or memory problem affecting term info, and avoids one search process inside the pod serialising every request.
Skip step 2 of the plan (changing the cost in gds_projections.sh). Option 2 retires that script, so leave the current browser on its existing scoring until it switches to the endpoint.
Two things to settle before building:
Which class numbers are canonical. The Upstream/Downstream class connectivity tables already show class-to-class figures, worked out by a different rule. The new graph assigns one leaf class per neuron and scores by input fraction, so the same pair of classes will show different numbers in two places. Either the tables move to the new class edges or the docs and MCP guidance say why they differ.
Other users of the cb_ graphs. In our repos only the geppetto-vfb circuit browser queries them, so retiring the projections is safe on our side once the browser has switched. We can't see whether anyone outside runs Cypher against them on public pdb; worth a line in the release notes when they go.
Optional: publish the class edge files as a download. A per-connectome class connectivity table is useful to users directly.
Thanks @Robbie1977. I agree with all four changes, and I'll update the plan comment to match. What they mean on the VFBquery side:
Pipeline build:vfb_circuit_classes.build() already takes the Neo4j endpoint as an argument, so the pipeline step can run it against the run's own database. I'll add the neuron edge files to its output, since only the class files are written at the moment. Each file will record the release it was built from in its header.
No refusal on a release mismatch: VFBquery will serve the last good graphs it has, and every /circuit_paths response will state the release they came from.
Separate deployment: I'll add a circuit mode that loads the graphs and serves only /circuit_paths (plus a health check that reports the loaded release). The routing and the deployment are yours.
No change to gds_projections.sh: agreed. The −log(inprop) cost will only go into the new endpoint.
Things to settle
Which class numbers are canonical. I don't think the tables should move to the new class edges, because the two answer different questions:
Upstream/Downstream class connectivity tables
Circuit class graph
Neurons counted for class X
every neuron typed as X or any subclass of X
only neurons whose single leaf type is X
Partner classes
rolled up to every ancestor class
leaf classes only
Datasets
pooled
kept separate
Figures
total N, connected N, % connected, pairs, total and average weight
synapses, pairs, input fraction (and output fraction where totals exist)
The graph uses only leaf classes so that each neuron is in exactly one node. If ancestor classes were nodes as well, the same neurons would sit in several overlapping nodes:
Hubs: broad classes such as "adult neuron" or "Kenyon cell" would connect to almost everything. The shortest paths would then run through them and say little about the circuit.
Double counting: a path could pass through the same neurons twice under different class names, for example KCab-p → KCab.
Diluted scores: a broad class's input fraction is an average over many unrelated neurons, so its edge scores aren't comparable with those of cell types.
Broad terms still work as query terms. A search for "Kenyon cell" starts from all the leaf classes under it, through the temporary start node, so they act as a start or end point but are never stepped through in the middle of a path.
The only figures in both are synapses and pairs. They will differ for the same pair of classes because of the roll-up, the pooling and the neurons the graph leaves out (in FlyWire, the 5.6% that have no single leaf type). If the tables used the class edges instead, queries on broad terms such as KC would lose their roll-up, and neurons left out of the graph would disappear from the tables too.
My proposal is to keep both:
/circuit_paths responses and the MCP tool describe their edge score as an input fraction within one dataset, and say that neurons without a single leaf type are left out.
The docs and MCP guidance have a short section on why the two sets of figures differ, with the table above.
Optionally, add a per-dataset input-fraction column to the class connectivity tables later, if users ask for it. This would be a separate change.
Other users of the cb_ graphs. Agreed. They stay until the geppetto-vfb browser has switched to /circuit_paths, and the release that removes them gets a release note. The comment at line 8 of geppetto-vfb's circuitBrowserConfiguration.js ("rebuilt per KB load by the polishing") is out of date, so it can be removed at the same time.
Class edge downloads: yes, I'm happy to publish them. I'll write the column descriptions and the source release into the file headers. I'll also publish the build report alongside them, which lists the neurons left out and links to the curation issues (VirtualFlyBrain/connectome-curation#1, #2), so users can see what the files don't cover.
Agreed on keeping both sets of class figures, with the docs and MCP section explaining the difference. Your table makes the case.
Layout, following the NeuronBridge map and RELEASED:
Run output:pipeline-out/<run>/circuit/<connectome>/ with neuron_edges.tsv.gz, class_edges.tsv.gz, neuron_classes.tsv.gz (each neuron's assigned class) and report.tsv (neurons left out). <connectome> is the same key the cb_ graphs use. Gzipped TSV with a header row, and the release and column descriptions as # lines at the top.
Manifest:pipeline-out/<run>/circuit/manifest.json, written last: run, datasets, file names, row counts and sha256 per file. The service treats a folder without a manifest as incomplete.
Release: I'll add a circuit-install step to vfb-release that copies the folder to pipeline-out/circuit/<run>/ and then rewrites pipeline-out/circuit/CURRENT (temp file and rename). The service mounts pipeline-out read-only, polls CURRENT, loads that run, and swaps only once it has loaded. Rollback is rewriting CURRENT.
p3: the test deployment can point at pipeline-out/<run>/circuit/ directly, so the graphs can be checked before a release.
So on your side: take the output folder as an argument, write the manifest last, and have circuit mode take either a fixed folder or a CURRENT pointer to follow. I'll do the workflow step, the deployment and the routing once the endpoint runs offline. The public download can come from the same files afterwards.
With no connectomes listed, it builds every Connectome in the database. The folder keys are the Connectome short_forms, which match the cb_ graph names.
--endpoint points it at the run's own database. It defaults to pdb-analytics.
Any existing manifest.json is deleted at the start. The new one is written last, via a temporary file and a rename, once every connectome has been built.
Each TSV starts with # lines giving the title, connectome, run, build time, endpoint, builder version and column descriptions, then a header row. The gzip files are written with a fixed timestamp, so the same content always gives the same sha256.
Tested against pdb-analytics:
FlyWire took about 4 minutes. Its neuron edges match cb_flywire783 exactly: 7,595,967.
L1EM took a few seconds. It has 157 more edges than cb_catmaid_l1em, and all of them are autapses: the Cypher pattern behind the cb_ graphs can't match a neuron to itself. I've kept them, as they count in the neurons' synapse totals, and the path search never uses self-loops.
Male CNS should take about twice as long as FlyWire.
Three changes to your layout. Please say if any of them don't suit:
One extra file, classes.tsv.gz: class id, label, symbol and number of neurons per class. The service needs labels for responses, and putting them on every class edge would repeat them across 874k rows for FlyWire.
One extra file, summary.md: a short human-readable summary of the build, covering counts per status, the commonest reasons neurons are left out and possible new axis classes. It isn't listed in the manifest and the service doesn't read it, so you could leave it out of what's promoted.
Extra columns in neuron_edges.tsv.gz:inprop_in and inprop_out per edge, so the neuron graph can use the −log(inprop) cost without a separate file of neuron totals.
report.tsv lists each neuron left out with its status (no_leaf, multi_leaf, only_axis, untyped) and the types involved.
Next on my side: circuit mode, which loads a fixed folder or follows CURRENT, then /circuit_paths.
Thanks @Clare72, all three changes are fine: classes.tsv.gz, summary.md (it gets copied along but nothing reads it), and the inprop_in/inprop_out columns.
On the cluster side, vfb-k8s#159 added the circuit-install step to vfb-release, a vfbquery-circuit deployment (0 replicas until your circuit mode is in an image) and /circuit_paths routing on api/v3-cached/vfbquery, bypassing v3-cached. vfb-k8s#160 reads your manifest shape and adds a circuit-graphs step to vfb-data-release that runs your module against the run's own PDB after polishing.
Two requests:
The CLI needs a way to pass Neo4j credentials (--user/--password, or env vars). The run's PDB isn't on the public neo4j/vfb login; for now the step patches Neo4jConnect from outside, which I'd like to drop.
For circuit mode, the deployment currently sets VFBQUERY_CIRCUIT_MODE=true, VFBQUERY_CIRCUIT_DIR=/pipeline-out/circuit (holds CURRENT and <run>/) and VFBQUERY_CIRCUIT_POLL=60. Happy to rename them to whatever you use; just tell me the names.
Thanks @Robbie1977, and thanks for 3029877, which is the credentials change. The circuit-graphs step can now set NEO4J_PASSWORD from the pipeline-neo4j secret (and NEO4J_USER if it isn't neo4j) and call python -m vfbquery.vfb_circuit_classes --run … --out … --endpoint … directly, without the patch.
Circuit mode env names. Please use these in circuit.yaml:
Setting
Name
Value
mode
VFBQUERY_MODE
circuit
folder holding CURRENT
VFBQUERY_CIRCUIT_ROOT
/pipeline-out/circuit
poll interval (s)
VFBQUERY_CIRCUIT_POLL
60
search processes
VFBQUERY_CIRCUIT_WORKERS
2 (default)
VFBQUERY_CIRCUIT_DIR is for a single fixed run folder, the one holding manifest.json. That suits p3: VFBQUERY_CIRCUIT_DIR=/pipeline-out/<run>/circuit. Set either _DIR or _ROOT, not both. With the names as they are now, the pod would start as the normal API (VFBQUERY_CIRCUIT_MODE isn't read), and _DIR=/pipeline-out/circuit would be refused for having no manifest.
The readiness probe on /health fits: it returns 503 until the first run has loaded, then 200 with the run name. /status shows what's loaded, what's loading and the last error.
Memory. The 8Gi limit is likely too low. FlyWire alone peaks at about 2.6 GB while loading, so all eight datasets will probably need 8–10 GB. While a new run is being swapped in, the old one stays in memory until the new one has loaded, which roughly doubles that for a minute or so. Could we start at a request of about 10Gi and a limit of about 20Gi, then adjust once we've seen real figures on p3? If that's too much to reserve per pod, I can add an option to drop the old run before loading the new one. Each pod would then return 503 while it reloads, and with two replicas and anti-affinity it's mainly a matter of the two not reloading at the same moment.
Done:#147 merged and released as v1.22.70 (image and PyPI). On the cluster: vfb-k8s#159, #160, #161 and #162 are live: circuit-graphs in vfb-data-release (off by default, vfbquery-ref=v1.22.70, credentials via NEO4J_PASSWORD), circuit-install in vfb-release, and vfbquery-circuit on v1.22.70 with your env names, /circuit_paths routed to it, 0 replicas. The main API is on v1.22.70 too.
Memory: agreed, 10Gi request / 20Gi limit in vfb-k8s#163. Keep the old run in memory during a swap for now; we can revisit the drop-first option if the figures make it necessary.
Next: the next data release runs with circuit-graphs=true; after vfb-release installs the graphs we scale vfbquery-circuit to 2 and check /circuit_paths. Still open on your side: the MCP find_circuit_paths tool, then the geppetto-vfb browser switch and retiring the cb_ projections with a release note.
/circuit_paths is live: https://api.virtualflybrain.org/circuit_paths?source=FBbt_00100484&target=FBbt_00004020&k=3 (also on v3-cached and vfbquery, routed straight to vfbquery-circuit, not cached by v3-cached).
Graphs: release 20261115, all 8 connectomes, built from pdb-analytics with vfb_circuit_classes (30 min, male CNS ~10 min of it) and installed with vfb-releasecircuit-install; CURRENT = 20261115. FlyWire neuron edges 7,595,967, matching cb_flywire783. From the next data release they are built in the pipeline (circuit-graphs=true).
Serving: two vfbquery-circuit pods on v1.22.71; load 98 s, about 4.3 GiB each, so the 10Gi/20Gi settings have room for a swap. Example above answers in about 0.7 s: LC12 → PVLP100 → DNp01 in both FlyWire and male CNS, LC12 → PVLP025 → PVLP151 → DNp01 in BANC.
Fix on the way: v1.22.70's scanner guard 404'd /circuit_paths for every request through the ingress (localhost tests count as trusted, so the Class-level circuit graphs and /circuit_paths (#114) #147 tests passed). #148 adds it to the allowlist and docs with a test that every circuit-mode route is reachable; released as v1.22.71, pinned in vfb-k8s#166.
Still open: the MCP find_circuit_paths tool, then the geppetto-vfb circuit browser switch and retiring the cb_ projections with a release note.
Memory: measured per circuit pod with all eight connectomes: 4.7–5.0 GiB (cgroup memory.current, peak 6.0 GiB), well inside 10Gi/20Gi, so it stays at 2 replicas. Each of the three processes shows ~4.3 GB RSS but only ~1.55 GB PSS: the workers share the graphs with the server.
Swap leak fixed: workers forked at a swap kept the replaced run until the next one, so each pod would have carried two runs after its first swap. #149 drops other runs in new workers and calls gc.freeze() before forking; released as v1.22.72, live via vfb-k8s#169. The first real swap comes with the next data release; I'll check memory settles back to one run then.
Slow case:instance_graph=true with k=10 (LC12 → giant fibre) took 35 s; the same query without instance_graph takes ~0.5 s and other queries up to 2 s. @Clare72, worth a lower cap on k/instance_k when instance_graph is on, or a note in the docs?
Activity
Clare72 commentedon Oct 1, 2026
How it works today
Proposed design
apart.
Suggested order
The MCP part of the issue can ship after steps 1–3, without waiting on the browser work.
Decisions for you
Clare72 commentedon Oct 1, 2026
Implications if we changed cost formula for instances too:
but I think we maybe should for consistency
Clare72 commentedon Oct 27, 2026
Plan for class-level circuit paths and MCP access
This replaces the earlier plan in this thread. Measurements are from the PDB on 2026-10-27.
Prerequisites now live
total_upstream/total_downstream) are on 559k neurons. Every connectome edge's target has a total, and no edge exceeds it, so inprop is always in (0, 1].total_downstreamis missing for the CATMAID datasets.cb_<Site>are built at pod start bygds_projections.sh(docker-vfb-neo4j-productiondb, branchpdb-k8s). geppetto-vfb'sbuild_connectome_projections.shis a stale copy that nothing runs.Scoring (the same at neuron and class level)
normalise=outputuses A's total output instead ("where does A's output go?" rather than "what drives B?"); unavailable for L1EM and FAFB CATMAID until they have output totals.normalise=output, the mirror image.Classes
One class per neuron per connectome, fully typed classes only:
Without step 1, about 9–14k neurons each in FlyWire, BANC and male CNS would have two leaf types (a lineage class plus their cell type). With it, very few do: 395 in L1EM, 292 in male CNS and under 40 elsewhere. These look like annotation problems (e.g. motor neurons typed to all three segments), so they are reported rather than settled by a tie-break. The build writes a per-connectome report of left-out neurons.
Leaf types are used at the ends and in the middle of paths. A class with a subclass used in the same dataset is never a node. There are no "not further typed" remainder nodes. The response reports how many neurons each dataset left out. Follow-up curation is tracked in VirtualFlyBrain/connectome-curation#1 (neurons with no leaf type) and VirtualFlyBrain/connectome-curation#2 (neurons with more than one).
Query terms expand to the fully typed classes beneath them in each dataset (or the term itself, if fully typed). Broad terms just mean more classes are considered.
Search
cb_GDS graphs as now, with cost changed from5000 − weightto −log(inprop).instance_graph=true: for each of the best class paths, return neuron chains: for each hop take the neuron edges between consecutive classes and run a layered search for the k best chains. Several neurons can sit at each end.query_connectivity.Steps, by repo
gds_projections.sh: switch thecb_cost to −log(inprop), keeping the raw weight for the browser's filter. Before switching, compare old and new paths on known circuits (olfactory PN→lateral horn, KC→MBON, LC→descending neurons): the answer changes from "fewest hops" to "strongest input chain".GET /circuit_paths(newvfb_circuit.py, route inha_api.py): parameters for the two ends,k, minimum synapses, minimum inprop,normalise,exclude_dbsandinstance_graph. It returns 503 if a graph is missing, uses the cache and worker pool, and has tests.find_circuit_paths: a thin wrapper, plus guidance inLLM_GUIDANCE.mdon when to use it rather thanquery_connectivityand what the score means.has_connected_instancestag so classes can be offered in the browser search./circuit_pathsinstead of building Cypher, accepts classes in the search box and in Term Info's "Add to Circuit Browser", shows results per dataset and multi-instance ends, updates the jest tests, and deletes the stale script.Later, possibly
Clare72 commentedon Nov 17, 2026
Where should the neuron and class graphs live?
@Robbie1977, your view would be useful here, as it affects the pdb pods and the VFBquery deployment.
Where things stand
cb_<connectome>, built on every pdb pod at start bygds_projections.sh(docker-vfb-neo4j-productiondb,pdb-k8s). The eight together hold 37M edges and use about 960 MiB per pod. geppetto-vfb runs Yen's on them via Cypher.circuit-class-graph(vfb_circuit_classes.py) and has been run for L1EM and FlyWire. It uses exactly the same neurons and edges as thecb_graphs. FlyWire comes to 7,318 classes and 874k class edges, built in about 3 minutes from pdb-analytics. It currently writes TSVs; it isn't stored anywhere yet.I'd like both sets of graphs in the same place. There are two options.
Measured (FlyWire, Yen's, k=5)
The GDS times were measured over HTTP on pdb-analytics and the igraph times on a laptop. Speed is similar either way, so it doesn't decide this. Male CNS is the largest graph, with about twice FlyWire's edges.
Option 1: both in the PDB (GDS)
Memory: class graphs would add a few hundred MiB per pod to the ~960 MiB already used by
cb_. That is negligible on 192 GiB pods.Build: the loader job builds the class graph once per release and writes it into the golden volume. Pods then project
cbc_graphs at start, adding perhaps 30–60 s to the ~4 min.Consistency: the class and neuron graphs always come from the same release, with no extra files to publish.
Limitation: GDS can't add temporary nodes per request, so the agreed approach (a temporary start node joined to every source class, and an end node joined from every target class) doesn't work. Broad query terms would need a workaround:
That needs a cap for very broad terms. Mixed class → neuron queries would also need a reversed copy of each neuron graph (about +1 GB per pod).
Other costs: a build step in the loader image, and all search load stays on pdb (2–4 pods).
Option 2: both in VFBquery
gds_projections.shcould be retired. pdb pods would then start about 4 minutes faster and use about 1 GB less each.instance_graphare all straightforward. It can also be tested offline in CI.Recommendation
Option 2, mainly because the class search depends on per-request temporary nodes, which only work in memory, and the browser is moving to call VFBquery anyway. Option 1 is better if we want the graphs to stay queryable by Cypher in Neo4j, or if a few extra GB on VFBquery is a problem.
Robbie1977 commentedon Nov 18, 2026
I agree with Option 2: both sets of graphs in VFBquery. The class search needs per-request temporary nodes, and taking the projections out of pdb start-up helps us more than the extra memory in VFBquery costs. The pdb pods now roll one at a time, so a start that is about 4 minutes faster shortens the time live pdb spends on a single pod.
Four changes to how we do it:
vfb-releasepromote them the way it does the NeuronBridge map. We can then check them on p3 before a release, and the release gets no extra manual step./circuit_pathsrouted to it. That keeps the 20 API workers light, stops a graph load or memory problem affecting term info, and avoids one search process inside the pod serialising every request.gds_projections.sh). Option 2 retires that script, so leave the current browser on its existing scoring until it switches to the endpoint.Two things to settle before building:
cb_graphs. In our repos only the geppetto-vfb circuit browser queries them, so retiring the projections is safe on our side once the browser has switched. We can't see whether anyone outside runs Cypher against them on public pdb; worth a line in the release notes when they go.Optional: publish the class edge files as a download. A per-connectome class connectivity table is useful to users directly.
Clare72 commentedon Nov 18, 2026
Thanks @Robbie1977. I agree with all four changes, and I'll update the plan comment to match. What they mean on the VFBquery side:
vfb_circuit_classes.build()already takes the Neo4j endpoint as an argument, so the pipeline step can run it against the run's own database. I'll add the neuron edge files to its output, since only the class files are written at the moment. Each file will record the release it was built from in its header./circuit_pathsresponse will state the release they came from./circuit_paths(plus a health check that reports the loaded release). The routing and the deployment are yours.gds_projections.sh: agreed. The −log(inprop) cost will only go into the new endpoint.Things to settle
Which class numbers are canonical. I don't think the tables should move to the new class edges, because the two answer different questions:
The graph uses only leaf classes so that each neuron is in exactly one node. If ancestor classes were nodes as well, the same neurons would sit in several overlapping nodes:
Broad terms still work as query terms. A search for "Kenyon cell" starts from all the leaf classes under it, through the temporary start node, so they act as a start or end point but are never stepped through in the middle of a path.
The only figures in both are synapses and pairs. They will differ for the same pair of classes because of the roll-up, the pooling and the neurons the graph leaves out (in FlyWire, the 5.6% that have no single leaf type). If the tables used the class edges instead, queries on broad terms such as KC would lose their roll-up, and neurons left out of the graph would disappear from the tables too.
My proposal is to keep both:
/circuit_pathsresponses and the MCP tool describe their edge score as an input fraction within one dataset, and say that neurons without a single leaf type are left out.Other users of the
cb_graphs. Agreed. They stay until the geppetto-vfb browser has switched to/circuit_paths, and the release that removes them gets a release note. The comment at line 8 of geppetto-vfb'scircuitBrowserConfiguration.js("rebuilt per KB load by the polishing") is out of date, so it can be removed at the same time.Class edge downloads: yes, I'm happy to publish them. I'll write the column descriptions and the source release into the file headers. I'll also publish the build report alongside them, which lists the neurons left out and links to the curation issues (VirtualFlyBrain/connectome-curation#1, #2), so users can see what the files don't cover.
Next steps on my side
/circuit_pathsin VFBquery, tested offline against the L1EM and FlyWire files.find_circuit_pathstool, once the endpoint is up.Where would you like the pipeline to put the files, and in what layout? I'll match the build's output to it.
Robbie1977 commentedon Nov 18, 2026
Agreed on keeping both sets of class figures, with the docs and MCP section explaining the difference. Your table makes the case.
Layout, following the NeuronBridge map and
RELEASED:pipeline-out/<run>/circuit/<connectome>/withneuron_edges.tsv.gz,class_edges.tsv.gz,neuron_classes.tsv.gz(each neuron's assigned class) andreport.tsv(neurons left out).<connectome>is the same key thecb_graphs use. Gzipped TSV with a header row, and the release and column descriptions as#lines at the top.pipeline-out/<run>/circuit/manifest.json, written last: run, datasets, file names, row counts and sha256 per file. The service treats a folder without a manifest as incomplete.circuit-installstep tovfb-releasethat copies the folder topipeline-out/circuit/<run>/and then rewritespipeline-out/circuit/CURRENT(temp file and rename). The service mountspipeline-outread-only, pollsCURRENT, loads that run, and swaps only once it has loaded. Rollback is rewritingCURRENT.pipeline-out/<run>/circuit/directly, so the graphs can be checked before a release.So on your side: take the output folder as an argument, write the manifest last, and have circuit mode take either a fixed folder or a
CURRENTpointer to follow. I'll do the workflow step, the deployment and the routing once the endpoint runs offline. The public download can come from the same files afterwards.Write circuit graphs in the pipeline layout agreed in #114
Clare72 commentedon Nov 18, 2026
Thanks @Robbie1977. The build on #147 now writes your layout:
Connectomein the database. The folder keys are theConnectomeshort_forms, which match thecb_graph names.--endpointpoints it at the run's own database. It defaults to pdb-analytics.manifest.jsonis deleted at the start. The new one is written last, via a temporary file and a rename, once every connectome has been built.#lines giving the title, connectome, run, build time, endpoint, builder version and column descriptions, then a header row. The gzip files are written with a fixed timestamp, so the same content always gives the same sha256.Tested against pdb-analytics:
cb_flywire783exactly: 7,595,967.cb_catmaid_l1em, and all of them are autapses: the Cypher pattern behind thecb_graphs can't match a neuron to itself. I've kept them, as they count in the neurons' synapse totals, and the path search never uses self-loops.Three changes to your layout. Please say if any of them don't suit:
classes.tsv.gz: class id, label, symbol and number of neurons per class. The service needs labels for responses, and putting them on every class edge would repeat them across 874k rows for FlyWire.summary.md: a short human-readable summary of the build, covering counts per status, the commonest reasons neurons are left out and possible new axis classes. It isn't listed in the manifest and the service doesn't read it, so you could leave it out of what's promoted.neuron_edges.tsv.gz:inprop_inandinprop_outper edge, so the neuron graph can use the −log(inprop) cost without a separate file of neuron totals.report.tsvlists each neuron left out with its status (no_leaf, multi_leaf, only_axis, untyped) and the types involved.Next on my side: circuit mode, which loads a fixed folder or follows
CURRENT, then/circuit_paths.Add circuit mode serving /circuit_paths (#114)
Robbie1977 commentedon Nov 18, 2026
Thanks @Clare72, all three changes are fine:
classes.tsv.gz,summary.md(it gets copied along but nothing reads it), and theinprop_in/inprop_outcolumns.On the cluster side, vfb-k8s#159 added the
circuit-installstep tovfb-release, avfbquery-circuitdeployment (0 replicas until your circuit mode is in an image) and/circuit_pathsrouting on api/v3-cached/vfbquery, bypassing v3-cached. vfb-k8s#160 reads your manifest shape and adds acircuit-graphsstep tovfb-data-releasethat runs your module against the run's own PDB after polishing.Two requests:
--user/--password, or env vars). The run's PDB isn't on the publicneo4j/vfblogin; for now the step patchesNeo4jConnectfrom outside, which I'd like to drop.VFBQUERY_CIRCUIT_MODE=true,VFBQUERY_CIRCUIT_DIR=/pipeline-out/circuit(holdsCURRENTand<run>/) andVFBQUERY_CIRCUIT_POLL=60. Happy to rename them to whatever you use; just tell me the names.Clare72 commentedon Nov 18, 2026
Thanks @Robbie1977, and thanks for 3029877, which is the credentials change. The
circuit-graphsstep can now setNEO4J_PASSWORDfrom thepipeline-neo4jsecret (andNEO4J_USERif it isn'tneo4j) and callpython -m vfbquery.vfb_circuit_classes --run … --out … --endpoint …directly, without the patch.Circuit mode env names. Please use these in
circuit.yaml:VFBQUERY_MODEcircuitCURRENTVFBQUERY_CIRCUIT_ROOT/pipeline-out/circuitVFBQUERY_CIRCUIT_POLL60VFBQUERY_CIRCUIT_WORKERS2(default)VFBQUERY_CIRCUIT_DIRis for a single fixed run folder, the one holdingmanifest.json. That suits p3:VFBQUERY_CIRCUIT_DIR=/pipeline-out/<run>/circuit. Set either_DIRor_ROOT, not both. With the names as they are now, the pod would start as the normal API (VFBQUERY_CIRCUIT_MODEisn't read), and_DIR=/pipeline-out/circuitwould be refused for having no manifest.The readiness probe on
/healthfits: it returns 503 until the first run has loaded, then 200 with the run name./statusshows what's loaded, what's loading and the last error.Memory. The 8Gi limit is likely too low. FlyWire alone peaks at about 2.6 GB while loading, so all eight datasets will probably need 8–10 GB. While a new run is being swapped in, the old one stays in memory until the new one has loaded, which roughly doubles that for a minute or so. Could we start at a request of about 10Gi and a limit of about 20Gi, then adjust once we've seen real figures on p3? If that's too much to reserve per pod, I can add an option to drop the old run before loading the new one. Each pod would then return 503 while it reloads, and with two replicas and anti-affinity it's mainly a matter of the two not reloading at the same moment.
Class-level circuit graphs and /circuit_paths (#114) (#147)
Robbie1977 commentedon Nov 18, 2026
Thanks @Clare72. Where things stand:
circuit-graphsinvfb-data-release(off by default,vfbquery-ref=v1.22.70, credentials viaNEO4J_PASSWORD),circuit-installinvfb-release, andvfbquery-circuiton v1.22.70 with your env names,/circuit_pathsrouted to it, 0 replicas. The main API is on v1.22.70 too.circuit-graphs=true; aftervfb-releaseinstalls the graphs we scalevfbquery-circuitto 2 and check/circuit_paths. Still open on your side: the MCPfind_circuit_pathstool, then the geppetto-vfb browser switch and retiring thecb_projections with a release note.Robbie1977 commentedon Nov 18, 2026
/circuit_pathsis live:https://api.virtualflybrain.org/circuit_paths?source=FBbt_00100484&target=FBbt_00004020&k=3(also on v3-cached and vfbquery, routed straight tovfbquery-circuit, not cached by v3-cached).vfb_circuit_classes(30 min, male CNS ~10 min of it) and installed withvfb-releasecircuit-install;CURRENT= 20261115. FlyWire neuron edges 7,595,967, matchingcb_flywire783. From the next data release they are built in the pipeline (circuit-graphs=true).vfbquery-circuitpods on v1.22.71; load 98 s, about 4.3 GiB each, so the 10Gi/20Gi settings have room for a swap. Example above answers in about 0.7 s: LC12 → PVLP100 → DNp01 in both FlyWire and male CNS, LC12 → PVLP025 → PVLP151 → DNp01 in BANC./circuit_pathsfor every request through the ingress (localhost tests count as trusted, so the Class-level circuit graphs and /circuit_paths (#114) #147 tests passed). #148 adds it to the allowlist and docs with a test that every circuit-mode route is reachable; released as v1.22.71, pinned in vfb-k8s#166.find_circuit_pathstool, then the geppetto-vfb circuit browser switch and retiring thecb_projections with a release note.Robbie1977 commentedon Nov 18, 2026
Follow-up on memory and one slow case:
memory.current, peak 6.0 GiB), well inside 10Gi/20Gi, so it stays at 2 replicas. Each of the three processes shows ~4.3 GB RSS but only ~1.55 GB PSS: the workers share the graphs with the server.gc.freeze()before forking; released as v1.22.72, live via vfb-k8s#169. The first real swap comes with the next data release; I'll check memory settles back to one run then.instance_graph=truewithk=10(LC12 → giant fibre) took 35 s; the same query withoutinstance_graphtakes ~0.5 s and other queries up to 2 s. @Clare72, worth a lower cap onk/instance_kwheninstance_graphis on, or a note in the docs?Circuit Browser: use /circuit_paths and allow neuron types (#1880)
Bound the time circuit searches spend on neuron chains (#152)
V3 preview release plus improved Circuit Browser (#1893)
Merge master into development to rejoin the branches (#1904)
Clare72 commentedon Nov 29, 2026
The class-level Circuit Browser is now live on v2 and v3 (geppetto-vfb v3.0.0.0, VirtualFlyBrain/vfb-k8s#196), so closing this.
What shipped:
/circuit_paths(Class-level circuit graphs and /circuit_paths (#114) #147, Serve /circuit_paths to clients outside the cluster #148, Keep one run per circuit worker and freeze the graphs before forking #149). Also example neuron chains (Circuit paths: time limit on example neuron chains #152), the list of searchable classes at/circuit_paths/terms(Circuit paths: list the classes a search can find #153), and reasons and type symbols for neurons left out of the class graph (Circuit paths: say why a neuron has no class #151, Circuit paths: symbols for the types of left-out neurons #154)./circuit_pathsand accepts neuron types at either end (Circuit Browser: use /circuit_paths and allow neuron types geppetto-vfb#1880), with later layout, search and help improvements (geppetto-vfb #1884–#1892, #1900–#1902).find_circuit_paths(Add find_circuit_paths (VFBquery#114) VFB3-MCP#23, Error parsing data in function 'term_info_parse_object' in vfb_queries.py #24; v1.13.0).Left for later: retiring the
cb_GDS projections that pdb still builds on startup for the old browser.