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
| **Performance** | Can take minutes — use higher weight (≥50 for both-ends) or group_by_class | Fast (pre-computed) |
292
+
### Step 1: Pick the Right Query
302
293
303
-
### Performance Notes
294
+
**Rule 1 — User has an individual neuron ID (starts with `VFB_`):**
295
+
- To see all synaptic partners of that neuron → use `run_query` with query_type `NeuronNeuronConnectivityQuery`
296
+
- To see which brain regions that neuron connects to → use `run_query` with query_type `NeuronRegionConnectivityQuery`
297
+
- To see presynaptic inputs with neurotransmitter types → use `run_query` with query_type `NeuronInputsTo`
298
+
- If the user specifically asks for a class-level query (e.g. "what classes connect to neurons like this one?"), first call `get_term_info` on the VFB ID to find its neuron class (`FBbt_...` ID), then use that class ID with the queries in Rule 2.
304
299
305
-
- `query_connectivity` is **not pre-cached** — it runs live queries across all connectome datasets, so responses can take up to several minutes
306
-
- **Both-ends queries** (upstream_type AND downstream_type both set) with low weight thresholds can timeout on large neuron classes — start with `weight ≥ 50`
307
-
- **Single-end queries** (only upstream_type or downstream_type) work well with `weight ≥ 10`
308
-
- Use `group_by_class=true` to get faster aggregated results instead of individual neuron-to-neuron rows
309
-
- Warn the user that connectivity queries may take a while before executing
300
+
**Rule 2 — User has a neuron class (starts with `FBbt_`) or a neuron type name (e.g. "Kenyon cell"):**
301
+
- To see downstream partner classes → use `run_query` with query_type `DownstreamClassConnectivity` (fast, pre-indexed)
302
+
- To see upstream partner classes → use `run_query` with query_type `UpstreamClassConnectivity` (fast, pre-indexed)
303
+
- To see region connectivity or neurotransmitter inputs for a neuron class → use the instance batch workflow described below
304
+
- To filter by **both** upstream AND downstream class at the same time, or to retrieve results that include data from multiple connectome datasets → use `query_connectivity` (slow, live query)
310
305
311
-
### Workflow
306
+
**Instance batch workflow — running individual neuron queries at the class level:**
307
+
308
+
Some queries (`NeuronRegionConnectivityQuery`, `NeuronInputsTo`) only work on individual neurons, not classes. To use them for a whole neuron class:
309
+
310
+
1. Get instances of the class: `run_query(id="FBbt_00003686", query_type="ListAllAvailableImages")`
311
+
2. Extract the VFB IDs from the results.
312
+
3. If there are many instances, tell the user how many there are and ask whether to query all of them or a subset.
313
+
4. Batch-query the instances: `run_query(id=["VFB_xxx", "VFB_yyy", ...], query_type="NeuronRegionConnectivityQuery")`
314
+
315
+
The `run_query` tool accepts an array of IDs and runs the query on all of them in parallel. Results are returned as a JSON object keyed by `"ID::query_type"`.
316
+
317
+
**Rule 3 — User asks about a brain region (e.g. "What connects to the lobula?"):**
318
+
- First use `search_terms` with `filter_types: ["neuron", "class"]` to find neuron classes in that region.
319
+
- Then apply Rule 2 for the neuron classes found.
320
+
321
+
**If unsure**, start with the `run_query` options listed in Rules 1–2. They are fast and cached. Only use `query_connectivity` when dual-end class filtering is specifically needed.
322
+
323
+
### Summary Table
324
+
325
+
| Query | Input | What it returns | Speed |
326
+
|-------|-------|----------------|-------|
327
+
| `NeuronNeuronConnectivityQuery` | Individual neuron VFB ID | All partner neurons with input/output weights | Fast (cached) |
328
+
| `NeuronRegionConnectivityQuery` | Individual neuron VFB ID | Brain regions with pre/postsynaptic terminal counts | Fast (cached) |
329
+
| `NeuronInputsTo` | Individual neuron VFB ID | Presynaptic partners with neurotransmitter types and weights | Fast (cached) |
330
+
| `DownstreamClassConnectivity` | Neuron class FBbt ID | Downstream partner classes with % connected, avg weight (includes data from all datasets) | Fast (pre-indexed) |
331
+
| `UpstreamClassConnectivity` | Neuron class FBbt ID | Upstream partner classes with % connected, avg weight (includes data from all datasets) | Fast (pre-indexed) |
332
+
| `query_connectivity` | Neuron class names or FBbt IDs | Connections between two neuron classes (includes data from all datasets) | Slow (1–5 min, live) |
333
+
334
+
### Step 2: Run the Query
335
+
336
+
#### For `run_query` connectivity queries (fast path)
337
+
338
+
1. Get the VFB ID or FBbt ID. If the user gave a name, use `search_terms` to find the ID first.
339
+
2. Call `get_term_info` on the ID. Check that the relevant query_type appears in the `Queries` array. If it does not, either the entity does not support that query type, or there are no results for it.
1. **Parse input** — Extract parameters using this inference table:
362
+
#### For `query_connectivity` (slow path — dual-end class-to-class)
314
363
315
-
| User says | Mode |
316
-
|-----------|------|
317
-
| "upstream of X", "inputs to X", "presynaptic to X" | set `downstream_type` = X |
318
-
| "downstream of X", "outputs from X", "postsynaptic to X" | set `upstream_type` = X |
319
-
| "between X and Y", "X to Y connections" | set both `upstream_type` = X, `downstream_type` = Y |
320
-
| "all connections from X" | set `upstream_type` = X only |
321
-
| "summarise by class", "aggregated" | set `group_by_class` = true |
364
+
1. **Check if you really need `query_connectivity`.** If the user asks about only one direction (e.g. "what is downstream of X?" or "what are the inputs to X?"), use `DownstreamClassConnectivity` or `UpstreamClassConnectivity` via `run_query` instead — they are much faster. Only use `query_connectivity` when the user specifies **both** upstream and downstream types.
2. **Confirm parameters** — Unless user explicitly specified all parameters, show planned query and ask to confirm:
368
+
| User says | Action |
369
+
|-----------|--------|
370
+
| "upstream of X", "inputs to X", "presynaptic to X" | Use `run_query` with `UpstreamClassConnectivity` on X. |
371
+
| "downstream of X", "outputs from X", "postsynaptic to X" | Use `run_query` with `DownstreamClassConnectivity` on X. |
372
+
| "between X and Y", "X to Y connections" | Use `query_connectivity` with `upstream_type` = X, `downstream_type` = Y |
373
+
| "summarise by class", "aggregated" | Use `query_connectivity` with `group_by_class` = true (this option is specific to `query_connectivity`) |
374
+
375
+
**Defaults for `query_connectivity`:** `weight` = 5, `exclude_dbs` = ["hb", "fafb"]
376
+
377
+
3. **Validate neuron type names.** Use `search_terms` with `filter_types: ["neuron", "class"]` to check the name is correct. If ambiguous, show candidates and ask user to pick.
378
+
379
+
4. **Confirm parameters with the user before running.** This query is slow. Show:
326
380
```
327
381
I'll query connectivity with these parameters:
328
382
- Upstream type: transmedullary neuron Tm1
329
-
- Downstream type: (any)
383
+
- Downstream type: T3 neuron
330
384
- Min. weight: 5
331
385
- Excluded DBs: hb, fafb
332
386
- Group by class: No
333
-
Shall I proceed, or would you like to change any of these?
387
+
This query may take several minutes. Shall I proceed?
334
388
```
335
389
336
-
3. **Validate neuron type names** — Use `search_terms` with `filter_types: ["neuron", "class"]` to validate/canonicalize labels. Skip if label is already clearly canonical (e.g., "GABAergic neuron"). If ambiguous or multiple candidates, show disambiguation list and ask user.
390
+
5. **Execute** — Call `query_connectivity` with confirmed parameters.
391
+
392
+
**Performance rules for `query_connectivity`:**
393
+
- Always start with the default `weight = 5`. There is no universal "good" weight — it varies by cell type.
394
+
- Single-end queries (only upstream or only downstream set) are **slower** than both-ends queries because they return more results. If the user only cares about one direction, prefer `DownstreamClassConnectivity` or `UpstreamClassConnectivity` via `run_query` instead — they are pre-indexed and fast.
395
+
- Use `group_by_class=true` for faster aggregated results.
396
+
- Only use `query_connectivity` when you need both ends filtered by class.
397
+
398
+
### Step 3: Present Results
399
+
400
+
**Always start with a query summary:**
401
+
```
402
+
Query: NeuronNeuronConnectivityQuery for VFB_00104glj
> **Tip:** If user asks about a brain region (e.g., "What connects to the lobula?"), first find neuron classes in that region using `search_terms`, then query connectivity for those specific classes.
416
+
**Result formatting:**
417
+
- **≤50 rows:** Show full table.
418
+
- **>50 rows:** Show top 20 sorted by weight descending. Include summary stats (total connections, unique partners, weight range). Note that results are truncated.
339
419
340
-
> **Tip:** If you have a VFB neuron ID (e.g., `VFB_...`), run `get_term_info` on it and look for the `FBbt_...` class identifier; use that as `upstream_type`/`downstream_type`.
420
+
**Column guide by query type:**
341
421
342
-
4. **Execute query** — Call `query_connectivity` with confirmed parameters.
**When to use:** User asks about the structure of a brain region, the types/subtypes of a cell class, or where something fits in the anatomical or cell type hierarchy.
| "What are the parts of the mushroom body?" | `part_of` | `descendants` |
459
+
| "What is the mushroom body part of?" | `part_of` | `ancestors` |
460
+
| "Where does the mushroom body fit in the brain?" | `part_of` | `both` |
461
+
| "What types of Kenyon cell are there?" | `subclass_of` | `descendants` |
462
+
| "What class of neuron is the Kenyon cell?" | `subclass_of` | `ancestors` |
463
+
| "Show me the Kenyon cell hierarchy" | `subclass_of` | `both` |
464
+
465
+
**Default:** Start with `max_depth=1` (direct parents/children only). If the user wants more detail, increase it. Use `max_depth=-1` with caution — broad terms can have thousands of descendants.
466
+
467
+
### Result Structure
468
+
469
+
- **Descendants** are returned as a **nested tree** for both relationship types (children contain their own children).
470
+
- **Ancestors** are returned as a **nested chain** for both relationship types.
471
+
- **`part_of` ancestors** are filtered to nervous system terms only (developmental lineage and generic structural terms are excluded).
472
+
- **`subclass_of` ancestors** are filtered to FBbt cell types only, stopping at "cell" (cross-ontology and non-cell ancestors are excluded).
- **`display`** — a pre-formatted text tree with large sibling groups shortened. Always present this directly to the user rather than reformatting the JSON.
490
+
- **`display_full`** — the same text tree with no shortening. Use this if the user asks to see all terms.
491
+
492
+
After showing the text tree, offer the user an interactive HTML version they can open in their browser. Construct the URL using this pattern:
- `get_term_info` (get VFB ID) → `run_query` with `NeuronNeuronConnectivityQuery`, `NeuronRegionConnectivityQuery`, or `NeuronInputsTo`
533
+
- `search_terms` (find term) → `get_hierarchy` (explore structure or taxonomy)
410
534
411
535
## How to Interpret Image Data
412
536
@@ -547,7 +671,11 @@ A term is a template brain if its `SuperTypes` array from `get_term_info` includ
547
671
- Neuron morphology: Search for neuron type with `filter_types: ["neuron"]` → get_term_info → check for SimilarMorphology
548
672
- Adult neurons with images: Search with `filter_types: ["neuron", "adult", "has_image"]`, `minimize_results: true`
549
673
- Brain regions: Search for anatomical terms with `filter_types: ["anatomy"]` → explore hierarchical relationships
550
-
- Connectivity: Search with `filter_types: ["has_neuron_connectivity"]` → run Connectivity queries
674
+
- Connectivity (individual neuron): Search with `filter_types: ["has_neuron_connectivity"]` → `get_term_info` → `run_query` with `NeuronNeuronConnectivityQuery`
675
+
- Connectivity (neuron class): Search with `filter_types: ["neuron", "class"]` → `run_query` with `DownstreamClassConnectivity` or `UpstreamClassConnectivity`
676
+
- Connectivity (class-to-class): Search with `filter_types: ["neuron", "class"]` → `query_connectivity` (both upstream and downstream types)
677
+
- Brain region structure: Search with `filter_types: ["anatomy"]` → `get_hierarchy` with `relationship: "part_of"`
678
+
- Cell type hierarchy: Search with `filter_types: ["neuron", "class"]` → `get_hierarchy` with `relationship: "subclass_of"`
551
679
- Datasets: Search with `filter_types: ["dataset"]` to find available datasets
552
680
- Exact term lookup: Use `auto_fetch_term_info: true` for immediate detailed information on exact matches
0 commit comments