Skip to content

API Reference parrot.knowledge.pageindex.segment_store

github-actions[bot] edited this page Dec 2, 2026 · 2 revisions

parrot.knowledge.pageindex.segment_store

View source

Immutable document-revision files for PageIndex trees (FEAT-840).

Alias DocumentRevision

Re-exported from parrot.knowledge.pageindex.segments.DocumentRevision.

Class SegmentStore

<storage_dir>/<tree>/segments/<doc_id>.<revision>.json, written once, read through an LRU.

Parameter Type Default Description
storage_dir str | Path
cache_size int 8

Method SegmentStore.segments_dir

Return <storage_dir>/<tree_name>/segments; ValueError on a bad name.

segments_dir(tree_name: str) -> Path

Parameter Type Default Description
tree_name str

Returns: Path

Method SegmentStore.revision_path

Path of one revision file; ValueError on a malformed doc_id or revision.

revision_path(tree_name: str, doc_id: str, revision: str) -> Path

Parameter Type Default Description
tree_name str
doc_id str
revision str

Returns: Path

Method SegmentStore.save_revision

Write rev atomically.

The revision id hashes segment texts only, so an existing file can hold the same text with different (or no) injection-scan results. An existing file is left untouched unless rev carries scan results (scored_by set) that differ from it, or it is unreadable; in that case it is replaced atomically and its cache entry evicted. An unscanned rev never overwrites a scanned one.

save_revision(tree_name: str, rev: DocumentRevision) -> Path

Parameter Type Default Description
tree_name str
rev DocumentRevision

Returns: Path

Method SegmentStore.load_revision

Return the cached/parsed revision, or None when the file is absent.

load_revision(tree_name: str, doc_id: str, revision: str) -> Optional[DocumentRevision]

Parameter Type Default Description
tree_name str
doc_id str
revision str

Returns: Optional[DocumentRevision]

Method SegmentStore.has_revision

has_revision(tree_name: str, doc_id: str, revision: str) -> bool

Parameter Type Default Description
tree_name str
doc_id str
revision str

Returns: bool

Method SegmentStore.list_revisions

(doc_id, revision) of every file on disk, sorted.

list_revisions(tree_name: str) -> list[tuple[str, str]]

Parameter Type Default Description
tree_name str

Returns: list[tuple[str, str]]

Method SegmentStore.live_revisions

Every (doc_id, revision) named by a node of tree.

live_revisions(tree: dict[str, Any]) -> set[tuple[str, str]]

Parameter Type Default Description
tree dict[str, Any]

Returns: set[tuple[str, str]]

Method SegmentStore.mark_superseded

Restart the grace clock (os.utime) of revisions a new generation stopped referencing.

mark_superseded(tree_name: str, pairs: Iterable[tuple[str, str]]) -> int

Parameter Type Default Description
tree_name str
pairs Iterable[tuple[str, str]]

Returns: int

Method SegmentStore.sweep_unreferenced

Delete non-live revision files older than max_age_s; return the count.

sweep_unreferenced(tree_name: str, tree: dict[str, Any], *, max_age_s: int) -> int

Parameter Type Default Description
tree_name str
tree dict[str, Any]
max_age_s int

Returns: int

Method SegmentStore.delete_tree

Remove segments/ for tree_name and evict its cache entries; return files removed.

delete_tree(tree_name: str) -> int

Parameter Type Default Description
tree_name str

Returns: int

Attribute logger

Alias structure_to_list

Re-exported from parrot.knowledge.pageindex.utils.structure_to_list.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally