The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← Back to program

← AI 320 — Applied AI, Retrieval and Reliable Automation

Weeks 6–8

Retrieval, chunking and evidence provenance

Learning objectives

  • Explain and trace the mechanisms in retrieval, chunking and evidence provenance.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.

Retrieval selects material relevant to a question. Keyword methods match terms; embedding methods compare learned representations. Semantic similarity is not the same as factual support. A passage can be topically similar while answering a different question, applying to another jurisdiction or being superseded by a later version.

Chunking divides documents into retrieval units. Very small chunks can lose context; very large chunks can dilute relevant details and exceed useful context budgets. Preserve document ID, title, date, version, location and access restrictions with each chunk. Retrieval must respect authorization before content enters the model context; hiding a confidential citation after generation does not undo disclosure.

Measure retrieval separately from answer generation. If the relevant passage is absent, improving the prompt cannot recover missing evidence reliably. Create questions with known supporting passages and assess whether the retriever returns them. Then check whether the answer uses the evidence correctly. A similarity threshold is a heuristic, not a calibrated probability that the answer is true. Version filters, exact identifiers and source-aware reranking may matter more than using a larger model.

Worked reasoning This transparent lexical baseline counts distinct shared tokens. It has no synonym handling, weighting, phrase model or authorization filter. It can retrieve a passage containing the words refund and policy even when it describes an exception rather than the general rule. Its simplicity makes failure diagnosis easier before a more complex retriever is introduced.

Extended teaching and laboratory

Retrieval ranks candidate evidence; it does not decide what the evidence means. Chunk size can separate a rule from its exception, while keyword overlap can rank a negated or outdated statement highly. Evaluate retrieval on whether required evidence is present, and evaluate answering on whether the conclusion follows from that evidence.

Authorization should restrict the candidate corpus before inaccessible passages can influence the answer. Filtering only the displayed citation can still leak private information through generated text. Record stable source IDs, versions and passage locations for reconstruction.

Worked problem A policy chunk says returns are accepted within 30 days. The following chunk excludes custom orders. A custom-order question retrieves only the first chunk. Explain the failure and repair.

Step-by-step reasoning 1. The retrieved general rule omits an applicable exception. The answer cannot safely infer universal eligibility.

  1. Preserve section context or retrieve neighboring exception-bearing passages, then evaluate the complete rule for the actual order type.
  1. Create an evaluation case requiring both chunks and score evidence sufficiency separately from fluent answer quality.
  1. Restrict retrieval to the requester’s authorized documents first. A correct answer based on private unauthorized text is still a boundary failure.

Calculate the retriever before interpreting its result

The retained project implements a small term-frequency/inverse-document-frequency cosine baseline. Its tokenizer lowercases text and extracts sequences matching

[a-z0-9]+

. This particular choice splits punctuation and does not supply stemming, multilingual tokenization or learned semantic representations. A query containing only tokens absent from the eligible vocabulary becomes a zero vector. The implementation then assigns zero similarity and returns no positively scored result, rather than dividing by zero. A useful semantic model might recognize a synonym this tokenizer misses, but that possibility requires a measured comparison.

First select eligible documents using the caller and policy snapshot. For N eligible documents, let df(t) be the number containing term t at least once. The project uses natural-log smoothed weight

idf(t)=ln((1+N)/(1+df(t)))+1

. A document's coordinate is its raw token count times this weight; the query uses the same fitted weights and vocabulary. Repeating a term changes its count, but not the document-frequency count by more than one. Cosine similarity divides the dot product by the two Euclidean lengths. It compares direction under this representation, not truth, authority or a probability of answer correctness.

Consider three fictional eligible chunks with stable IDs: A has text

refund receipt

, B has

refund refund custom

, and C has

custom excluded

. Use coordinate order [refund,custom,receipt,excluded]. Both refund and custom occur in two documents, so their weight is a=ln(4/3)+1≈1.287682. Receipt and excluded each occur in one document, giving b=ln(2)+1≈1.693147. The vectors are A=[a,0,b,0], B=[2a,a,0,0] and C=[0,a,0,b]. For query

refund custom

, q=[a,a,0,0] and its length is √2·a.

The three dot products are a², 3a² and a². A and C each have length √(a²+b²); B has length √5·a. Consequently B's score is 3/√10≈.948683, while A and C each score a/(√2·√(a²+b²))≈.428046. The implementation sorts decreasing scores and then ascending string IDs, so it returns B,A,C. The tie-break makes this fixture reproducible; it gives A no greater substantive authority than C. B ranks highly because its terms align with the query. Its three words do not establish any refund policy.

Now suppose A is the general rule's required receipt passage and C is an applicable custom-order exception. Answering a custom-order eligibility question requires both, even though B ranks first. Top-one keyword or cosine relevance does not establish complete evidence. A chunker that separates rule and exception must retain document/section relationships or use an explicitly tested neighbor-expansion strategy. Expanding neighbors must still recheck authorization and version: proximity is not permission. Large chunks can preserve qualifications while admitting irrelevant text and consuming context; small chunks can lose conditions. Compare these settings on questions with known complete support sets rather than selecting chunk size from aesthetics.

For a question whose gold support set is {A,C}, returning {A} has passage recall 1/2 and precision 1/1 under that declared labeling, but complete-support success is zero. Returning {A,B,C} has recall 1, precision 2/3 and complete-support success one. These are retrieval labels, not an assessment of whether generation used the passages faithfully. Record unsupported citations, wrong versions and unauthorized context separately. A fluent answer produced after incomplete retrieval can be a lucky unsupported answer and should not receive grounded-success credit.

Optional changed eligible corpus: complete reasoning

Remove B because the caller lacks permission. Refit on A and C only: N=2 and every remaining term occurs in one document, so every weight is c=ln(3/2)+1. The query is [c,c,0,0], while each document has two nonzero coordinates of weight c. Each score is c²/(√2c·√2c)=1/2, so A precedes C only by stable ID. Filtering B after ranking under the three-document IDF state would not reproduce this declared algorithm. More seriously, a shared vocabulary or ranking cache fitted using a restricted corpus can expose information about that corpus; specify the scope and ownership of fitted retrieval state. If the query becomes

unicorn

, no coordinate remains and both scores are zero: return the explicit no-evidence state, not an arbitrary first document. If top-two A,C are supplied, assess their conditions before composing an answer; two references alone are not entailment.

Optional criteria, one point each: calculate counts and smoothed weights; reconcile dot products, norms and ranking; recompute after eligibility changes and handle zero vectors; distinguish passage recall, complete evidence and supported answering. Explain all four for four points.

Apply the idea

A policy chunk says returns are accepted within 30 days. The following chunk excludes custom orders. A custom-order question retrieves only the first chunk. Explain the failure and repair.

Two authorized passages of the same version conflict about the deadline. What should an evidence-bounded assistant do?

Read the worked reasoning

Identify and cite the conflict, avoid selecting a convenient deadline without a justified precedence rule, and route to clarification or review. Capture both locators in the result. A retrieval score is not an authority hierarchy, so the top-ranked passage does not automatically resolve contradictory policy.

Check understanding

Why must access filtering occur before model context construction?

  1. Because semantic ranking itself grants permission
    Feedback

    Similarity and access rights are unrelated properties.

  2. Because exposing a restricted passage to generation already crosses the boundary
    Feedback

    Authorization governs the data the system may use, not just displayed links.

  3. Because hiding the link afterward always removes the disclosure
    Feedback

    Generated text can reveal content even without its citation.

Further reading

Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.

Use the preserved original investigation and connected Academy preparation/application below. Compare your reasoning with its optional complete model. Historical source directions remain in immutable edition4.

My learning →