> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Search in depth

> The eight steps of one search, what a hit carries, and the numbers you can tune.

`Searcher` reads concepts and the context tree through a `ConceptSource`, which any store can be. The [How it works](https://ladygraph.io.vn/concepts/how-it-works.md) page gives the outline. This page gives the steps.

## One search

**1. Serve filter**

Keep only servable concepts: `stable`, not merged, with at least one piece of evidence that is not stale and is allowed by the query's `access_filter`. The concept must also be at or above the required trust tier and match any hard `facets` (type, context, or an `extra` key).

**2. Entry**

Take the best contexts at each depth, and the best concepts, by cosine, within one depth at a time.

**3. Route**

A model, the decider, judges which child context probably holds the answer, level by level, and follows a child only above `min_route`. It looks at every depth together, not strictly top-down. This follows the "collapsed tree" idea of recursive summary trees.

**4. Judge**

The decider judges the concepts of the contexts it reached. A concept is returned only above `min_score`.

**5. Declared words**

A concept whose human-declared word appears in the question is returned with a fixed score, unless the decider scored it higher.

**6. Hop**

From the best concepts, follow typed relations in both directions, at most 2 hops and `fanout` per hop, with a visited set. A concept reached over one relation scores the seed's score times `decay` and the relation's weight. A relation to a concept that is not served is not followed.

**7. Gate**

Optionally, if no concept is as close as `min_cosine`, the decider is not asked and only declared-word concepts are returned.

**8. Resolve**

Optionally, read the live source to confirm each quote.

## What a hit carries

Each hit carries:

* `address`
* `score`
* `path`, which reads `query → concept → relation → … → concept`
* `evidence_id`
* `context_path`, the labels from the top level down
* `access_labels`
* when resolved, the `resolution` and the `content`

A hit can therefore always say why it is there.

## The query

A `Query` says where and how far to search. Lesson 1 builds one:

```python theme={null}
from ladygraph.core.query import Query

q = Query(scope="finance",                      # never crosses domains
          text="tiền tiếp khách tối đa bao nhiêu",
          seeds=5, hops=1, fanout=10,           # top 5 concepts, then one hop, at most 10 per hop
          relation_types=["DEFINES"],           # None means every traversable relation
          access_filter=["internal"],           # labels this reader is cleared for
          resolve=True)                         # also fetch the live quote through the resolver
```

`hops` is capped at 2. A larger value is rejected with a validation error.

## Tunable numbers

These are the fields of `SearchConfig`, with their defaults.

| Field | Default | Meaning |
| - | - | - |
| `per_depth` | 2 | Entry contexts taken at each depth, by cosine. |
| `entry_concepts` | 3 | Entry concepts taken by cosine. Their contexts are judged. |
| `beam` | 3 | Child contexts followed at each routing step. |
| `min_route` | 0.15 | A child context is followed only when its probability is at least this. |
| `min_score` | 0.2 | A concept is returned only when its probability in its context is at least this. |
| `max_options` | 60 | The largest option set sent to the decider. Larger sets are cut by cosine. |
| `decay` | 0.8 | A concept reached over one relation scores the seed's score times this. |
| `max_evidence` | 1 | Evidence pointers returned per concept. |
| `word_match` | `True` | A concept whose human-declared word is in the question is returned. |
| `word_score` | 0.9 | The score of such a concept, unless the decider scored it higher. |
| `min_cosine` | `None` | The relevance gate. Needs an embedder. Off by default. |

`Searcher` also keeps a `SearchStats` for the last search: the number of decider and embed calls, the entry, routed and judged contexts, the declared-word matches, the closest concept's cosine, and whether the gate refused the question. Use it in tests and to measure cost.

`min_route` and `min_score` are tuned values, not constants. Scores across levels may not be calibrated, so measure on your own question set. Search reads every servable concept on each call, and the vector column dominates that cost.

## The relevance gate

The decider only ranks options against each other, so on a small or vague index something always wins. With `SearchConfig(min_cosine=...)`, a question whose closest concept has a lower cosine gets no answer and costs no decider call. The gate is off by default, because a cosine depends on the embedder and on the index.

Measure the cut-off with `retrieval.calibrate(searcher, scope, off_topic=[...], on_topic=[...])`. It returns a suggestion and says when the two groups overlap.

On the sample blueprint, a cut-off of 0.64 to 0.66 refused 18 of 24 off-topic questions and kept all 27 answerable ones. It cut decider calls by 38%, about 40% less search time. Questions that share the domain's own words, such as an HR question in an IT index, still get through.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.