> ## 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.

# retrieval

> Search the index.

Retrieval: search over the context tree and the concept graph, using a `Decider` and an `Embedder`.

## `retrieval.calibrate`

Choosing `SearchConfig.min_cosine` for one embedder and one index.

#### `Calibration`

| Field | Type | Default |
| - | - | - |
| `off` | `dict[str, float]` | required |
| `on` | `dict[str, float]` | required |
| `suggested` | `float` | required |
| `separable` | `bool \| None` | required |

| Method | What it does |
| - | - |
| `(property)` | — |
| `(property)` | — |
| `(property)` | — |
| `summary(self) -> str` | — |

#### `calibrate`

```python theme={null}
calibrate(searcher: Searcher, scope: str, off_topic: Sequence[str], on_topic: Sequence[str] = (), margin: float = 0.02) -> Calibration
```

## `retrieval.searcher`

Search over the context tree and the concept graph (docs/DATASTURCTURE.md section 6).

#### `ConceptSource`

What the searcher reads.

Construct with `ConceptSource(*args, **kwargs)`.

| Method | What it does |
| - | - |
| `registry(self, scope: str) -> ContextRegistry` | — |
| `concepts_in(self, scope: str) -> Iterable[Concept]` | — |

#### `SearchConfig`

| Field | Type | Default |
| - | - | - |
| `per_depth` | `int` | `2` |
| `entry_concepts` | `int` | `3` |
| `beam` | `int` | `3` |
| `min_route` | `float` | `0.15` |
| `min_score` | `float` | `0.2` |
| `max_options` | `int` | `60` |
| `decay` | `float` | `0.8` |
| `max_evidence` | `int` | `1` |
| `word_match` | `bool` | `True` |
| `word_score` | `float` | `0.9` |
| `min_cosine` | `float \| None` | `None` |

#### `Searcher`

Construct with `Searcher(source: ConceptSource, decider: Decider, embedder: Embedder \| None = None, *, ontology: Ontology \| None = None, resolvers: Mapping[str, Resolver] \| None = None, config: SearchConfig \| None = None, min_trust: Literal['unverified', 'machine', 'human'] = 'unverified', resolve_timeout_s: float = 2.0, clock=<function Searcher.<lambda> at 0x1065ae340>)`.

| Method | What it does |
| - | - |
| `option_sets(self, scope: str) -> list[PickSpec]` | Every option set a search of `scope` asks the decider about: the children of each context (and of the top level), and the concepts each context holds. |
| `prepare(self, scope: str) -> int` | Hand the option sets to the decider when it can use them. |
| `search(self, q: Query) -> list[Hit]` | — |
| `asearch(self, q: Query) -> list[Hit]` | — |
| `best_cosine(self, q: Query) -> float \| None` | The cosine between the question and the closest servable concept, or None without an embedder or concepts. |

#### `SearchStats`

What the last search did, for tests and for measuring cost.

| Field | Type | Default |
| - | - | - |
| `decider_calls` | `int` | `0` |
| `embed_calls` | `int` | `0` |
| `entry_contexts` | `list[str]` | factory |
| `routed_contexts` | `list[str]` | factory |
| `judged_contexts` | `list[str]` | factory |
| `word_matches` | `dict[str, str]` | factory |
| `best_cosine` | `float \| None` | `None` |
| `gated` | `bool` | `False` |
| `errors` | `list[str]` | factory |


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