AI (artificial intelligence) Learning · 07 / 08

RAG (Retrieval-Augmented Generation) Integration

Retrieval over contracts, policy and pricing for the invoicing system: clause-level indexing, access-filtered retrieval, cited answers, grounding checks and evaluation.

What the knowledge base is for

Exceptions turn on text: the clause in a supplier contract that allows or forbids a charge, the AP (Accounts Payable) policy that sets a threshold, the pricing schedule that fixes a unit price. A retrieval-augmented system finds the right passages, and the answer is only as good as those passages and the checks on the answer. See ADR-004.

The pipeline

Retrieval-augmented generation for contracts and policy Indexing runs ahead of time: documents are parsed into clause-level chunks, tagged with vendor, dates and access groups, and embedded into a hybrid index. At question time, the query is filtered by tenant and access, retrieved, reranked, answered with citations and checked for grounding before it is returned. INDEX · AHEAD OF TIME Sources contracts · policy · pricing Parse & chunk by clause, with headings Attach metadata vendor · dates · ACL Embed & index vector + keyword (BM25) ANSWER · PER QUESTION Question user or agent Filter tenant · ACL · vendor Retrieve top 40, hybrid Rerank top 6 passages Generate answer + citations index lookup Grounding check every claim cited? Answer or route to human review No supporting passage means no answer: the system says so and routes the question to a person.
Answers are built only from retrieved, access-checked clauses, and each one cites its source.
  1. Parse by clause

    Layout-aware parsing keeps headings, clause numbers and tables. Each chunk is one clause or table row group, prefixed with its heading path.

  2. Attach metadata

    vendor_id, document type, effective and expiry dates, version, and the access groups allowed to read it.

  3. Index hybrid

    Dense embeddings for meaning plus BM25 (Best Matching 25 ranking) for exact terms such as clause numbers and PO (Purchase Order) references.

  4. Filter at query time

    Tenant, vendor and access group are applied as hard filters before ranking. The model never sees a passage the user cannot read.

  5. Retrieve and rerank

    Top 40 candidates by hybrid score, reranked to the top 6 passages.

  6. Answer with citations

    The model answers only from those passages and must cite a clause for each claim.

  7. Check grounding

    A second check confirms every claim maps to a cited passage. Failures route to a human.

The corpus

SourceWhat it contributesRefreshAccess
Supplier contractsCharge rules, receipt and invoicing clauses, payment termsOn signatureAP and procurement
AP policy handbookApproval bands, tolerances, dispute procedureQuarterlyAll AP staff
Pricing schedulesAgreed unit prices by vendor and periodOn changeAP and procurement
Purchase order termsStandard terms attached to POsOn releaseAll AP staff

Only the clauses a user is entitled to see are ever retrieved. Restricted contract pricing stays with procurement.

A question and its grounded answer

The exception agent asks whether the supplier may bill for a quantity the buyer did not receive. The excerpt below is fictional contract text, used for the demo.

answer record · trace trc_7f3a9c
Question: Can Example Supplies Ltd invoice for quantity above the goods receipt?

Retrieved (rank 1, score 0.91)
  doc:      contract/V-10442-2025-msa.pdf   version 3   effective 2025-01-01
  clause:   7.3 Receipt and invoicing
  text:     "Supplier shall invoice only for goods or services accepted by Buyer at
             goods receipt. Quantities invoiced above accepted quantities are not
             payable and shall be credited."

Answer (grounded)
  The supplier may invoice only for quantities accepted at goods receipt. Quantities
  above accepted quantities are not payable and must be credited (clause 7.3).

  citations: [contract/V-10442-2025-msa.pdf#7.3]
  grounding: 1/1 claims cited · confidence 0.94
  action:    dispute 4 units ($720.00); approve accepted quantity

Evaluation

The knowledge base is judged on evidence, not impressions. A golden set of questions with known source clauses is run on every change to the chunker, the embedding model, the rankers or the prompt.

MeasureWhat it checksIllustrative threshold
Recall@6The right clause appears in the top six passages≥ 0.90
Citation precisionCited clauses actually support the claim≥ 0.95
FaithfulnessClaims contain nothing beyond the cited text (checked by a model acting as judge, plus a human sample each month)≥ 0.97
Refusal accuracyOut-of-scope questions get no answer rather than a guess100% on the refusal set
Access leakageRestricted passages never appear for unauthorised usersZero, tested with a permissions suite

When it says no

Build this for your business

This example uses a generic invoicing system, but the same pattern — orchestrated steps, governed tools, grounded knowledge and a documented lifecycle — fits most back-office processes. We can scope a pilot on your own documents and systems.

Book a discovery call