rag.core.catalog¶
Paper catalog and corpus-vs-paper query routing.
Attributes¶
Classes¶
Whether a question is about one paper or the whole corpus. |
|
Keys in the on-disk catalog JSON object. |
|
One PDF in the corpus catalog. |
|
Ordered catalog of ingested papers. |
Functions¶
|
Classify a user question as paper-level or corpus-level. |
|
Collapse whitespace and truncate opening text for the catalog. |
|
Build a catalog keyed by PDF path, using first-page text when present. |
|
Return the catalog JSON path under the Chroma directory. |
|
Write |
|
Load the catalog from disk, or filenames from |
Module Contents¶
- class rag.core.catalog.QueryScope[source]¶
Bases:
enum.StrEnumWhether a question is about one paper or the whole corpus.
- class rag.core.catalog.CatalogJsonKey[source]¶
Bases:
enum.StrEnumKeys in the on-disk catalog JSON object.
- class rag.core.catalog.PaperCatalogEntry[source]¶
One PDF in the corpus catalog.
- Variables:
file_name (str) – PDF basename.
title (str) – Opening-page snippet used as a title stand-in.
- class rag.core.catalog.PaperCatalog[source]¶
Ordered catalog of ingested papers.
- Variables:
papers (tuple of PaperCatalogEntry) – One entry per PDF, typically ingest order.
- papers: tuple[PaperCatalogEntry, Ellipsis][source]¶
- classmethod from_json(raw: str) PaperCatalog[source]¶
Parse a catalog JSON string.
- Parameters:
raw (str) – JSON produced by
to_json.- Returns:
Parsed catalog (empty when
papersis missing).- Return type:
- rag.core.catalog.classify_query_scope(*, question: str) QueryScope[source]¶
Classify a user question as paper-level or corpus-level.
- Parameters:
question (str) – Natural-language question.
- Returns:
CORPUSwhen the question is about the whole library.- Return type:
- rag.core.catalog.title_from_text(*, text: str) str[source]¶
Collapse whitespace and truncate opening text for the catalog.
- Parameters:
text (str) – First extractable page (or any snippet).
- Returns:
Short title stand-in.
- Return type:
str
- rag.core.catalog.catalog_from_documents(*, pdf_paths: collections.abc.Sequence[pathlib.Path], documents: collections.abc.Sequence[Any]) PaperCatalog[source]¶
Build a catalog keyed by PDF path, using first-page text when present.
- Parameters:
pdf_paths (sequence of Path) – Source PDFs (defines order and completeness).
documents (sequence) – Page-like objects with
file_namemetadata andtext.
- Returns:
One entry per PDF path.
- Return type:
- rag.core.catalog.catalog_path(*, chroma_dir: pathlib.Path) pathlib.Path[source]¶
Return the catalog JSON path under the Chroma directory.
- Parameters:
chroma_dir (Path) – Persistence directory.
- Returns:
chroma_dir / catalog.json.- Return type:
Path
- rag.core.catalog.write_paper_catalog(*, catalog: PaperCatalog, chroma_dir: pathlib.Path) pathlib.Path[source]¶
Write
catalog.jsonnext to the Chroma store.- Parameters:
catalog (PaperCatalog) – Catalog to persist.
chroma_dir (Path) – Persistence directory (created if missing).
- Returns:
Path written.
- Return type:
Path
- rag.core.catalog.load_paper_catalog(*, config: rag.core.config.RagConfig) PaperCatalog[source]¶
Load the catalog from disk, or filenames from
papers_dir.- Parameters:
config (RagConfig) – Provides
chroma_dirandpapers_dir.- Returns:
Persisted catalog, or a filenames-only fallback.
- Return type: