Objective
Grounded retrieval — find the passage a question is actually about — is the foundation of a trustworthy answer. In a sovereign or air-gapped deployment it must run with local inference and no egress. This recipe does exactly that: semantic retrieval over a controlled corpus, entirely inside the boundary.
Step 1: A controlled corpus with embeddings
DROP TABLE IF EXISTS enclave_docs;
CREATE TABLE enclave_docs (
doc_id TEXT PRIMARY KEY,
title TEXT,
passage TEXT,
emb VECTOR(384)
);
INSERT INTO enclave_docs VALUES
('D-118','Logistics SOP',
'Resupply convoys stage at the forward node and depart at first light under escort.',
EMBED('Resupply convoys stage at the forward node and depart at first light under escort.')),
('D-204','Comms plan',
'Primary channel is the encrypted satellite link; fall back to HF on scheduled windows.',
EMBED('Primary channel is the encrypted satellite link; fall back to HF on scheduled windows.'));
Step 2: Retrieve the passage that grounds a question
SELECT doc_id,
title,
COSINE_SIMILARITY(
emb,
EMBED('What is the fallback communications method if the satellite link fails?')
) AS sim
FROM enclave_docs
ORDER BY sim DESC
LIMIT 1;
Result — the comms question retrieves the comms plan as its grounding source:
| doc_id | title | sim |
|---|---|---|
| D-204 | Comms plan | 0.41 |
Why it matters
The retrieved passage is the citation that keeps a generated answer honest — and it is produced by local inference with nothing leaving the boundary. Combine it with entity link analysis, and record what the agent produced on a tamper-evident ledger. For the full self-hosted agent backend (memory + RAG + graph + audit), see the coding-agent backend.