- Erlang 74%
- Rust 18.2%
- Python 3.6%
- Shell 3.1%
- Dockerfile 1.1%
|
All checks were successful
build-and-push / guard-1 (push) Has been skipped
c4 model / c4-model-1 (push) Successful in 5s
c4 model / c4-model (push) Successful in 0s
build-and-push / check (push) Successful in 5m52s
lint-and-test / check (push) Successful in 5m51s
lint-and-test / The tested lock arrives whole (push) Has been skipped
build-and-push / The tested lock arrives whole (push) Has been skipped
build-and-push / test (push) Successful in 0s
build-and-push / build-and-push (push) Successful in 2s
build-and-push / File the tested resolve for the signer (push) Successful in 2s
build-and-push / guard (push) Has been skipped
build-and-push / attest (push) Successful in 0s
|
||
|---|---|---|
| .github | ||
| apps | ||
| architecture | ||
| assets | ||
| config | ||
| cutover | ||
| deploy | ||
| docs | ||
| measure | ||
| native | ||
| schema | ||
| scripts | ||
| spike | ||
| test | ||
| .dockerignore | ||
| .gitignore | ||
| .tool-versions | ||
| CHANGELOG.md | ||
| Containerfile | ||
| LICENSE | ||
| README.md | ||
| rebar.config | ||
| SECURITY.md | ||
mcl-rag
The mesh shared memory: retrieval over a realm-bound corpus, and the deposits agents remember into it
Architecture: the C4 model (context, containers, components) is in architecture/README.md.
What it does
It holds the mesh's shared memory: documents from a set of git repos plus the
knowledge agents deposit, chunked and embedded (384 dims,
intfloat/multilingual-e5-small, from the node's own ollama on loopback, where
it is named macula/multilingual-e5-small:f16; stored text is embedded with
e5's passage: prefix and queries with query: , see
measure/e5_prefixes),
and answers retrieval over it. It also serves as one shard of the org's
federated retrieval (macula_rag, procedure mcl-rag/rag.query_shard_v1).
The data is one SQLite file, rag.sqlite (documents, vectors and topics), under
MCL_DATA_DIR, next to the corpus checkouts. deploy/corpus-repos.json lists the repos and the branch
each one is followed on; nothing is pinned, and an entry may bound its history
(depth, a shallow first clone) and the files it ingests (paths) so a big code repo
does not cost its whole history and tree (mcl-rag#5; the
measurements
picked those bounds). Every 2 hours the node fetches each
branch and checks out its head (vendored libgit2, HTTPS only). When a head has
moved, it re-ingests the files that changed, retires the files that are gone
(their chunks with them), and drops everything of a repo that left the list.
Licence files, .github templates and copyright headers are left out, and
identical text is returned once per query. The ids in that file are the
watermark namespace, so renaming one re-embeds that repo from scratch.
To serve your own corpus, see Run your own corpus.
The procedures
Each of the service's own procedures is served as mcl-rag/<name> (version 1)
under the org mcl-rag. The realm has to grant this node a provider
authorization for each one (D25); until it does, /health names the missing
grants.
| Open to any caller the station admits | Operator-only |
|---|---|
describe_corpus, ingest_status, answer_query, rerank_results, search_chunks_semantic, get_chunk_by_id, list_chunks_by_source, get_source_by_id, list_sources_page, get_document_verbatim, add_knowledge |
prune_chunks, retire_document, ingest_document, upload_knowledge, embed_document, classify_topics, schedule_reembed, detect_corpus_change |
mcl-om adds mcl-rag/info and mcl-rag/get_limits to every service, both
open, and capabilities/0 is the list.
The loopback HTTP API has no route for get_document_verbatim, describe_corpus
or ingest_status; those three are mesh only.
Operators are the node ids in MCL_RAG_OPERATORS. The check reads the
caller as macula verified it on the wire, never a field the caller wrote. The
operator-only procedures refuse everyone else with not_an_operator. An empty
list means nobody, which is a valid setting. Anyone running
macula-cli upload_knowledge has to be listed.
Known callers: macula-mcp (mesh_recall, mesh_remember), macula-cli and
macula-lazymesh.
Provenance and corpus identity
mcl-rag is the reference implementation of the RAG service contract
(macula-architecture plans/DESIGN_RAG_SERVICE_CONTRACT.md).
-
Every hit says where it came from. A search hit, a chunk fetched by id, a source row, a verbatim document and a federated hit all carry
provenance:kind(corpusordeposit),path,content_sha256(the sha256 of the stored text), plusrepo_idandcommitfor corpus content, the lines for a chunk, anddeposited_byfor a deposit whose depositor is known.commitis the branch head the text is present at: the head it was ingested at, or a later head the refresh found the file unchanged at. A hit whose text also occurs in other files names them underalso_in. -
Every answer names its corpus.
answer_queryreplies{corpus_hash, hits}.describe_corpusreturnscorpus_hash,model,dimandrepos(id, url, branch, and the commit each repo is served at; a repo whose first refresh has not finished is left out).corpus_hashis the lowercase hex sha256 of the RFC 8785 canonical JSON of{"dim", "model", "repos": [{"branch", "commit", "id", "url"}]}, repos in list order, so a caller can recompute it. With no corpus list, the corpus is empty and still named; a list that is refused makes both calls refuse. -
The operator signs its corpus. With an identity key,
describe_corpusalso returnssignature, a macula signed object (CBOR bytes, carrying its key) over{corpus_hash}under the labelmacula-rag corpus v1, andsigned_by, the hex node id of that key, a display label only. Without an identity key the corpus is unsigned and neither field is present.The signature is static, so any provider can copy another's. A caller calls P itself (
macula:call/6with#{provider => P}; acall/5caller treats the corpus as unsigned) and checks the description withmacula_rag:verify_corpus(Description, P, Profile), which derives the signer from the verified key and recomputes the hash. The hash and the signature are macula_rag's, and its guide (The RAG service contract) is the canonical text, with frozen vectors.
Health
/health, on the Unix socket /run/mcl/health.sock inside the container (scripts/health.sh asks it), returns ok once the store is open and the org
can reach this shard. Opening the store rebuilds the vector index, which takes
over three minutes on the full corpus (longer on a Celeron). While it
runs, /health reports degraded, store_opening and every call is refused with
{error, store_opening}. That is by design. The image's health check has a
900 s start period to cover the open.
Running it
rebar3 compile
rebar3 eunit
rebar3 ct # starts the real application, per suite
rebar3 dialyzer
rebar3 lint
scripts/health.sh # against a running node
The build and CI run in ghcr.io/macula-io/macula-ci-otp, and the image runs on
ghcr.io/macula-io/macula-pq-runtime, each pinned by its dated tag and its
digest (the fleet's plain pair). It is named on public ghcr, not on the forge
registry, because host00's image signer builds the Containerfile and refuses a
git.macula.io/ base it cannot cosign-verify. Nothing links
librocksdb any more: the store is one SQLite file through the mcl_rag_store_nif
Rust NIF, which bundles its SQLite. This service's two NIFs
(native/mcl_rag_corpus_sync_nif and native/mcl_rag_store_nif, both Rust) are
built inside the image, never copied in; locally, scripts/build-corpus-sync-nif.sh
and scripts/build-store-nif.sh build them into priv/lib/, which is gitignored.
podman build -t mcl-rag -f Containerfile .
Configuration
| Variable | Default | Meaning |
|---|---|---|
MCL_REALM |
required | 64-hex realm tag, the sha256 of the realm's name. No default: a service that guesses its realm announces itself where nobody can attribute it. |
MCL_REALM_KEY |
required | The realm's public signing key, hex encoded: the trust anchor, not an identifier. Every org-namespaced advertisement is verified against it, so without it nothing resolves, the boot claim never reaches the realm, and the service stays green while unreachable. Public material, not a secret. |
MACULA_STATION_SEEDS |
required | Station hosts to dial, host[:port], comma-separated. No default: naming a realm costs nothing, dialling a fleet station from every dev clone does. |
MACULA_STATION_NODE_IDS |
required | The matching 64-hex station node ids, comma-separated, index-paired with the seeds. The 11.x dial is pinned (D5): mcl_om refuses to boot a pool with an unpinned seed. |
MCL_REALM_NAME |
required | The realm's name. Its sha256 must be MCL_REALM, or joining the federation is refused and /health reports down. |
MCL_RAG_OPERATORS |
empty | Node ids (64 hex, comma-separated) allowed to call the operator-only procedures. Empty means nobody. |
MCL_RAG_CORPUS_REPOS |
/etc/mcl-rag/corpus-repos.json |
The corpus list: every repo and the branch it is followed on, in the shape schema/corpus-repos.schema.json publishes. A list that breaks it is refused whole, naming the entry. See Run your own corpus. |
MCL_DATA_DIR |
/var/lib/mcl-rag |
The store and the corpus checkouts. Mount it on a persistent volume (compose names it mcl-rag-data). |
MCL_RAG_IMAGE_DIGEST |
required by the compose file | sha256:<digest> of the released image to run: the compose file runs the image by digest, never by tag. |
MCL_RAG_HTTP_PORT |
8451 |
The local HTTP API. Registered in macula-fleet PORTS.md, like the health port. |
MCL_RAG_HTTP_IP |
127.0.0.1 |
Keep it on loopback: the API has writes and no authentication. |
MCL_SERVICE_NAME |
mcl-rag |
Label on the boot claim the realm's operator sees on the Providers desk. |
MCL_BOX |
from the host | Label naming the box, also on the boot claim. Set it where you deploy. |
| (none) | /run/mcl/health.sock |
/health is served on this Unix socket inside the container (mcl_om health_socket); no health port is bound. scripts/health.sh asks it. |
MCL_NODE_NAME |
mcl_rag |
Erlang node name. |
MCL_NODE_HOST |
127.0.0.1 |
Erlang node host. |
MCL_COOKIE |
none, required | Erlang cookie. Nothing ships a default (mcl-rag#32): deploy/docker-compose.yml refuses to start without one. Under Quadlet or a plain podman run it is not enforced: relx substitutes an empty value, the start script does not refuse, and erl mints a random cookie into /app/.erlang.cookie on each start, so the node starts with a cookie nobody chose. Set it from your own secret file either way. |
ERL_EPMD_ADDRESS |
127.0.0.1 |
Binds epmd to loopback, beside the node's own distribution listener, which -kernel inet_dist_use_interface {127,0,0,1} in config/vm.args.src keeps on loopback too (mcl-rag#32). |
deploy/docker-compose.yml runs it, and carries what the service knows about
itself. If you deploy through something else, let that carry placement: which
host, which station, which realm, which secret store. Keeping the two apart is
what stops a config table in a README and the real environment drifting.
Deployment
A v* tag publishes ghcr.io/macula-services/mcl-rag:<version> and nothing else, signed
by digest with its SBOM and provenance (macula-ci-images' attest-image.yml). A push to
main publishes :main and :<sha>, which nothing follows. Nothing moves :latest.
The fleet runs a release by digest: macula-fleet's pin-releases workflow finds the signed
release, verifies it was signed on its tag and pins <version>@sha256:<digest>
(macula-fleet#14, #15), so a green v* tag is the deploy. To roll back, revert the pin and
hold the image there.
Three things CI cannot do for you:
- The registry package may be created private, and the pull then fails on
the host with a bare
unauthorizedthat names nothing. Check it after the first build. On ghcr theorg.opencontainers.image.sourcelabel in the Containerfile is what links the package to the repository. - The host needs
MCL_REALM,MCL_REALM_NAME,MCL_REALM_KEY, the stations it dials (each seed paired with its node id) andMCL_RAG_IMAGE_DIGESTsupplied from its deploy config, plus its own ollama on127.0.0.1:11434holding the embedding model (macula/multilingual-e5-small:f16) and the classifier's (qwen2.5:7b-instruct-q4_K_M). No API key: both models are local. - The data volume is the memory. Recreating the container keeps it, but
removing
mcl-rag-datawipes it, and the node then re-embeds the whole corpus.
The service contract
Six callbacks in mcl_rag_service, all required, all resolved by name by
mcl_om at startup on a live node. The -behaviour(mcl_om_service)
attribute turns a missing one into a compile error rather than an undef where
nobody is watching, and the eunit suite guards the attribute itself.
Licence
Apache-2.0.