Corpus¶
This is an automatically generated API reference for searching a folder of
.vera files as one collection.
corpus
¶
Corpus search: query a folder of .vera files as a single collection.
Classes:
-
VeraCorpus–A folder of .vera files searchable as one corpus.
-
CorpusSearchResult–A search result attributed to the .vera file it came from.
VeraCorpus
¶
VeraCorpus(
directory: str,
paths: list[str],
*,
recursive: bool = False,
excludes: tuple[str, ...] = (),
includes: tuple[str, ...] = (),
max_open_documents: int = 16,
collection_index: VeraCollectionIndex | None = None,
index_status: dict[str, Any] | None = None,
invalid_files: list[dict[str, str]] | None = None,
)
A folder of .vera files searchable as one corpus.
Documents needed for citations and figures are opened lazily with a bounded LRU cache. File fan-out search uses parallel short-lived connections; a fresh local collection index is preferred automatically. Each file's query embedding uses that file's recorded embedding model, so a corpus may mix models.
Ranking: semantic results are merged by raw cosine score (comparable
across files that share a model). Mixed-model semantic lists and hybrid
semantic+keyword lists use :func:~vera_doc.ranking.reciprocal_rank_fusion
so a library searched with or without a local index returns the same
chunk order for a fixed hybrid query. Keyword-only scores are only
comparable within a file; those candidates keep their original score
with reciprocal rank as a tiebreaker.
Methods:
-
open–Open a directory of
.verafiles for corpus search. -
from_paths–Build a corpus from an explicit list of .vera file paths.
-
document–Return the (cached) open VeraDocument for a file in this corpus.
-
close– -
__enter__– -
__exit__– -
index_search_report–Index status for the most recent search, including fallback reasons.
-
inspect–Summarize the corpus and optionally report per-archive progress.
-
inspect_summary–Open a library quickly without validating every archive.
-
search–Search every file in the corpus and return the fused top_k results.
Attributes:
-
directory– -
paths– -
recursive– -
excludes– -
includes– -
max_open_documents– -
index_status– -
invalid_files– -
skipped_semantic_model_groups(list[dict[str, Any]]) – -
uses_index(bool) –Whether the most recent search used the local collection index.
index_status
instance-attribute
¶
index_status = index_status or {
"exists": False,
"fresh": False,
"reasons": ["index is missing"],
}
skipped_semantic_model_groups
instance-attribute
¶
uses_index
property
¶
Whether the most recent search used the local collection index.
Before the first search, this is whether an index is attached.
open
classmethod
¶
open(
directory: str,
*,
recursive: bool | None = None,
excludes: list[str] | tuple[str, ...] | None = None,
includes: list[str] | tuple[str, ...] | None = None,
max_open_documents: int = 16,
use_index: bool = True,
default_recursive: bool = False,
allow_empty: bool = False,
) -> VeraCorpus
Open a directory of .vera files for corpus search.
Parameters:
-
directory(str) –Root directory containing
.veraarchives. -
recursive(bool | None, default:None) –When
True, include nested directories. WhenNone, use persisted index settings when an index exists. -
excludes(list[str] | tuple[str, ...] | None, default:None) –Glob patterns to skip.
-
includes(list[str] | tuple[str, ...] | None, default:None) –Glob patterns that a relative path must match when provided. Omitted includes keep every discovered file.
-
max_open_documents(int, default:16) –LRU cache size for opened documents.
-
use_index(bool, default:True) –When
True, use a fresh local index when available. -
default_recursive(bool, default:False) –Default recursion when no index exists.
-
allow_empty(bool, default:False) –When
True, allow opening a directory with no valid archives.
Returns:
-
VeraCorpus–A corpus handle ready for :meth:
search.
Raises:
-
NotADirectoryError–When
directoryis not a directory. -
FileNotFoundError–When no valid archives are found and
allow_emptyis false.
from_paths
classmethod
¶
from_paths(paths: list[str]) -> VeraCorpus
Build a corpus from an explicit list of .vera file paths.
Selected files do not need a shared parent. Desktop multi-select can
include paths on different Windows drives, where os.path.commonpath
raises ValueError; the corpus root then falls back to the first
file's parent. Result file attributes remain the original paths.
document
¶
document(file: str) -> VeraDocument
Return the (cached) open VeraDocument for a file in this corpus.
index_search_report
¶
Index status for the most recent search, including fallback reasons.
inspect
¶
Summarize the corpus and optionally report per-archive progress.
inspect_summary
¶
Open a library quickly without validating every archive.
A fresh collection index supplies persisted metrics from its last
validated build. Missing or stale indexes return discovery counts only;
callers can run inspect explicitly when they need a deep scan.
search
¶
search(
text: str,
*,
mode: str = "hybrid",
top_k: int = 10,
context_chunks: int = 0,
where: Mapping[str, Any] | None = None,
) -> list[CorpusSearchResult]
Search every file in the corpus and return the fused top_k results.
where is applied before top_k. Caller tags stamped on chunks
match every path. Convert-owned archive headers match indexed search;
single-file and fallback search evaluate chunk metadata.
CorpusSearchResult
dataclass
¶
CorpusSearchResult(
record: ChunkRecord,
score: float,
semantic_score: float | None = None,
keyword_score: float | None = None,
before: tuple[ChunkRecord, ...] = (),
after: tuple[ChunkRecord, ...] = (),
file: str = "",
)
Bases: QueryResult
A search result attributed to the .vera file it came from.
Methods:
-
as_dict–
Attributes:
-
file(str) – -
record(ChunkRecord) – -
score(float) – -
semantic_score(float | None) – -
keyword_score(float | None) – -
before(tuple[ChunkRecord, ...]) – -
after(tuple[ChunkRecord, ...]) – -
chunk_id(str) – -
text(str) – -
citation(Citation) – -
page_start(int | None) – -
page_end(int | None) – -
heading_path(str | None) – -
source_filename(str | None) – -
document_id(str | None) – -
before_chunks(list[dict[str, Any]]) – -
after_chunks(list[dict[str, Any]]) –
For large libraries, pair with a persistent library index.