Skip to content

op doc_search_levels

Mikhail Deynekin edited this page Nov 22, 2026 · 7 revisions

doc_search_levels

Dual-level search: local facts and the global level in one answer.

Group Documents
Edition community — works without a licence
Capability search — the feature that carries this operation; the licence matrix is on 15 · Editions and licensing
MCP tool ragraf_doc_search_levels · read-only · idempotent · requires query
CLI ragraf -p <config> query doc_search_levels …

Why it exists

This is a separate operation rather than one more mode of search, because search already has a contract: a flat list of hits, the one-answer mode, material and document role, staleness marks. A two-level answer has a different shape — two named levels and the links between them — and a second shape inside the first contract would break comparison with earlier measurements: a client expecting a list would receive a dictionary. So search stays as it is, and the levels live here, on the same engine (search_hybrid) and the same address source (entity_mention).

What it solves

  • Get local hits and graph-level entities in one answer, with the links between them named.
  • Keep the base search free: the local level works under any edition, and under an edition without doc-graph the global mode refuses with a reason while both returns the local facts and names the gap in limits.
  • Trust the silence: an entity without a mention address is counted in rejected_no_citation instead of being asserted.

How to use it

The call that produced the answer below, as a command line:

$ ragraf -p demo-corpus.yaml query doc_search_levels orders --mode both

The same call through MCP: ragraf_doc_search_levels(query=…).

The answer below was captured on the demo corpus, not written for the page:

{
 "op": "doc_search_levels",
 "index_rev": "rev-0002",
 "capability": "degraded",
 "provenance": "index",
 "found": true,
 "result": {
  "query": "orders",
  "mode": "both",
  "local": {
   "level": "local",
   "found": true,
   "count": 11,
   "hits": [
    {
     "match_channels_count": 1
    },
    {
     "match_channels_count": 1
    },
    "... 9 more"
   ]
  },
  "global": {
   "level": "global",
   "found": false,
   "count": 0,
   "entities": [],
   "relations": [],
   "code": "edition",
   "links": {
    "hits": 11,
    "hits_with_entities": 0,
    "entities": 0,
    "relations": 0,
    "relations_linked": 0
   }
  }
 },
 "limits_count": 2
}

The call succeeded. The answer is trimmed to two items per list and to the fields that carry no Russian prose: limits and the explanatory strings are counted in the footer below instead of being quoted.

Parameters

Name Type Default
query str required
limit int 20
mode str 'both'

What it returns

result is assembled at runtime, so the code carries no static list of its keys: the shape is whatever the sentence above describes, and the diagram below shows the steps that build it.

The body also writes these fields into the answer envelope itself (extra): degraded, refused, suggest.

The envelope around the result is the same for every operation; how to read it: 04 · Operations reference.

How it works

Step What happens
Reads none of the three stores directly — the answer comes through the engine the body calls, or from what the call is given
Calls docgraph_ops.layer_state, docgraph_ops.locator, edition_mod.feature_denial
Guarded by the index revision is read (current_rev), so every fact belongs to a named revision; a missing index is refused by name (_no_index) instead of raising
Writes degraded, refused, suggest into the answer envelope
Empty answer yes, and names where to go instead: search, doc_search, repo_map
flowchart TD
  Start[query doc_search_levels]
  Rev{index revision}
  NoIndex[refused: no index]
  Call0[docgraph_ops.layer_state]
  Call1[docgraph_ops.locator]
  Call2[edition_mod.feature_denial]
  Found{found}
  Empty[empty result + suggest: search doc_search repo_map]
  Out[envelope with result]
  Start --> Rev
  Rev -- none --> NoIndex
  Rev -- rev-N --> Call0
  Call0 --> Call1
  Call1 --> Call2
  Call2 --> Found
  Found -- no --> Empty
  Found -- yes --> Out
Loading

Where it stops

Every answer carries a limits field, and it is never empty when a boundary exists: that is where the limits of this particular call are named — which part of the corpus was not covered, which fact could not be confirmed, what the operation refused to guess.

The boundary of the whole Documents group is stated once, on the reference page. It is a sentence about the group, so it is not repeated here as if it were a sentence about doc_search_levels.

Around this group

← previous in the group: doc_validate

→ next in the group: doc_ocr

The full table with all 87 operations · A–Z index · Documents


Where these fields come from: the parameters, their types and defaults are read from the signature op_doc_search_levels in src/ragraf/facade.py:4988 (line numbers as of 0.12.0); the MCP annotations from the tool registration; the edition from src/ragraf/edition_baseline.json; the guards, calls, stores, envelope fields and the diagram from the body of that same method. The example is a run of tools/build-op-examples.py on the demo corpus at revision rev-0002; fields whose value is Russian prose in this build (limits, explanatory strings) are counted, not quoted. Nothing else on this page is written by hand.

The reason and the tasks above are a translation of the docstring of op_doc_search_levels, src/ragraf/facade.py:4988, kept in tools/op-text.json next to the line it came from. That file is the only hand-written text in the pipeline; the gate tools/check-op-text.py checks that the line exists and that its text is English.

Clone this wiki locally