Elamur: **Mova** · [Parse](https://mova.elamur.ai/free/en/parse/) · [Research](https://md.research.elamur.ai/free/en/) · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/) · [Shryfti](https://md.shryfti.elamur.ai/free/en/)

[Mova](https://md.mova.elamur.ai/free/en/) · [this page in HTML](https://mova.elamur.ai/free/en/docs/tools/sentstore/)

[Mova](https://md.mova.elamur.ai/free/en/) / [docs](https://md.mova.elamur.ai/free/en/docs/) / [tools](https://md.mova.elamur.ai/free/en/docs/tools/) / sentstore — a document-sharded, append-only store of sentence records

# sentstore — a document-sharded, append-only store of sentence records

`sentstore` keeps sentence records grouped by document: one JSON record per document (or per part of a document that one batch added), each sentence with its id, position and text and any number of other fields (context, parse layers, provenance). The same sentence text in two documents is two records, because its context and its parses may differ. It is the store of the continuous corpus pipeline ([Text corpora from 0.6](https://md.mova.elamur.ai/free/en/docs/repo-docs/corpora/)); the format is generic.

```
cargo build --release -p sentstore
sentstore get DIR DOC SENT       # one sentence: its id, #N (its number) or =TEXT (its exact text)
sentstore doc DIR DOC            # one document, its parts from every batch joined
sentstore info DIR               # shard count and committed batches
sentstore verify DIR             # segments against their commits, every document read, keys complete
sentstore compact DIR [SHARD]    # merge a shard's segments (every shard without SHARD)
```

From Rust: `Store::create(dir, shards)`, `store.append(batch, &records, &meta)`, `store.get(doc, &Sel::parse(sent))`, `store.keys()` (every committed `(document, sentence)` pair: what a sampler draws without replacement against).

## How it works

- **Shards.** A document's shard is FNV-1a of its id modulo the shard count, fixed when the store is created (256 shards keep millions of sentences in shards of tens of megabytes). Every part of a document lies in its shard.
- **Batches append.** A batch writes one new segment per shard it touches, `shard-NNNN/seg-<batch>.mpk` (JSON lines packed with [`mova-pack`](https://md.mova.elamur.ai/free/en/docs/pack/): templates, zstd blocks with a record index, checked by unpacking before it is written) with its document index `seg-<batch>.idx`, then `keys/<batch>.tsv`, and last the commit marker `batches/<batch>.json`. A segment counts only once its batch is committed, so a crash leaves nothing half-visible; an uncommitted batch is moved to `.aside/` and written again. No batch rewrites a shard. A batch that repeats a committed `(document, sentence)` key is refused.
- **Compaction** merges a shard's live segments into one (`seg-c<last batch>.mpk`) and switches `live.json` to it with one rename; the old segments move to `.aside/`. Reads are the same before and after.
- **Reading** a document reads the index of each live segment of its shard and decodes one block per segment.

## Checks

`cargo test --release -p sentstore`: batches append to their shards without rewriting them, a document grows across batches, the same text in two documents stays two records, compaction keeps every read, a repeated key and malformed records are refused, an uncommitted segment is invisible and redone, and (negative control) a corrupted segment fails `verify`.

## Limits

- One writer at a time; no locking.
- Each read decodes one block per live segment of the shard: compact shards with many segments.
- Small batch segments are packed without a trained zstd dictionary (it pays from about 1 MB).
- `.aside/` is never emptied by the store itself.
- [← previous Sea Spider — mova-seaspider](https://md.mova.elamur.ai/free/en/docs/tools/seaspider/)
- [next → sitegraph](https://md.mova.elamur.ai/free/en/docs/tools/sitegraph/)
- [↑ back to tools](https://md.mova.elamur.ai/free/en/docs/tools/)

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://mova.elamur.ai/sitemap.xml) · [llms.txt](https://mova.elamur.ai/llms.txt)
