Skip to main content

fihris

Fihris (فهرس, "index") is a retrieval engine for Arabic and English documents. It ingests files, keeps their page text, chunks and vectors, and answers a question with numbered, access-filtered sources that fit a context budget. It stops at retrieval: generating the answer is the caller's job.

  • Ingestion: every format textkeel reads, with Arabic PDFs rebuilt from their fonts by pdf-ar. Pages the quality gate rejects fall back to OCR when OCR passes its own check, and otherwise wait in a review queue.
  • Chunks: structure-aware, never crossing a page, each under a Document: and Section: header. Repeated page furniture is kept once.
  • Search across languages: the question is translated into the other language (opus-mt), and BM25 and dense search run on both, so an English question finds Arabic-only evidence and the reverse.
  • Ranking: reciprocal rank fusion of the four lists, then a cross-encoder reranker on the top 30, each chunk scored against the question in its own language.
  • Access: every document carries groups. A principal sees only documents sharing a group, at every step: keyword, dense, reranking and the library. A document outside a principal's groups is reported as missing.
  • Builds: each index build is its own vector collection behind a live alias. Single-document changes update the live build; a corpus re-index builds a new collection, reusing unchanged vectors, and switches only when complete.

The pipeline

  1. Translate the question into the other language (opus-mt, local).
  2. BM25 on the question and on its translation, top 100 each, over the allowed chunks.
  3. Dense search with Qwen3-Embedding 4B (with its query instruction) on both, top 100 each, filtered in the vector store.
  4. Reciprocal rank fusion of the four lists (k 60, depth 100).
  5. bge-reranker-v2-m3 on the top 30.
  6. The chunks that fit whole in 8,000 characters, numbered from 1.

These settings are pinned in config.py (Pinned) and fingerprinted, and every build records the fingerprint of the configuration that made it.

What it needs

Part Default Setting
Embedding server (OpenAI-compatible /v1/embeddings, such as vLLM serving Qwen/Qwen3-Embedding-4B) http://127.0.0.1:8100 FIHRIS_EMBED_URL
Reranker server (vLLM /classify serving BAAI/bge-reranker-v2-m3) http://127.0.0.1:8101 FIHRIS_RERANK_URL
Qdrant 127.0.0.1:6333 (gRPC 6334) FIHRIS_QDRANT_HOST, FIHRIS_QDRANT_PORT, FIHRIS_QDRANT_GRPC_PORT
Database (SQLAlchemy URL; SQLite or PostgreSQL) sqlite:///artifacts/fihris/fihris.db FIHRIS_DATABASE_URL
Translator models (Helsinki-NLP/opus-mt-en-ar, opus-mt-ar-en) in the Hugging Face cache GPU when available FIHRIS_TRANSLATOR_DEVICE
Fonts folder for Arabic PDFs (see pdf-ar) fonts FIHRIS_FONTS_DIR
Documents folder for import-pages documents FIHRIS_CORPUS_ROOT
Work folder for uploads and temporary files artifacts/fihris FIHRIS_WORK_DIR

Model files are read from the local Hugging Face cache only (local_files_only), so the engine runs offline once they are downloaded.

Install

Python 3.11 or later:

pip install "fihris[translate]"                  # with SQLite
pip install "fihris[postgres,translate,ocr]"     # PostgreSQL and the OCR fallback too

Or from a clone of the repository: pip install -e ".[translate,ocr,dev]".

Search translates every question, so it needs the translate extra (torch). Without it, ingestion, the library and builds still work. Install the torch build that matches your hardware first if you want CUDA.

Use

fihris init-db
fihris ingest documents/ --visible-to-all          # files or folders, one job per file
fihris search "How many days of annual leave do staff get?" --text
fihris status
fihris builds
fihris access --doc doc_0123456789abcdef --groups hr
fihris reindex                                    # re-chunk everything into a new build

fihris import-pages --catalogue docs.jsonl --pages pages.jsonl --activate loads documents extracted elsewhere: a catalogue with one document per line (any Document column, and at least relative_path or doc_id) and a page index (doc_id, page, status, text and optional md per line).

Output is content-free (counts, ids, scores) unless --text is asked for.

From Python:

from fihris.config import Endpoints
from fihris.db import create_schema, engine_for, sessions
from fihris.engine import Engine
from fihris.principal import Principal

endpoints = Endpoints.from_env()
db = engine_for(endpoints.database_url)
create_schema(db)
engine = Engine(endpoints, sessions(db))
engine.load()
result = engine.retrieve("كم مدة الإجازة السنوية؟", Principal.for_groups(["hr"], pilot_mode=False))
for source in result.sources:
    print(source.n, source.doc_id, source.page, source.score)

Engine.upsert_documents adds documents from any catalogue, and Engine.submit("ingest", ...) runs a file through extraction, chunking, embedding and indexing as a job with step-by-step progress.

Access model

  • Every document visible to everyone carries the group all, and every principal holds it.
  • Principal.for_groups(groups, pilot_mode): in pilot mode a principal is narrowed to all alone.
  • Principal.unrestricted() exists for the command line and offline checks; nothing a caller sends can produce it.
  • Superseded, duplicate and removed documents are never returned by search.

Tests

pip install -e ".[dev]"
pytest

Model servers are replaced by deterministic fakes, and the vector store by MemoryIndex, the same contract in NumPy.

License

AGPL-3.0. Fihris requires textkeel, pdf-ar and PyMuPDF, which are AGPL-3.0 (PyMuPDF also sells a commercial license).

Metadata

Release files for fihris 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fihris 0.1
File Size Uploaded Provenance Actions
fihris-0.1.tar.gz 56.9 kB Without provenance Details for fihris-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fihris 0.1
File Interpreter ABI Platform Actions
fihris-0.1-py3-none-any.whl Python 3 none any Details for fihris-0.1-py3-none-any.whl

Total release size: 112.3 kB

Release files / fihris-0.1.tar.gz

Download URL fihris-0.1.tar.gz
Size 56.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c4aa1f34e44e77ce773404942d535f561dc5027a8ec1dd2847de332091094e78
BLAKE2b-256 checksum
How to use checksums
00faab09158bc33b5c6605167eda3ec46e111982b0e2a402e3278d85c7378735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / fihris-0.1-py3-none-any.whl

Download URL fihris-0.1-py3-none-any.whl
Size 55.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78b6129a2ae6ce12bb755baed57d8b21de35fd9dcb98d187d76f378b26d1c1f0
BLAKE2b-256 checksum
How to use checksums
02d9211f5b02aa65a16cb75b7f3f9f5cab6b2eda6c8b4869ba2b7403fb39c0d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for fihris 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page