Memory & RAG
~8 min readUpdated: November 2026

CA-RAG: Constraint-Aligned Retrieval for Zero-Omission Long-Form AI Agents

CA-RAG Constraint-Aligned RAG architecture showing ontology schema matching, policy knowledge graph expansion, and dense vector retrieval

CA-RAG (arXiv:2611.33497) resolves the retrieval-generation mismatch in compliance-critical long-form RAG by conditioning section queries with ontology schema concepts and policy knowledge-graph edges before vector search. Raising Recall@6 from 0.5402 to 0.5950 and outperforming Self-RAG and Flare-RAG in reliability, it prevents mandatory clause omissions in contracts and specs.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

CA-RAG: Constraint-Aligned Retrieval for Zero-Omission Long-Form AI Agents: CA-RAG (arXiv:2611.33497) resolves the retrieval-generation mismatch in compliance-critical long-form RAG by conditioning section queries with ontology schema concepts and policy knowledge-graph edges before vector search. Raising Recall@6 from 0.5402 to 0.5950 and outperforming Self-RAG and Flare-RAG in reliability, it prevents mandatory clause omissions in contracts and specs. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Exampleca-rag-compliance-agent.ts
ca-rag-compliance-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Constraint-Aligned RAG orchestrator: extract ontology + policy KG obligations before vector search
const complianceAgent = createAgent({
agentId: 'ca-rag-contract-author',
provider: 'openai',
baseUrl: process.env.VLLM_BASE_URL ?? 'http://127.0.0.1:8000/v1',
apiKey: 'local-vllm',
model: 'meta-llama/Llama-3.1-8B-Instruct',
workspacePath: process.cwd(),
tools: ['filesystem', 'search', 'terminal'],
permission: 'ask-default',
mcp: [
{
id: 'policy-kg',
name: 'Policy Ontology & KG MCP',
description: 'Query ontology classes and requires/permits/prohibits policy graph edges',
command: 'python3',
args: ['scripts/policy_kg_mcp.py'],
enabled: true,
},
],
});
complianceAgent.on('permission.required', (event) => {
const allowed = ['read_file', 'write_file', 'grep', 'glob', 'kg_expand_constraints'];
complianceAgent.resolvePermission(
event.data.toolCallId,
allowed.includes(event.data.toolName) ? 'allow' : 'deny'
);
});
async function main() {
const res = await complianceAgent.run(
'Generate Third-Party Transfer section for DSA-Finance: expand ontology/KG obligations via policy-kg MCP, retrieve k=6 evidence chunks, and audit clause completeness.'
);
console.log('CA-RAG generation status:', res.status);
}
main().catch(console.error);
Video Guides

Watch: Related Video Guides

Agentic RAG Simply Explained

RAG Explained: From BM25 to Agentic RAG | Stanford CS329Z Lecture 3 with Diyi Yang

What Is CA-RAG? Solving the Retrieval–Generation Mismatch

CA-RAG (arXiv:2611.33497) is a retrieval-conditioning framework that augments section-level RAG queries with ontology schema constraints and policy-grounded knowledge-graph (KG) relations before dense vector search. By shifting structural alignment upstream to retrieval time, it recovers mandatory compliance evidence that semantic similarity alone misses.

Standard RAG conditions generation on R(x), assuming cosine similarity to a section heading surfaces everything needed. In long-form contracts, clinical docs, or regulatory disclosures, that fails structurally: querying *"Third-Party Transfer"* in standard RAG returns generic data-sharing passages while omitting legally linked obligations like DPIA assessments, incident response duties, and onward-disclosure restrictions. Formally, CA-RAG replaces R(x) with R(x | C(x)) where C_t = C_t^onto ∪ C_t^kg injects up to m=3 ontology concepts and m=3 KG obligations (requires, permits, prohibits) into each section query q_t*.

Retrieval-Only Precision/Recall & Multi-Domain Reliability Benchmarks

Evaluated with generation disabled on manually annotated pooled top-20 evidence, CA-RAG outperforms standard dense RAG (all-MiniLM-L6-v2) at every retrieval depth k ∈ {3, 6, 9}, proving gains originate directly from better evidence selection rather than prompt engineering.

Manually Annotated Retrieval-Only Evaluation (Aggregated Across Domains)

MethodDepth kPrecision@k ↑Pooled Recall@k ↑F1@k ↑
Standard RAG30.50000.25690.3966
CA-RAG30.53110.27540.4193
Standard RAG60.52680.54020.5389
CA-RAG60.56920.59500.5672
Standard RAG90.54990.86540.6506
CA-RAG90.58660.91850.6938

Downstream Reliability (0.7 * Comp + 0.3 * Sim) Across 3 Open-Weight LLMs

MethodLlama-3.2-3B (Fin / Health / Edu)Llama-3.1-8B (Fin / Health / Edu)Mistral-7B (Fin / Health / Edu)
Standard RAG0.6156 / 0.6634 / 0.65150.6259 / 0.6560 / 0.66850.6051 / 0.6682 / 0.6588
Self-RAG0.6227 / 0.6602 / 0.61670.6024 / 0.6666 / 0.67720.6106 / 0.6625 / 0.6673
Flare-RAG0.6092 / 0.6604 / 0.64590.6145 / 0.6793 / 0.66260.6113 / 0.6780 / 0.6504
CA-RAG0.6410 / 0.6730 / 0.65210.6404 / 0.6549 / 0.68300.6329 / 0.6698 / 0.6653

Why Prompting Constraints During Generation Is Not Enough

Comparing CA-RAG against a Gen-Constraint baseline (which receives the exact same ontology and KG obligations at generation time while keeping standard RAG retrieval) exposes a classic failure mode: prompting forces the LLM to mention missing clauses without retrieved backing, lowering overall compliance and reliability.

Retrieval-Stage Conditioning vs. Generation-Only Constraints

VariantClause Coverage (%)Compliance Score (Comp.) ↑Reliability Score (Rel.) ↑
Standard RAG75.9%0.65710.6459
Gen-Constraint (Prompt Only)78.7%0.66830.6517
CA-RAG (Retrieval + Gen)77.8%0.67260.6569

Crucially, simply raising retrieval budget k does not fix standard RAG: on Finance with Llama-3.1-8B, standard RAG compliance collapses sharply at k=9, whereas CA-RAG peaks cleanly at k=6 (0.6404 reliability) with far lower latency than iterative Self-RAG or Flare-RAG loops.

python
# Minimal CA-RAG query-conditioning step before dense pgvector/FAISS search
def build_ca_query(scenario: str, heading: str, onto_terms: list[str], kg_obligations: list[str]) -> str:
    constraints = list(dict.fromkeys(onto_terms[:3] + kg_obligations[:3]))
    return f"{scenario} | Section: {heading} | Required obligations: {'; '.join(constraints)}"

Domain Alignment Nuance

CA-RAG's shared ontology used 21 classes, 15 object properties, and 169 triples (with 79, 141, and 267 domain KG entities). When ontology/KG terminology mismatches source corpora (as seen in some dense finance clauses), ensure KG edge labels mirror the vocabulary of your indexed regulatory documents.

Deploying Constraint-Aligned RAG Pipelines in Smoke Monkey Harness

For engineering teams building SOC-2 reports, Data Sharing Agreements, RFPs, or architectural RFCs inside Smoke Monkey Harness, CA-RAG eliminates silent section omissions without heavy multi-turn agentic search loops.

  1. Expose Policy Graphs as an MCP Tool: Serve your lightweight ontology and requires/permits/prohibits KG triples (< 300 entities) over a local stdio MCP server in @smoke-monkey/harness.
  2. Generate Section-by-Section with `k=6`: Rather than stuffing a 100K context window once, loop section headings through build_ca_query() at k=6 so each section receives focused, obligation-grounded passages.
  3. Gate Output with a Checklist Auditor: Run a deterministic structured-output auditor over each drafted section before committing files, flagging any required ontology slot that lacks a cited passage.
Google Search Questions & Answers

Frequently Asked Questions

Q:What problem does CA-RAG solve that standard dense RAG misses?

Standard RAG retrieves passages semantically close to a heading, often missing mandatory cross-cutting obligations (like DPIA, incident response, or retention rules). CA-RAG injects ontology and policy-KG constraints into the retrieval query before vector search.

Q:How much does CA-RAG improve retrieval metrics independently of the LLM?

With generation disabled at k=6, CA-RAG raises Precision@6 from 0.5268 to 0.5692, pooled Recall@6 from 0.5402 to 0.5950, and F1@6 from 0.5389 to 0.5672 across manually annotated test pools.

Q:Why not just pass compliance constraints in the generation prompt?

In CA-RAG's ablation, generation-only constraints achieved higher raw clause mention coverage (78.7% vs 77.8%) but lower compliance (0.6683 vs 0.6726) and lower reliability (0.6517 vs 0.6569) because the model lacked supporting retrieved evidence.

Q:Does CA-RAG require iterative LLM calls like Self-RAG or Flare-RAG?

No. CA-RAG runs constraint matching and KG expansion once per section prior to a single dense retrieval pass, keeping latency close to standard RAG while beating Self-RAG and Flare-RAG in 6 of 9 configurations.

Q:Can CA-RAG work with small open-weight models like Llama-3.2-3B?

Yes. CA-RAG achieved the highest reliability across all three tested domains (0.6410 Finance, 0.6730 Healthcare, 0.6521 Education) on Llama-3.2-3B using all-MiniLM-L6-v2 embeddings.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness