cadrumo.application.corpus_search.runtime module

Runtime corpus-search service: provision the index and run grounding search.

External tools and resources consume grounding through one service entry, search_corpus(), so the protocol layer never re-derives the retrieval wiring. The lexical index covers top-level normatives/html/*.html.extracted.json payloads. It is provisioned in an app-controlled cache and rebuilt atomically whenever the indexed bytes or schema identity changes.

Retrieval is fully offline: the FTS5 lexical ranking and the exact-citation lookup need no model, no vectors, and no network. The service has no degraded mode because it has no optional half to degrade from.

See also

run_retrieval()

Retrieval primitive this runtime service provisions and calls.

corpus_search_dir(settings=None)[source]

Return the app-controlled corpus-search cache directory.

Read from the settings field rather than joined onto the storage root here. A module-local subdirectory literal is invisible to the taxonomy: no environment override could reach it, the tree materialiser could not pre-create it, and a root override in a test would not redirect it – so this module carried its own mkdir to compensate for a directory nothing else knew about.

Return type:

Path

Parameters:

settings (Settings | None)

corpus_index_path(settings=None)[source]

Return the lexical index path (whether or not it has been built).

Return type:

Path

Parameters:

settings (Settings | None)

ensure_corpus_index(settings=None)[source]

Return the current lexical index, rebuilding stale caches atomically.

Currency is determined from the sorted relative paths and exact bytes of every indexed source plus explicit index and extractor schema versions. Builds are staged beside the destination and published with one atomic replace, so an interrupted build is never mistaken for a current index.

Return type:

Path

Parameters:

settings (Settings | None)

search_corpus(query, *, limit=8, settings=None)[source]

Run grounding retrieval for query.

Provisions the content-keyed normative-HTML lexical index and runs the separate signed-authority citation lookup before ranked FTS5 search.

Parameters:
  • query (str) – The free-text query or an exact citation id.

  • limit (int) – Maximum number of hits.

  • settings (Settings | None) – Optional settings override (test isolation).

Return type:

RetrievalResponse

Returns:

A RetrievalResponse.