AgentLex

Every answer, sewn to its page.

AgentLex is retrieval for documents where a wrong page is a wrong answer. It cuts clinical notes, contracts and statutes, classical texts and archives the way their authors did, finds by word and by meaning, and checks every quotation and every claim against the page it cites.

60 of 61quotations found on their page3
0.95nDCG@10 on the legal benchmark4
0.47 sto the first sources3
What changed in the metformin dose, and why?
MRN-SYN-0042 · 6 encounters searched · 3.1 s

It was doubled from 500 mg to 1000 mg twice daily after an A1c of 8.4% 1, because the lower dose had been tolerated without GI upset 1. A repeat A1c is due in three months 1.

3 of 3 claims supported AL-7C21E0B4 · p. 3
Progress note · Internal medicine · 03/02/2026p. 3 of 4

Labs

A1c 8.4% on 03/02, up from 7.6% in November. Creatinine 0.9 mg/dL, stable.

Assessment and plan

Type 2 diabetes mellitus (E11.9), above goal. Metformin increased from 500 mg to 1000 mg BID; patient tolerated 500 mg without GI upset. Continue lisinopril 20 mg daily. Repeat A1c in three months.

From a stack of pages to an answer you can check.

Six steps, each one an endpoint you can call alone. Use the whole thread, or only the part your pipeline is missing.

i

Cut where the author cut

Clinical notes by section, with medication lists and lab tables kept whole. Contracts and codes by their hierarchy, each definition a passage of its own. Classical print with body and footnotes apart. Prose by headings. A table is never split mid-row.

POST /documents · POST /chunk
Medications, 3 items kept wholemedication
Labs, table with its headerlab · table
Article 4 › 4.2 › (b)clause
“Processor” means…definition
ii

Find by word and by meaning

Keyword and semantic search fused by rank, then reranked. Queries are expanded the way your documents are written: HTN becomes hypertension, § becomes section. Quoted phrases must match. Filter by document, passage kind, metadata and date.

POST /search
query "metformin" dose change HTN expand HTN → hypertension filter patient = MRN-SYN-0042, kind = medication
Progress note, p. 3
Telehealth note, p. 1
iii

Copy, never paraphrase

A fast reader copies out only the sentences that answer the question. Code then looks for each one on its page; anything it cannot find there is discarded before you ever see it.

POST /extract
“Metformin increased from 500 mg to 1000 mg BID”on page
“Dose raised because of weight gain”not found, dropped
iv

Research, then write

The question is searched before the model speaks, so sources arrive at once. An agent then searches what the first pass missed and reads where a passage is cut short. The answer streams, written from those pages alone.

POST /research · stream: true
search the question itself 8 pages search "A1c" kind = lab 3 pages read Progress note, p. 3 in full done 11 pages, writing
v

Check it twice

Every quotation is matched letter for letter against the page it cites. Every claim is judged against its own sources and labeled supported, partial, unsupported or uncited, so your interface can show which sentences stand on the page.

verification · claims · quotes
The dose was doubled after an A1c of 8.4%.supported
It was tolerated without side effects.partial
Kidney function was normal.uncited
vi

Keep identifiers close

Social Security numbers, record numbers, phone numbers, emails and names after labels are masked before text reaches an embedding or language model, or redacted before it is stored. They are never logged.

settings · mask_identifiers · redact_storage
Patient NAME-1 (MRN-1), DOB DOB-1, reached at PHONE-1 to discuss results.

Built for libraries where the page is the proof.

Each kind of document has its own chunker, chosen automatically or by name, so a passage is a unit its readers would recognize.

Rx

Clinical records

One patient's notes across years: medication and lab passages found by name and section, identifiers masked before any model sees them.

sectionmedicationlabdiagnosis
§

Law and policy

Statutes, contracts and rulings where an answer is only as good as the clause it cites, read as enacted, with its place in the hierarchy attached.

clausedefinitioncitation
ع

Classical scholarship

Arabic print and critical editions: body and footnotes apart, a hadith kept with its chain, every quotation checked letter for letter.

footnotehadithverse

Archives

Letters, minutes and oral histories, with speakers, dates and places as filters. Search a decade of correspondence and land on the line.

speakerdateheading

In use today at

  • KhateebNotesresearch and khutbah preparation
  • Noorani LMScourse library search
  • KhateebNotes Enterpriselive khutbah, citations on screen

Measured, not described.

Every setting was chosen by a race on real questions, graded the same way for every variant. Run the same race on your own corpus with POST /evaluate.

0.81nDCG@10 with whole pages as the search unit, against 0.69 for 500-character chunks1
0.79nDCG@10 with weighted fusion and a reranker, up from 0.57 without the reranker2
60/61quotations in researched answers found verbatim on the page they cite3
0.47sto the first sources on the fast tier; the full cited answer took a median of 12.8 seconds3

The benchmark that ships with AgentLex

Three fictional corpora, 25 questions each, every answer a verbatim passage in a named document. scripts/bench.mjs reruns it on any build; the console loads the same corpora.4

CorpusDocumentsKeywordHybridHybrid + rerankFound in top 10
Clinical notes53 encounters, 10 patients0.800.830.8925 of 25
Legal texts12 contracts, codes and opinions0.740.730.9525 of 25
Archive32 letters, minutes and transcripts0.860.900.9625 of 25
1 KhateebNotes chunk-index race, 9 October 2026: 23 whole books, 20 Arabic topical questions, pages graded by a model judge.
2 KhateebNotes planner-replay benchmark, October 2026: 40 questions, research tier, graded blind. Keyword weight 0.5 against semantic 1.0.
3 KhateebNotes research-agent race, 9 October 2026: 20 questions over 10,710 classical Arabic books, fast tier.
4 nDCG@10, 15 October 2026, Jina embeddings v3 and jina-reranker-v3; hybrid search with the local hashed embedder and no reranker scores 0.71, 0.75 and 0.76. The corpora are fictional (invented patients, parties and places) and ship in data/fixtures.

A small API with the checks built in.

JSON over HTTP, two SDKs with no dependencies, and an event stream your interface can render as it arrives.

import { AgentLex } from "agentlex";

const agentlex = new AgentLex({ apiKey: process.env.AGENTLEX_KEY });

// Identifiers are masked before text reaches any model.
const col = await agentlex.collections.create({
  name: "Cardiology notes",
  settings: { mask_identifiers: true },
});

await agentlex.documents.add(col.id, {
  title: "Progress note",
  metadata: { patient: "MRN-SYN-0042", date: "2026-03-02" },
  text: note,
});

The research stream

NDJSON, one event per line, in this order.

  1. statussearching
  2. query"metformin" dose change · hybrid · 8
  3. sources11 pages, 4 documents
  4. deltaIt was doubled from 500 mg to…
  5. answer3 citations
  6. claims3 of 3 supported
  7. doneresult, verification, usage

Any text format

Text, Markdown, HTML, CSV, TSV, JSON records and printed pages with their numbers.

Your models, or ours

Embeddings from Jina, OpenAI or your own server; reranking from Jina, Cohere or Voyage; answers from Claude.

Read the reference

Every endpoint and field in the docs, plus an OpenAPI file.

Questions, answered.

Anything else, write to us.

What is AgentLex?
A retrieval API for documents where a wrong page is a wrong answer. You add documents to a collection; AgentLex cuts them into pages and passages the way their authors structured them, indexes them for keyword and semantic search, and answers questions with quotations and claims checked against the page they cite.
Who is it for?
Teams building on clinical records, statutes and contracts, classical and critical editions, and archives: anyone whose readers will ask where an answer came from and expect to see the page. It is built for developers, and no retrieval expertise is needed to use it well.
Does my data train a model?
No. Documents are returned only to the account that indexed them, nothing you index trains a model, and the Turath corpus is not part of the service. You bring your own documents and get answers from them alone.
Which formats and languages?
Plain text, Markdown, HTML, CSV, TSV, JSON records, and page arrays that carry printed page numbers. Four chunkers: clinical, legal, classical Arabic print and general prose, chosen automatically or by name. Search and verification work in English and Arabic, with Arabic spelling variants and vowel marks set aside when comparing.
Can it run in my own cloud?
Yes, on Enterprise: a dedicated index and region, your own embedding and reranking models, and identifiers that never leave your account. Contact sales to set it up.
How is a quotation verified?
After an answer is written, every quotation in it is looked up on the page it cites. It counts as verified when it is found there letter for letter, or equal once vowel marks and letter variants are set aside, and the result says which. A quotation that is not on its page is reported as such, never silently kept.
What happens when the sources do not answer?
The answer says so. Nothing is filled in from memory, and a claim that no source supports is labeled unsupported or uncited rather than smoothed over.

Built for records that carry names.

The safeguards HIPAA's Security Rule asks of software are built into AgentLex, each one tested, and we sign business associate agreements. Ask us for the control mapping or a BAA.

Encrypted at restPage text, passages, titles, metadata and vectors sealed with AES-256-GCM; a tampered value fails to open.
Identifiers never leaveIn a PHI collection, names, record numbers and phone numbers are masked before any text reaches a model or embedding provider.
Every access auditedWho called, which collection and document, when, and the outcome. Never the query or the text.
Retention and deletionDocuments expire after the period you set; deleted rows are overwritten; an account can be erased with everything in it.
HTTPS onlyAPI calls over plain HTTP are refused when you require it, with HSTS and strict security headers.
BAA vendors onlyA PHI collection sends text only to vendors under a signed business associate agreement; anything else is refused, not attempted.

Bring a library. Ask it anything.

For a dedicated index in your own cloud, with your own models, talk to us. To see it work first, load a sample library in the console.

contact@khateebnotes.ai