Source code for aeat.application.corpus_search._models
"""Typed records for the on-host corpus-search grounding surface.Every record is a strict, frozen pydantic v2 model. The surface neverexposes a bare ``dict`` for a chunk, a search hit, or a citationresolution: the console grounds an operator against verbatim legal text,so the provenance carried alongside each result (corpus_ref, sourcepath, document id, permalink) is contract, not decoration.See Also: :func:`~application.corpus_search.search_corpus` Runtime service that returns :class:`~application.corpus_search.RetrievalResponse`. :func:`~entrypoints.mcp._corpus_tools.corpus_search_payload_from_response` MCP transport mapper that preserves the typed retrieval provenance."""from__future__importannotationsfromenumimportStrEnumfromtypingimportAnnotatedfrompydanticimportBaseModel,Field,StringConstraintsfrom...coreimportSTRICT_FROZEN_CONFIGas_STRICT_FROZEN_Text=Annotated[str,StringConstraints(strip_whitespace=True,min_length=1)]
[docs]classRetrievalMode(StrEnum):"""How a retrieval response was produced. ``CITATION`` — the query was an exact citation id, short-circuited to the structured lookup; ``HYBRID`` — lexical FTS5 fused with semantic cosine; ``LEXICAL_ONLY`` — the degraded no-model mode (search extra absent or no precomputed vectors supplied). """CITATION="citation"HYBRID="hybrid"LEXICAL_ONLY="lexical_only"
[docs]classCorpusChunk(BaseModel):"""One retrievable prose chunk extracted from the bundled corpus. A chunk is a paragraph-bounded slice of a single extracted unit (an article or disposition). ``chunk_id`` is deterministic given the same corpus, so a rebuilt index re-mints byte-identical ids and the shipped embedding matrix stays row-aligned with the lexical index. """model_config=_STRICT_FROZENchunk_id:_Textcorpus_ref:_Textsource_path:_Textdoc_title:_Textsection:str|None=Noneanchor:str|None=Noneordinal:int=Field(ge=0)text:_Text
[docs]classCorpusDocument(BaseModel):"""Metadata for one extracted corpus source file in the lexical index."""model_config=_STRICT_FROZENcorpus_ref:_Textsource_path:_Texttitle:_Textchunk_count:int=Field(ge=0)
[docs]classLexicalSearchHit(BaseModel):"""One ranked lexical-search result over the FTS5 index."""model_config=_STRICT_FROZENchunk_id:_Textcorpus_ref:_Textdoc_title:_Textsection:str|None=Noneanchor:str|None=Nonerank:int=Field(ge=0)score:floattext:_Text
[docs]classCitationResolution(BaseModel):"""A citation id resolved to catalogue metadata plus verbatim text. The metadata is projected from the registry legal catalogue (the single citation authority); ``verbatim_text`` is read from the bundled extracted corpus the citation's ``corpus_ref`` points at. """model_config=_STRICT_FROZENcitation_id:_Textdocument_id:_Textkind:_Textcorpus_ref:_Textpermalink:_Textarticle:str|None=Nonesection:str|None=Noneanchor:str|None=Noneverbatim_text:_Text
[docs]classSimilarChunk(BaseModel):"""One cosine-nearest chunk for the more-like-this primitive."""model_config=_STRICT_FROZENchunk_id:_Textrank:int=Field(ge=0)similarity:float
[docs]classCorpusIndexBuildResult(BaseModel):"""Summary of one lexical-index build."""model_config=_STRICT_FROZENdatabase_path:_Textdocument_count:int=Field(ge=0)chunk_count:int=Field(ge=0)
[docs]classCorpusEmbeddingBuildResult(BaseModel):"""Summary of one build-time embedding precompute."""model_config=_STRICT_FROZENmatrix_path:_Textchunk_ids_path:_Textchunk_count:int=Field(ge=0)dimensions:int=Field(ge=1)embedding_model_id:_Textembedding_model_revision:_Text
[docs]classRetrievalHit(BaseModel):"""One fused hybrid-retrieval result over the corpus. ``text`` is the verbatim chunk prose (the snippet source); ``corpus_ref`` grounds it in the bundled source (and is the ``aeat://corpus/{ref}`` key that resolves the full verbatim text). ``score`` is the fused RRF score; ``lexical_rank`` / ``semantic_rank`` record the per-side contribution (``None`` when a side did not surface the chunk). """model_config=_STRICT_FROZENchunk_id:_Textcorpus_ref:_Textdoc_title:_Texttext:_Textscore:float=Field(ge=0.0)rank:int=Field(ge=0)lexical_rank:int|None=Nonesemantic_rank:int|None=None
[docs]classRetrievalResponse(BaseModel):"""The typed result of one corpus retrieval. ``mode`` records how the response was produced (citation short-circuit, hybrid, or lexical-only degraded). ``citation`` carries the resolved citation when ``mode`` is ``CITATION``; otherwise ``hits`` carries the ranked results. """model_config=_STRICT_FROZENquery:_Textmode:RetrievalModehits:tuple[RetrievalHit,...]=()citation:CitationResolution|None=None