macula_rag_contract (macula_rag v0.4.0)

View Source

The wire contract every shard of an org speaks. Pure.

ONE PROCEDURE, <Org>/rag.query_shard_v1. Each shard node provides it under its org's namespace, so macula 12 only lets a node provide it with a D25 procedure_delegation from that org, and only calls a provider whose delegation verifies against the realm key. That is what makes "the shards of this org" a checked set rather than whoever says so.

TWO FACTS, canonical app facts under the org:

<realm>/<org>/rag/shard/shard_summarized_v1 what a shard holds <realm>/<org>/rag/shard/shard_withdrawn_v1 it holds nothing any more

A summary names the EMBEDDING the shard's index was built with, model and dimension. Scores from two embeddings are not comparable, so a query is only sent to, and only merged across, shards whose embedding matches the querying node's own.

WHO SENT A FACT IS NOT IN THE PAYLOAD. macula delivers every event with its verified publisher; a summary belongs to that node, whatever it claims. shard_id is informational: the node id is the shard's identity.

A HIT'S MINIMUM is a binary id and a numeric score. Everything else in a hit, and the whole query, is the consumer's, carried as it is.

Build functions take atom keys. parse/2 reads what a peer receives, where macula's codec hands text back as {text, Binary}: received maps, the consumer's query and hits included, come back with binary keys.

Summary

Functions

The realm NAME the topics carry must be the realm the pool uses: a topic naming another realm reaches nobody.

Read a received payload as Kind. {error, malformed} for anything without the contract's keys and types; a consumer drops those rather than crash on another node's bad frame.

The procedure every shard of Org provides. An org that would not parse back as the namespace (empty, _, or holding a /) is refused.

A hit carries at least a binary id and a numeric score, under atom or binary keys.

Types

embedding/0

-type embedding() :: #{model := binary(), dim := pos_integer()}.

fact/0

-type fact() :: shard_summarized | shard_withdrawn.

kind/0

-type kind() :: fact() | query_shard | shard_answered.

Functions

check_realm_name(Name, Realm)

-spec check_realm_name(binary(), <<_:256>>) -> ok | {error, {realm_name_mismatch, binary()}}.

The realm NAME the topics carry must be the realm the pool uses: a topic naming another realm reaches nobody.

parse(Kind, Payload)

-spec parse(kind(), term()) -> {ok, map()} | {error, malformed}.

Read a received payload as Kind. {error, malformed} for anything without the contract's keys and types; a consumer drops those rather than crash on another node's bad frame.

plain(M)

-spec plain(term()) -> term().

procedure(Org)

-spec procedure(binary()) -> binary().

The procedure every shard of Org provides. An org that would not parse back as the namespace (empty, _, or holding a /) is refused.

query_shard(Query, TopK, _)

-spec query_shard(map(), pos_integer(), embedding()) -> map().

shard_answered(ShardId, _, Hits)

-spec shard_answered(binary(), embedding(), [map()]) -> map().

shard_summarized(ShardId, _, Topics, Bloom, AtMs)

-spec shard_summarized(binary(), embedding(), [binary()], binary(), integer()) -> map().

shard_withdrawn(ShardId, AtMs)

-spec shard_withdrawn(binary(), integer()) -> map().

topic(RealmName, Org, Fact)

-spec topic(binary(), binary(), fact()) -> binary().

valid_hit(Hit)

-spec valid_hit(term()) -> boolean().

A hit carries at least a binary id and a numeric score, under atom or binary keys.