kora-doc
Document layer that turns Kora from a key-value cache engine into a JSON-native document database. Documents are stored in a compact binary packed format, queried via a WHERE expression parser, and indexed through four secondary index types (hash, sorted, array, unique).
Architecture
A JSON document passes through a pipeline of transformations before it reaches storage:
-
Decomposition ([
decompose]) -- a JSON object is recursively walked, each leaf field is assigned a numericFieldIdvia theIdRegistry, string values are dictionary-encoded when their field cardinality is low, and the result is assembled into aPackedDoc. -
Packed encoding ([
packed]) -- fields are stored in a flat binary buffer with an offset table sorted by field ID, enabling O(log F) single-field reads via binary search. -
Recomposition ([
recompose]) -- the inverse of decomposition, rebuilding aserde_json::Valuefrom packed bytes, dictionary lookups, and registry path resolution. Supports full reconstruction or field-level projection.
Key Modules
| Module | Purpose |
|---|---|
[packed] |
Binary packed document format and builder |
[registry] |
Integer-keyed ID mapping for collections, fields, and docs |
[dictionary] |
Dictionary encoding for low-cardinality string values |
[decompose] |
JSON to packed document conversion |
[recompose] |
Packed document to JSON reconstruction |
[engine] |
Collection CRUD, index maintenance, and query execution |
[expr] |
WHERE clause recursive-descent parser |
[index] |
Hash, sorted, array, and unique secondary indexes |
[collection] |
Collection metadata and configuration |
[key] |
Binary key encoding for storage and index records |