The search command finds articles in ZIM archive files using either full-text keyword search or semantic vector similarity search. It supports searching within a specific ZIM file or across all indexed library files.
The search command provides two powerful search modes:
- Full-Text Search (default) - Uses SQLite FTS5 for keyword matching with ranked results
- Semantic Search (
--semantic) - Uses Model2Vec embeddings to find conceptually similar articles
zim search <file.zim or name> <query>zim search <query>| Flag | Short | Description |
|---|---|---|
--semantic |
-s |
Use vector similarity search instead of full-text |
--json |
Output results in JSON format | |
--non-interactive |
Disable interactive selection mode |
Full-text search uses SQLite FTS5 for fast, ranked keyword matching:
- Searches both article titles and content excerpts
- Uses AND logic for multi-word queries (
machine learningmatches articles with both terms) - Ranks results by relevance (title matches weighted higher than content matches)
- Automatically handles special characters (hyphens, apostrophes become spaces)
- Falls back to bounded native title similarity and prefix lookup only when the selected archive has no SQLite index
zim search wikipedia_en "machine learning"Output:
Searching (full-text): machine learning
======================
Searching SQLite index... found 47 results
Found 47 results:
1. Machine learning
2. Deep learning
3. Supervised learning
4. Unsupervised learning
5. Reinforcement learning
...
Enter number to read (1-20), 'm' for more, or 'q' to quit:
Semantic search uses vector embeddings to find conceptually similar articles:
- Generates 512-dimensional embeddings using Model2Vec
- Compares article vectors using cosine distance
- Finds related concepts even without exact keyword matches
- Requires a semantic index created with
zim index
zim search --semantic wikipedia_en "artificial intelligence"Output:
Searching (semantic): artificial intelligence
==========================
Searching with semantic similarity... found 42 results
Found 42 results:
1. Artificial intelligence
2. Machine learning
3. Neural network
4. Deep learning
5. Cognitive science
...
Enter number to read (1-20), 'm' for more, or 'q' to quit:
| Use Full-Text When... | Use Semantic When... |
|---|---|
| Searching for specific keywords | Exploring related concepts |
| You know the exact terms | Keywords don't return good results |
| Need fast, precise results | Want broader, conceptual matches |
| Title/phrase matching | Discovering connected topics |
The search query is automatically processed to improve matching:
- Hyphens and apostrophes become spaces (
Spider-Man→Spider Man) - Special characters are removed (
C++→C) - Multiple words use AND logic (
quantum physicsrequires both terms) - Case-insensitive matching
Search automatically filters out non-article resources:
- Images (
.svg,.png,.jpg,.gif,.webp,.ico) - Stylesheets and scripts (
.css,.js) - Fonts (
.woff,.woff2,.ttf) - Media files (
.mp3,.mp4,.ogg,.webm) - Data files (
.json,.xml)
In interactive mode (default), you can:
- Enter a number (1-20) to read that article
- Type 'm' to show more results (next 20)
- Type 'q' or press Enter to quit
Non-interactive mode disables prompts and displays only results:
zim search --non-interactive wikipedia "python"For automation and scripting, use --json:
zim search --json wikipedia "climate change"Output:
{
"query": "climate change",
"results": [
{
"Title": "Climate change",
"URL": "Climate_change"
},
{
"Title": "Global warming",
"URL": "Global_warming"
}
],
"count": 2
}zim search wikipedia_en "photosynthesis"Searching (full-text): photosynthesis
=========================
Searching SQLite index... found 12 results
Found 12 results:
1. Photosynthesis
2. Carbon fixation
3. Chlorophyll
4. Calvin cycle
5. Photosystem
...
zim search -s wikipedia_en "how plants make food"Searching (semantic): how plants make food
===========================================
Searching with semantic similarity... found 18 results
Found 18 results:
1. Photosynthesis
2. Plant nutrition
3. Chloroplast
4. Carbon fixation
5. Autotroph
...
zim search wikipedia "quantum mechanics"Searches for articles containing both "quantum" AND "mechanics":
Searching (full-text): quantum mechanics
===============================
Searching SQLite index... found 34 results
Found 34 results:
1. Quantum mechanics
2. Introduction to quantum mechanics
3. History of quantum mechanics
4. Quantum field theory
5. Mathematical formulation of quantum mechanics
...
zim search "Dionysus"Searches across all indexed ZIM files:
Searching ALL library files for: Dionysus
=======================================
Found 15 results across 2 files:
wikipedia_en_all_maxi_2024:
[1] Dionysus
[2] Dionysian
[3] Maenads
wikipedia_mythology:
[4] Dionysus
[5] Bacchus
[6] Thyrsus
...
zim search --json wikipedia "algorithm"{
"query": "algorithm",
"results": [
{"Title": "Algorithm", "URL": "Algorithm"},
{"Title": "Algorithmic efficiency", "URL": "Algorithmic_efficiency"},
{"Title": "Sorting algorithm", "URL": "Sorting_algorithm"}
],
"count": 3
}zim search --non-interactive wikipedia "rust"Searching (full-text): rust
==================
Searching SQLite index... found 8 results
Found 8 results:
1. Rust
2. Rust (programming language)
3. Iron oxide
4. Corrosion
5. Rusting
...
Showing first 20 results. Use interactive mode to select and read articles.
Search behavior can be configured via ~/.zim.yaml:
search:
max_results: 50 # Maximum results to return
non_interactive: false # Disable interactive mode
json_output: false # Output in JSON formatEnvironment variables:
export ZIM_SEARCH_MAX_RESULTS=100
export ZIM_SEARCH_NON_INTERACTIVE=true
export ZIM_SEARCH_JSON_OUTPUT=trueSearch requires a local SQLite index:
zim index <file>Before searching, create an index:
# Full-text search index
zim index wikipedia_en
# Full-text only, if you want to skip embeddings
zim index --no-semantic wikipedia_enIndexing status:
zim info wikipedia_enLook for Search Index: in the output.
All-library search is indexed-only. SQLite corruption, permission, and query failures are returned directly rather than being hidden by a native scan.
Error: database not initialized
Solution: Create the local index with zim index <file> or check index.path.
No index found for this ZIM file.
Run 'zim index <file>' to create a search index.
Solution: Create a search index with zim index <file>
SQLite search failed: no index for ZIM file
Solution: Check index.path, filesystem permissions, and whether the index exists
❌ No results found for 'query'
Solution: Try different search terms, use semantic search, or verify the index exists
-
No results found
- Check if index exists:
zim info <file> - Try semantic search:
zim search --semantic <file> <query> - Use broader search terms
- Check if index exists:
-
Too many resource files
- Search automatically filters non-articles
- If issue persists, check your query has meaningful keywords
-
Slow search performance
- Put the SQLite index on fast local storage
- Check that exact vector ranking exists for vector search
- Reduce
max_resultsin config
- Full-text: ~1000 articles/sec
- Semantic: ~345 articles/sec (includes embedding generation)
- Parallel indexing: Uses all CPU cores by default
- Full-text: Typically <100ms for 50 results
- Semantic: Typically <200ms for 50 results (with exact vector ranking)
- Database size: ~0.8x of ZIM file size
Full-text indexes add minimal overhead. Semantic indexes with embeddings add significant storage due to 512-dimensional vectors per article.
zim index- Create search indexeszim read- Read a specific articlezim list- List all articles in a ZIM filezim serve- Start web server for browsingzim info- Display ZIM file and index information