No description
  • Erlang 74%
  • Rust 18.2%
  • Python 3.6%
  • Shell 3.1%
  • Dockerfile 1.1%
Find a file
beamologist 4a2526f893
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
Merge PR 10: Run the corpus-sync NIF's three builds on one cargo profile lint.yml's check job compiled native/mcl_rag_corpus_sync_nif's dependency tree three times, cold: clippy's dev check pass, the dev test build, and the release build scripts/build-corpus-sync-nif.sh makes for the NIF itself. Most of that tree is C -- vendored libgit2 and openssl-src, 5m38s of the clippy step's 6m43s in the log mcl-rag#9 quotes -- and cargo runs a build script's work once per profile, so the C was compiled twice and the job overran its 15-minute ceiling (lint runs 68 at 15m01s, and a green run at 14m26s).
2026-11-24 02:26:29 +01:00
.github Run the corpus-sync NIF's three builds on one cargo profile 2026-11-24 02:16:31 +01:00
apps The image pair is named on public ghcr, by dated tag and digest 2026-11-24 00:35:11 +01:00
architecture Say the store is SQLite: docs and the stale barrel comments 2026-11-23 12:21:54 +01:00
assets Say the store is SQLite: docs and the stale barrel comments 2026-11-23 12:21:54 +01:00
config Port the barrel-coupled tests, add the cutover tests, fix the JSON module 2026-11-23 12:15:23 +01:00
cutover The cutover script keeps no owner path 2026-11-24 00:35:17 +01:00
deploy 0.8.3: distribution and epmd bound to loopback, and no cookie ships 2026-10-17 04:35:38 +02:00
docs c4_model: the claims hold, and the gate is the current one 2026-10-24 01:40:52 +02:00
measure c4_model: the claims hold, and the gate is the current one 2026-10-24 01:40:52 +02:00
native An empty filter column means NULL, not the whole store 2026-11-23 19:16:35 +01:00
schema Bound a corpus entry's history and paths: depth and paths (#5) 2026-10-10 23:31:35 +02:00
scripts The way-back one-shot runs on a real release: erl, and MCL_DATA_DIR 2026-11-23 13:45:53 +01:00
spike spike: say it is an evidence record, not service code (mcl-rag#1 land condition) 2026-11-23 11:37:47 +01:00
test A delete by an empty column value is refused; prune reads a path-less document by its id 2026-11-23 20:46:12 +01:00
.dockerignore on mcl_om 0.27 and the rocksdb image pair; the claim says which service, which box 2026-09-24 01:51:41 +02:00
.gitignore The tested resolve: lint resolves rebar.lock, hands it on, and the build is filed for host00's signer 2026-11-23 21:32:33 +01:00
.tool-versions scaffold: rebar3 new mcl_service 2026-09-23 16:18:41 +02:00
CHANGELOG.md The cutover script keeps no owner path 2026-11-24 00:35:17 +01:00
Containerfile The image pair is named on public ghcr, by dated tag and digest 2026-11-24 00:35:11 +01:00
LICENSE scaffold: rebar3 new mcl_service 2026-09-23 16:18:41 +02:00
README.md Merge PR 8: The cutover script keeps no owner path 2026-11-24 01:20:55 +01:00
rebar.config Release 0.11.0: the SQLite store, and the forge release path it is built on 2026-11-23 21:32:33 +01:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:59:34 +01:00

mcl-rag

CI License ghcr.io BEAM Buy Me a Coffee

Macula

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 (corpus or deposit), path, content_sha256 (the sha256 of the stored text), plus repo_id and commit for corpus content, the lines for a chunk, and deposited_by for a deposit whose depositor is known. commit is 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 under also_in.

  • Every answer names its corpus. answer_query replies {corpus_hash, hits}. describe_corpus returns corpus_hash, model, dim and repos (id, url, branch, and the commit each repo is served at; a repo whose first refresh has not finished is left out). corpus_hash is 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_corpus also returns signature, a macula signed object (CBOR bytes, carrying its key) over {corpus_hash} under the label macula-rag corpus v1, and signed_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/6 with #{provider => P}; a call/5 caller treats the corpus as unsigned) and checks the description with macula_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:

  1. The registry package may be created private, and the pull then fails on the host with a bare unauthorized that names nothing. Check it after the first build. On ghcr the org.opencontainers.image.source label in the Containerfile is what links the package to the repository.
  2. The host needs MCL_REALM, MCL_REALM_NAME, MCL_REALM_KEY, the stations it dials (each seed paired with its node id) and MCL_RAG_IMAGE_DIGEST supplied from its deploy config, plus its own ollama on 127.0.0.1:11434 holding 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.
  3. The data volume is the memory. Recreating the container keeps it, but removing mcl-rag-data wipes 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.