Skip to content

op doc_search

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

doc_search

Search across document chunks: the fact, its address, its provenance.

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

Why it exists

A document answer is only usable if it can be checked, and checking needs the address of the chunk and the status of extraction, not just text. search --kind doc looks through all chunks, while a document address lives in document_chunk; here one batch query returns the address, the structure and the extraction status — the facts trust is judged by.

What it solves

  • Find a fact in the documents with an address to quote.
  • Read the structure of the document around the fact, not only the sentence.
  • Judge whether the extraction that produced the chunk can be trusted.

How to use it

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

$ ragraf -p demo-corpus.yaml query doc_search orders

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

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

{
 "op": "doc_search",
 "index_rev": "rev-0002",
 "capability": "degraded",
 "provenance": "index",
 "found": true,
 "result": {
  "query": "orders",
  "hits": [
   {
    "locator": "README.md:14",
    "path": "README.md",
    "doc_id": "14d42449282f9ad06edf40ed48d0e58e7bd5c653",
    "kind": "section",
    "tokens": 5,
    "extraction_status": "ok",
    "structure": {},
    "provenance": {},
    "score": 1.729,
    "snippet": "How orders are built",
    "validity": "current",
    "version_id": "a27e34f0b20e467b13c32d9fe60916443406e7c5",
    "superseded": false,
    "superseded_by": "",
    "validity_source": "unknown",
    "validity_warnings": []
   },
   {
    "locator": "README.md:11-12",
    "path": "README.md",
    "doc_id": "14d42449282f9ad06edf40ed48d0e58e7bd5c653",
    "kind": "paragraph",
    "tokens": 33,
    "extraction_status": "ok",
    "structure": {},
    "provenance": {},
    "score": 1.5481,
    "snippet": "The `web` directory holds one PHP endpoint that reads `$_GET` and queries the\n`orders` table, and a second copy that nothing refers to.",
    "validity": "current",
    "version_id": "a27e34f0b20e467b13c32d9fe60916443406e7c5",
    "superseded": false,
    "superseded_by": "",
    "validity_source": "unknown",
    "validity_warnings": []
   }
  ],
  "count": 2,
  "doc_hits_before_filter": 2,
  "include_superseded": false,
  "filtered_by_validity": 0
 },
 "limits_count": 1
}

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
kind str | None None
doc str | None None
with_text bool True
text_width int 240
asof str | None None
include_superseded bool False

What it returns

Result keys visible in the code: asof, count, doc_hits_before_filter, filtered_by_validity, hits, include_superseded, query.

The body also writes these fields into the answer envelope itself (extra): evidence, 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 no module function: the body computes the answer itself
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 evidence, suggest into the answer envelope
Empty answer yes, and names where to go instead: doc_search, doc_asof
flowchart TD
  Start[query doc_search]
  Rev{index revision}
  NoIndex[refused: no index]
  Body[operation body]
  Found{found}
  Empty[empty result + suggest: doc_search doc_asof]
  Out[envelope with result]
  Start --> Rev
  Rev -- none --> NoIndex
  Rev -- rev-N --> Body
  Body --> 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.

Around this group

← this is the first operation of the group

→ next in the group: doc_get

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 in src/ragraf/facade.py:6464 (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, src/ragraf/facade.py:6464, 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