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

> Tìm kiếm trong chỉ mục.

Truy xuất: tìm kiếm trên cây ngữ cảnh và đồ thị khái niệm, dùng một `Decider` và một `Embedder`.

## `retrieval.calibrate`

Chọn `SearchConfig.min_cosine` cho một bộ nhúng và một chỉ mục.

#### `Calibration`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `off` | `dict[str, float]` | required |
| `on` | `dict[str, float]` | required |
| `suggested` | `float` | required |
| `separable` | `bool \| None` | required |

| Phương thức | Làm gì |
| - | - |
| `(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`

Tìm kiếm trên cây ngữ cảnh và đồ thị khái niệm (docs/DATASTURCTURE.md mục 6).

#### `ConceptSource`

Thứ mà bộ tìm kiếm đọc.

Khởi tạo bằng `ConceptSource(*args, **kwargs)`.

| Phương thức | Làm gì |
| - | - |
| `registry(self, scope: str) -> ContextRegistry` | — |
| `concepts_in(self, scope: str) -> Iterable[Concept]` | — |

#### `SearchConfig`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `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`

Khởi tạo bằng `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>)`.

| Phương thức | Làm gì |
| - | - |
| `option_sets(self, scope: str) -> list[PickSpec]` | Mọi tập phương án mà một lần tìm kiếm trong `scope` hỏi bộ quyết định: các con của mỗi ngữ cảnh (và của cấp trên cùng), và các khái niệm mà mỗi ngữ cảnh chứa. |
| `prepare(self, scope: str) -> int` | Đưa các tập phương án cho bộ quyết định khi nó có thể dùng chúng. |
| `search(self, q: Query) -> list[Hit]` | — |
| `asearch(self, q: Query) -> list[Hit]` | — |
| `best_cosine(self, q: Query) -> float \| None` | Cosine giữa câu hỏi và khái niệm có thể phục vụ gần nhất, hoặc None khi không có bộ nhúng hoặc khái niệm. |

#### `SearchStats`

Lần tìm kiếm gần nhất đã làm gì, dùng cho các bài kiểm thử và để đo chi phí.

| Trường | Kiểu | Mặc định |
| - | - | - |
| `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.