Skip to content

op search

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

search

Hybrid search: lexis + vectors (RRF), every hit with its provenance.

Group Navigation and reading
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_search · read-only · idempotent · requires query
CLI ragraf -p <config> query search …

Why it exists

Search is how a reader enters a corpus it has not read: it answers where a concept lives without loading files. Since the rev-0030 measurement the hit itself can carry snippet, the beginning of the chunk text FROM THE INDEX, because before that the text of a hit cost a second call: twenty hits cost twenty file reads. The text comes in one batch query to the chunk store (lexvec.chunk_texts), not one per hit.

What it solves

  • Find where a concept lives without opening files.
  • Read the opening of a hit's text in the same answer, and see when the text is absent: the field does not appear, and the count is named in limits, so an empty string never stands for missing text.
  • Judge a hit by its evidence — chunk id, path:line, score and reason — instead of a bare list.

How to use it

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

$ ragraf -p demo-corpus.yaml query search order

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

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

{
 "op": "search",
 "index_rev": "rev-0002",
 "capability": "degraded",
 "provenance": "index",
 "found": true,
 "result": [
  {
   "chunk_id": "22348ccf4e26e7e98da6af873f1690f5145fa28d",
   "path": "src/app/service.py",
   "node_id": "2c8fb46935c9ab058c0336bd63c63afaea59a1b0",
   "start_line": 6,
   "end_line": 8,
   "source_kind": "symbol",
   "score": 1.5693256741432302,
   "material": "code"
  },
  {
   "chunk_id": "978163b594cef7e27060a6f2f834d7fefd9795fa",
   "path": "src/app/repository.py",
   "node_id": "ada5c3c92d92f41f6eb71db8770353dc5ce23615",
   "start_line": 17,
   "end_line": 23,
   "source_kind": "symbol",
   "score": 1.5585525300997198,
   "material": "code"
  },
  "... 10 more"
 ],
 "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
kinds list[str] | None None
with_text bool False
text_width int 160
answer bool False
mode str 'auto'

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): code_candidate, material_mix, snippet_width, suggest, text_from_index, vector_available, vector_used.

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 formats_mod.group_of_material
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 code_candidate, material_mix, snippet_width, suggest, text_from_index, vector_available, vector_used into the answer envelope
Empty answer no separate branch: the body returns what it computed
flowchart TD
  Start[query search]
  Rev{index revision}
  NoIndex[refused: no index]
  Call0[formats_mod.group_of_material]
  Out[envelope with result]
  Start --> Rev
  Rev -- none --> NoIndex
  Rev -- rev-N --> Call0
  Call0 --> 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 Navigation and reading 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 search.

But one sentence of it is about this operation, and it applies to every call of search:

Search answers "where the text looks like the question", not "where the answer is": lexis and vectors decide, not meaning.

Around this group

← this is the first operation of the group

→ next in the group: search_multi

The full table with all 87 operations · A–Z index · Navigation and reading


Where these fields come from: the parameters, their types and defaults are read from the signature op_search in src/ragraf/facade.py:4678 (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_search, src/ragraf/facade.py:4678, 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