"""Runtime Evidence lookup bound to the atomically active corpus generation.""" from tht.corpus.store import CorpusStore def active_evidence_hits(store: CorpusStore, vector_store, embedding, *, limit: int): manifest = store.active_manifest() if manifest is None or manifest.vector_generation is None: return [] document_generations = dict(manifest.metadata.get("document_generations", {})) active_documents = {document.document_id for document in manifest.documents} hits = vector_store.search(["evidence"], embedding, limit=limit, kinds=["evidence"]) return [ hit for hit in hits if hit.metadata.get("document_id") in active_documents and hit.metadata.get("vector_generation") == document_generations.get(hit.metadata.get("document_id"), manifest.vector_generation) ] def resolve_evidence_file(store: CorpusStore, evidence_id: str) -> str: manifest = store.active_manifest() if manifest is None: return "" for document in manifest.documents: frontmatter = document.metadata.get("frontmatter", {}) identifiers = {document.document_id, document.source_id, str(frontmatter.get("id", ""))} if evidence_id in identifiers: path = store.resolve_document(document.document_id) return str(path) if path else "" return ""