Skip to content
OscSantoPublic

About

Multilingual semantic search for offline libraries (Kiwix ZIM files). Ask in your own words and your own language, and find the right article in Wikipedia, WikiMed and more. Runs fully offline, on low resource devices..

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Zimantic

Offline search that understands what you mean, for Kiwix ZIM files.

Zimantic adds meaning based searching on ZIM files; the compressed offline copies of Wikipedia and other websites which are published by Kiwix.

Ask a question, describe something without knowing its name, misspell it, or search in one of 100+ languages, and Zimantic looks for the article closest to what you mean. It works best in widely spoken languages. Everything runs offline, on low resource hardware as small as a Raspberry Pi Zero 2 W.

You type Kiwix search Zimantic
"what causes lockjaw" Tetanus not in the top 20 Tetanus at #1
"diabetis" (misspelled) Diabetes not in the top 20 Diabetes at #1
"糖尿病" (Chinese for "diabetes") Diabetes not in the top 20 Diabetes at #1

Searched in WikiMed, the Wikipedia medical encyclopedia ZIM. Results below.

Features

  • Search by meaning: questions and descriptions find articles even when they share no words with the title.
  • Alternate names and misspellings: "diabetis" finds Diabetes; "Leber's disease" finds Leber's hereditary optic neuropathy.
  • Multilingual: one model covers 100+ languages; a query in one language finds articles written in another. Strongest in widely used languages (see the results below).
  • Several collections at once: search any combination of your ZIMs, ranked together in one list.
  • Best of three searches: combines meaning, title-word and Kiwix full-text search into a single ranking.
  • Clean results & previews: redirects are merged into their article, so each article appears once, with its first paragraph as a preview.
  • Lightweight and offline: runs on low resource devices, such as on a Raspberry Pi Zero 2 W (512 MB RAM), using ~250–300 MB while serving.
  • Web page and JSON API: search from any browser on the network, or from your own programs.

Zimantic finds articles; kiwix-serve displays them. Searching itself does not require Kiwix, but serving the article pages does, so Zimantic works alongside Kiwix rather than replacing it.

How it works

1. Indexing a ZIM (build, once per ZIM)

What gets read. Every entry in the ZIM is visited once. Images, stylesheets and scripts are skipped. Redirects, including the small "forwarding" pages some ZIMs use instead of real redirects, are stored as title-only entries that point to their article. Thus, searching "USA" still finds the United States page.

Why the first paragraph. For each article, Zimantic keeps the title plus the first paragraph. Wikipedia's writer's guidelines require opening paragraph to summarize the whole article, so it's the most compact description. That makes it the best text to compare with questions and descriptions.

Forming a clean paragraph. Zimantic uses Wikipedia's page structure:

  • it takes the first <p> with at least 50 characters, so pages that open with a one-liner like "Mercury may refer to:" (disambiguation pages, lists) are stored as title-only;
  • it skips stylesheets, scripts and footnote markers like [1] inside the paragraph;
  • it keeps at most 1,000 characters.

Other ZIMs (Stack Exchange, Gutenberg, TED, …) aren't refused: build runs on any ZIM and applies the same first-paragraph rule to every HTML page. But nothing has been tuned or tested for them, so results depend on how each site lays out its pages. PDFs inside a ZIM are skipped.

Embedding. The title and first paragraph are turned into a vector (a list of numbers describing their meaning), currently by multilingual-e5-small (int8 ONNX, ~118 MB). Input is capped at 256 tokens.

Storage. Each ZIM gets two files in index_dir:

  • <name>.sqlite: titles, first paragraphs, paths, redirect targets, and a full-text index of the titles (SQLite FTS5).
  • <name>.faiss: the vectors, in one of two layouts depending on aritlce count:
ZIM size Vector index Why
Under 10,000 articles Flat: the query is compared with every vector Exact, and small enough (a few MB) that comparing everything is fast
10,000 articles or more IVF + 8-bit (SQ8): vectors are grouped into 4·√n clusters, and each search only scans the closest nprobe clusters (64 by default) Comparing millions of vectors per search is too slow. On WikiMed (70k articles), scanning 64 of 1,062 clusters (6%) was within a few points of scanning every cluster, at less than half the search time (26 ms vs 66 ms). 8-bit numbers were nearly exact. Heavier compression (e.g. PQ48) lost ~25% of the top hits in earlier testing.

The .faiss file is memory-mapped: the operating system reads only the clusters a search touches instead of loading the whole index into RAM. Clusters are found relative to the distance of query-to-cluster centres in vector space.

If a build stops, running it again resumes from the last saved batch.

2. Starting the server (serve, once)

At startup Zimantic loads the embedding model and opens every finished index; that is, the SQLite file , the FAISS file, and the ZIM. These stay open for as long as the server runs; nothing is reloaded per search.

A lightweight HTML page is served through FastAPI and is accessible from any browser at http://<host>:8090 (the port in config.yaml).

3. Each search

  1. Embed the query with the same model used to index

  2. Run three searches on each selected ZIM. They find the best matches in different ways:

    Search Finds Good at Time
    Meaning (FAISS) Articles whose first-paragraph vector is closest to the query (cosine similarity) Questions, descriptions, other languages ~13 ms
    Title words (SQLite FTS5, BM25 ranking) Titles containing every word of the query, including redirect titles Exact titles, alternate names (via redirect titles) ~4 ms
    Full text (the ZIM's own Kiwix index) Articles containing the words anywhere Words buried deep inside an article ~8 ms
  3. Collapse redirects: every hit on a redirect is replaced by the article it points to, and duplicates are merged, so each article appears only once.

  4. Merge the three lists with Reciprocal Rank Fusion (RRF). Their scores can't be compared (a cosine similarity, a BM25 score, a position in Kiwix's list), so RRF ignores scores and uses positions only: an article earns 1 / (60 + its position) from each list it appears in. An article found near the top by several searches beats one that's first in just one.

Timings measured on WikiMed; a whole search took 26 ms (median over 785 benchmark queries). A Raspberry Pi Zero 2 W is much slower (around 150 ms).

Compared with Kiwix search

Ask a question, get the article Ask in another language How often the right article comes first: Zimantic vs Kiwix

Measured on WikiMed, the Wikipedia medical encyclopedia ZIM (wikipedia_en_medicine_maxi_2026-04, 70,523 articles), against kiwix-serve's full-text search.

Results by type of search

#1 = the right article is the first result. Top 5 = it's somewhere in the first five. "Not in top 20" = it didn't appear in the first 20 results.

Type of search Example query → article wanted Kiwix Zimantic #1 Kiwix → Zimantic Top 5 Kiwix → Zimantic Queries
Common single words "tuberculosis" → Tuberculosis #3 #1 33% → 100% 93% → 100% 15
Exact titles "Malaria" → Malaria #2 #1 72% → 100% 100% → 100% 25
Alternate names "Leber's disease" → Leber's hereditary optic neuropathy #2 #1 52% → 82% 70% → 99% 200¹
Misspellings "diabetis" → Diabetes not in top 20 #1 0% → 60% 7% → 83% 30
First-sentence descriptions "(INN) is a non-steroidal anti-inflammatory drug (NSAID)." → Ampiroxicam #5 #1 72% → 83% 82% → 92% 200¹
Describing it without the name "poor blood flow to part of the brain that kills brain cells" → Stroke #17 #1 8% → 37% 37% → 78% 60
Questions "what causes lockjaw" → Tetanus not in top 20 #1 12% → 45% 28% → 80% 40
Questions & phrases in other languages² "Herzinfarkt" (German: heart attack) → Myocardial infarction not in top 20 #1 0% → 33% 0% → 53% 30
Words deep inside an article "When undergoing lymphadenopathy, these are described as feeling like a "firm pea"." → Facial lymph nodes #1 #2 68% → 28% 78% → 76% 200¹

¹ Generated automatically from the articles, not typed by real users. The other sets were written by hand; with 25–60 queries each, treat their numbers as accurate to roughly ±12–18 points. ² Spanish, French, German, Chinese, Hindi, Arabic, Russian, Japanese, Swahili and Portuguese, mixed.

Single words in other languages

The English articles searched with one word in another language, 15 common medical words per language (malaria, diabetes, fever, cough, pregnancy, heart, blood, …). Translations were written for this test, so less common languages may contain mistakes.

Language Example query → article wanted Kiwix Zimantic #1 Kiwix → Zimantic Top 5 Kiwix → Zimantic
English "tuberculosis" → Tuberculosis #3 #1 33% → 100% 93% → 100%
Spanish "dolor de cabeza" → Headache not in top 20 #1 13% → 60% 20% → 73%
French "tuberculose" → Tuberculosis #15 #1 13% → 53% 27% → 60%
Portuguese "coração" → Heart #4 #1 13% → 53% 40% → 80%
Afrikaans "bloed" → Blood not in top 20 #1 7% → 33% 20% → 33%
Arabic "سعال" → Cough not in top 20 #1 0% → 20% 0% → 33%
Hindi "मलेरिया" → Malaria not in top 20 #1 0% → 20% 0% → 33%
Amharic "ልብ" → Heart not in top 20 #1 0% → 13% 0% → 13%
Somali "madax xanuun" → Headache not in top 20 #1 0% → 13% 0% → 13%
Swahili, Igbo, Zulu, Kinyarwanda e.g. "ikholera" (Zulu) → Cholera not in top 20 #1 0% → 7% 0–7% → 7%
Hausa, Yoruba 0% → 0% 0% → 0%

Where Kiwix is still better, or cheaper:

  • Words buried deep inside an article. Kiwix indexes every word thus performs better on deeper searches (68% first vs 28%; in the top 5 they're nearly tied, 78% vs 76%). While Zimantic only indexes each article's title and first paragraph.
  • No setup. Kiwix search works the moment a ZIM is added. Zimantic must index each ZIM first.
  • Smaller footprint. Zimantic adds a .sqlite and .faiss per ZIM and needs more RAM.

Requirements

  • Python 3.12, 3.13 or 3.14 (the pinned numpy needs 3.12+; libzim doesn't support 3.15 yet)
  • About 120 MB for the embedding model, plus your ZIM files
  • Wikipedia-style ZIM files (Zimantic relies on their predictable HTML structure to find the first paragraph)
  • Searching does not require Kiwix. To open the articles from the result links, run kiwix-serve with the same ZIMs (set its address as kiwix_url in config.yaml).

Where your files go

By default everything lives inside the project folder, so config.yaml works without changes:

zimantic/
├── config.yaml          ← settings (paths below are its defaults)
├── model/               ← model_dir: model.onnx + sentencepiece.bpe.model   (you download)
├── zims/                ← zim_dir:   your .zim files                          (you download)
├── indexes/             ← index_dir: <name>.sqlite + <name>.faiss            (created by build)
└── zimantic/           ← the program

Your files are somewhere else (a USB drive, another disk)? Point zim_dir, model_dir or index_dir in config.yaml at them instead. These three folders are git-ignored, so ZIMs, models and indexes never get committed.

Install

  1. Get the code and enter the folder
  • run the next commands from here

  • config.yaml is read from this folder, so configure appropriately

    git clone https://github.com/OscSanto/zimantic.git
    cd zimantic
  1. Create a virtual environment and install the dependencies:

    python3 -m venv .venv
    . .venv/bin/activate              # Windows: .venv\Scripts\activate
    pip install -r requirements.txt
  2. Download the model into model/ (keep these exact file names):

    mkdir -p model
    curl -L -o model/model.onnx https://huggingface.co/Xenova/multilingual-e5-small/resolve/main/onnx/model_quantized.onnx
    curl -L -o model/sentencepiece.bpe.model https://huggingface.co/intfloat/multilingual-e5-small/resolve/main/sentencepiece.bpe.model

    (curl is built into Linux, macOS and Windows 10+. On Windows PowerShell, use curl.exe and mkdir model.)

  3. Put your ZIM files in zims/. Download them from library.kiwix.org or download.kiwix.org/zim.

  4. Check config.yaml. If you used the folders above, nothing needs changing. Otherwise point zim_dir / model_dir / index_dir at your folders. To open articles from the results, set kiwix_url to where kiwix-serve runs.

  5. Check that it runs:

    python -m zimantic --help

Use

python -m zimantic build wikipedia_en_medicine_maxi_2026-04   # index ZIMs in zim_dir by name (one or more)
python -m zimantic build --path /some/where/x.zim             # or index one ZIM file by its path
python -m zimantic serve                                      # web page on http://<host>:8090 after build is succesful

The name is the ZIM's file name without .zim (for zims/wikipedia_en_medicine_maxi_2026-04.zim, use wikipedia_en_medicine_maxi_2026-04).

To open articles from the results, run kiwix-serve with the same ZIMs, in a second terminal:

sudo apt install kiwix-tools             # Debian/Ubuntu/Raspberry Pi OS; other systems: kiwix.org/en/applications
kiwix-serve --port 8080 zims/*.zim       # matches the default kiwix_url in config.yaml

If a build stops, run it again and it will automatically pick up where it left off.

To rebuild a ZIM, delete its .sqlite and .faiss from index_dir first. Restart serve after building a new index so it picks it up.

Each ZIM gets two files in index_dir: <name>.sqlite (titles, first paragraphs) and <name>.faiss (vectors). If building index is slow, consider building on a more powerful PC and copying over both files.

JSON API Example: GET /api/search?q=...&zim=<name>&zim=<name2>&limit=20 (no zim = all) and GET /api/zims.

About

Multilingual semantic search for offline libraries (Kiwix ZIM files). Ask in your own words and your own language, and find the right article in Wikipedia, WikiMed and more. Runs fully offline, on low resource devices..

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages