Blueprint: legal RAG

Contract memory outside the context window.

Persist MATTER-level facts like governing_law and renewal_notice alongside versioned CLAUSE records the first time a contract is reviewed, then retrieve only what changed on later passes. Instead of rehydrating an entire matter for every revision, the workflow pulls active facts plus the specific clauses flagged with a revision bump, each still linked back to its supporting text.

The Legal Contract Review blueprint is a RushDB pattern that persists MATTER, CLAUSE, and FACT records with citation links so contract-review agents retrieve only changed clauses and current facts instead of reprocessing an entire matter on every revision.

Repeated contract review wastes context on facts you already know.

A contract copilot should already know the current term, governing law, renewal window, and which clauses back each fact. Without that memory, every revision reloads the full document set, re-extracts facts that never changed, and flattens clause provenance into prompt text — so revisions overwrite prior interpretation instead of building on it, and reviewers lose the citation trail behind each answer.

Before

  • Every review reloads the full document set
  • Stable facts are extracted repeatedly
  • Clause provenance gets flattened into prompt text
  • Revisions overwrite prior interpretation

With RushDB

  • Stable facts persist with supporting references
  • Changed clauses are retrieved for focused review
  • Schema keeps query planning grounded in stored labels
  • Application code measures assembled context size

Graph intelligence on ingest

Incoming data becomes queryable graph context.

Contract text arrives as MATTER and CLAUSE data at different times: a base FACT like governing_law on intake, then revised CLAUSE text like clause 8.2 on amendment. RushDB infers types on each write, auto-links CLAUSE records to their MATTER, and keeps prior clause revisions addressable instead of overwritten, so facts and the clauses that support them stay queryable together.

01

Normalize as clauses arrive

Each MATTER, FACT, and CLAUSE payload is typed on write, so renewal_notice strings and clause revision numbers are queryable immediately.

02

Auto-link nested structure

CLAUSE records nested under a MATTER are automatically related to it, keeping clause 8.2 and its revisions attached to the matter that owns them.

03

Enrich scattered sources

Suggested-relationship analysis surfaces links between FACT records and the CLAUSE text that supports them, even when they were imported in separate batches.

Suggested relationship analysis requires an LLM configured for the project. Suggestions stay in draft form until you approve them, so inferred domain meaning never mutates the graph silently. You can also add explicit relationships through the SDK or API.

Review suggested relationship patterns

Data model

One flexible graph for the workflow.

Start with the payload shape your product already produces. RushDB stores it as Records, infers typed properties, and keeps nested or approved domain relationships queryable.

Schema sketch
Contract-review payload

Changed clauses, durable facts, and references stay separate so review prompts can stay focused and cited.

{
  "matterId": "lease-2026",
  "clientId": "northstar",
  "DOCUMENT": [{
    "documentId": "lease-v3",
    "version": 3,
    "CLAUSE": [{
      "number": "8.2",
      "changed": true,
      "text": "Notice must be delivered 120 days before renewal.",
      "FACT": [{ "key": "renewalNoticeDays", "value": "120" }],
      "REFERENCE": [{ "page": 14, "sourceId": "lease-v3-p14" }]
    }]
  }]
}

Working example

Review the revision, not the whole matter.

The first pass stores clause-linked facts. A later pass retrieves active facts plus changed clauses so the application can assemble a smaller, cited review prompt.

Input
MATTER lease-2026
  FACT governing_law: "New York"
  FACT renewal_notice: "90 days"
  CLAUSE 8.2 revision: 2
    "Notice must be delivered 120 days before renewal."
Query
{
  "labels": ["CLAUSE"],
  "propertyName": "text",
  "query": "What changed about renewal notice?",
  "where": { "matter_id": "lease-2026", "changed": true }
}
Result
{
  "existing_fact": "Renewal notice: 90 days",
  "changed_clause": "Clause 8.2: Notice must be delivered 120 days before renewal.",
  "review_action": "Supersede the active renewal-notice fact."
}

Python SDK

Load schema. Retrieve the delta. Assemble a cited prompt.

The token-footprint improvement is an application-level result to measure on your own prompt assembly. RushDB supplies the persisted facts, references, schema, and focused retrieval path.

from rushdb import RushDB

db = RushDB('RUSHDB_API_KEY')

schema = db.ai.get_schema_markdown({'labels': ['MATTER', 'CLAUSE', 'FACT', 'REFERENCE']}).data
facts = db.records.find({'labels': ['FACT'], 'where': {'active': True, 'MATTER': {'matterId': 'matter-northstar-msa'}}, 'limit': 20})
clauses = db.ai.search({
    'labels': ['CLAUSE'],
    'propertyName': 'text',
    'query': 'renewal termination indemnity governing law',
    'where': {'MATTER': {'matterId': 'matter-northstar-msa'}},
    'limit': 20,
})

Implementation blueprint

Build the memoized legal RAG path.

Use this sequence to persist contract facts and retrieve focused deltas without sending an entire matter through every review run.

  1. 01Import MATTER, DOCUMENT, CLAUSE, FACT, and REFERENCE records
  2. 02Create a managed index for CLAUSE.text
  3. 03Extract durable facts with clause references
  4. 04Retrieve active facts plus changed clauses for each revision
  5. 05Measure prompt-size reduction in the application payload

Build path

  • Keep stable facts separate from clause text and revisions.
  • Preserve citation links from FACT records to supporting CLAUSE records.
  • Supersede changed facts instead of mutating history away.
  • Report token reduction only as a measured application-level result.

How it works

Build the smallest useful workflow first.

01

Extract durable facts once

Persist facts such as governing law, term length, and renewal notice with references to the supporting clauses.

02

Load schema before retrieval

Give the agent the live labels and fields it can query instead of allowing guessed schema names.

03

Assemble focused context

Retrieve current facts, changed clauses, and supporting references, then measure the resulting prompt payload in application code.

Know where it fits.

Measure the token claim

Report context-size reduction from the application payload. Do not present it as a generic RushDB benchmark.

Preserve legal history

Append or supersede fact and clause revisions instead of mutating away prior review state.

Questions developers ask.