Skip to content
All insights

Guide6 min readAahlan team

Retrieval for Arabic documents: making RAG work on scanned PDFs

A knowledge assistant is only as good as the text it can find. For Arabic archives full of scanned PDFs, that means getting OCR, normalisation, chunking and search right before any model is involved.

  • Arabic NLP
  • Retrieval
  • Knowledge assistants

Retrieval-augmented generation, or RAG, is the standard way to build an assistant that answers from an organisation’s own documents. The model does not memorise the documents. A search step finds the relevant passages, and the model answers from them, citing where they came from. When it works, staff get a direct answer with the source one click away.

In many organisations in the Kingdom, the documents that matter most are scanned PDFs: signed contracts, circulars, older policies, correspondence with stamps and handwritten notes, tables of figures. A RAG system built for clean, born-digital English text performs poorly on this material, and the failure is quiet. The assistant does not crash; it simply cannot find the right passage and answers from the wrong one. This guide covers what we do at each stage to avoid that.

OCR: where most problems begin

If the text extracted from a page is wrong, nothing downstream can fix it. Choose the optical character recognition (OCR) engine by testing it on your own documents, not on published benchmarks.

  • Mixed Arabic and English pages. Contracts and technical documents switch language within a line. Check that the engine handles both scripts on the same page, keeps numbers, dates and reference codes intact, and does not reverse the direction of embedded English.
  • Tables. Fee schedules, specifications and financial statements lose their meaning if rows and columns are flattened into one stream of words. Use layout-aware extraction that keeps table structure, and store tables as tables.
  • Stamps, signatures and seals. They overlap the text and produce noise. Detect them as regions, record that they exist (“stamped”, “signed”), and exclude their pixels from text extraction.
  • Handwriting. Modern engines read printed Arabic well; handwritten Arabic, especially in margins and annotations, is far less reliable. Flag handwritten regions, index them separately with lower weight or route them for human transcription, and never let the assistant present them as certain.
  • Quality checks. Sample pages from every source and document type, compare the extracted text with the page, and record a confidence score per page. Pages below a threshold go to a review queue instead of the index.

Layout and reading order

Arabic runs right to left, but a page can also hold left-to-right blocks, two columns, headers, footers and side notes. OCR output often puts these in the wrong order, so a sentence ends up joined to a footer or to the opposite column. Detect the layout first — columns, headings, paragraphs, tables, headers and footers — and rebuild the reading order from it. Drop repeated headers and footers from the indexed text, but keep page numbers as metadata.

Arabic normalisation

Arabic has spelling variation that is harmless to a reader and damaging to a search index. The same word may be written with different forms of alef, with or without diacritics, or stretched with tatweel for layout. We normalise a copy of the text for indexing:

  • Alef variants: أ and إ and آ are all mapped to ا, so أحمد and احمد match.
  • Taa marbuta and haa: a final ة and a final ه are unified for matching, so مدرسة and مدرسه are treated as the same word.
  • Alef maqsura and yaa: ى and ي are unified, so مستشفى and مستشفي match.
  • Tatweel: the stretching character ـ is removed, so التـــقرير becomes التقرير.
  • Diacritics: short-vowel marks such as fatha, damma, kasra and shadda are removed for indexing, so مُعَلِّم matches معلم.
  • Digits: Arabic-Indic and Western digits (٠١٢ and 012) are indexed in one form, so a reference number matches however it was typed.

Chunking by structure

RAG systems split documents into chunks: small enough to search precisely, large enough to answer from. Splitting by a fixed number of characters is simple, and it works badly on formal Arabic documents, where one article of a regulation or one clause of a contract is the natural unit of meaning.

  • Split by headings, articles, clauses and sections, using the layout detected earlier.
  • Keep each table whole with its title and column headings, or split it by rows with the headings repeated.
  • Attach context to every chunk: document title, section path (for example, Chapter 3 › Article 12), date, version and language.
  • Keep a small overlap between neighbouring chunks, so a sentence split across a boundary is not lost.
  • Store the page number and the position of each chunk on the page, so every answer can be traced to the exact place it came from.

Hybrid search, re-ranking, citations and permissions

Semantic search with embeddings finds passages that mean the same thing in different words, including across Arabic and English. Keyword search (BM25) finds exact terms: reference numbers, names, article numbers, product codes. Arabic archives need both. Run them together, merge the results, and pass the top candidates to a re-ranker — a model that reads the question and each passage side by side and orders them by relevance. Choose an embedding model and a re-ranker that have been evaluated on Arabic, and test them on your own questions.

Every answer should cite the document, the page and, where possible, the region on the page, so the user can open the scan with the passage highlighted and check it. If the retrieved passages do not support an answer, the assistant should say so rather than guess.

Permissions belong in retrieval, not in the answer. Store the access rules of each source document with its chunks, and filter search results by the user’s permissions before anything reaches the model. A model cannot leak a passage it never received.

Evaluate with real questions

Collect real questions from the people who will use the assistant — in the Arabic and English they actually write, including dialect, spelling mistakes and abbreviations — and record the document and page that answer each one. Measure retrieval separately from answering: did the right passage appear in the top results, and did the answer use it correctly? When quality drops, this tells you whether to fix OCR, chunking, search or the prompt.

The table below summarises the most common problems on scanned Arabic archives, how they show up, and where the fix lies.

ProblemSymptomFix
Poor OCR on scansThe right document exists but is never found; quotes come back garbledTest engines on your own pages; score confidence per page; send weak pages to a review queue
Wrong reading orderAnswers join text from different columns or from footersDetect layout before assembling text; drop repeated headers and footers
Flattened tablesWrong figures, or values attached to the wrong rowUse table-aware extraction; keep tables whole with their headings
Spelling variationA search for one spelling misses another (for example أحمد and احمد)Normalise the index and the question the same way; keep the original for display
Fixed-size chunksAnswers cite half a clause, or miss the condition that follows itChunk by articles, clauses and sections, with context attached
Embeddings aloneReference numbers and names are not matchedHybrid keyword and semantic search, followed by re-ranking
No permission filterUsers see passages from documents they cannot openFilter by source permissions at retrieval, before the model

None of this shows in a demo on ten clean PDFs. It shows on the first real archive. When we build knowledge assistants for Arabic content at Aahlan, we start with a sample of the client’s hardest documents, not their easiest.

Want to talk this through?

We are happy to discuss how this applies to your organisation — no sales script.

Newsletter

Practical AI, in your inbox.

Real use cases, Saudi regulations and what works in Arabic — once or twice a month. No spam; unsubscribe any time.

We’ll e-mail you to confirm. Unsubscribe any time — see our privacy policy.