Search and Retrieval
Search
POST /v1/search finds the passages of the tafsir that speak to a query, by keyword, by meaning, or both. Every result is a scholar's passage, or an ayah of the Qur'an, word for word, with its citation and a link to its source.
Overview
- Call
POST https://grep.getbayan.app/v1/search - Bodya JSON object, sent with
Content-Type: application/json, at most 8,192 bytes. Onlyqueryis required. - Sign-innone, and no API key. Callers are limited by IP address (see Rate limits).
- AnswerJSON (
application/json; charset=utf-8), always sent withCache-Control: no-store. - Browsersthe API sends no CORS headers and answers
OPTIONSwith 405, so a web page on another origin cannot call it from the browser. Call it from a server, a script or a native app.
No model writes any part of the answer. A reranker, when the service has one, only orders the passages it is given; as configured it has none. A model (Gemma 4) turns a query with no Arabic letter into Arabic search terms, and those terms are never returned. The passages are the scholars' words, unchanged.
Example
A keyword search for الصبر عند المصيبة in Ibn Kathir's tafsir (book 1503), within Surah 2, for the single best passage:
const res = await fetch("https://grep.getbayan.app/v1/search", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({query: "الصبر عند المصيبة",mode: "keyword",rerank: false,topK: 1,filter: { surah: 2, books: [1503] },}),}); if (!res.ok) {const { error } = await res.json();throw new Error(`${res.status} ${error.code}: ${error.message}`);} const { results, ayahs } = await res.json();for (const passage of results) {console.log(passage.citation.text, passage.source.reader);}
curl https://grep.getbayan.app/v1/search \-H "Content-Type: application/json" \-d '{"query": "الصبر عند المصيبة","mode": "keyword","rerank": false,"topK": 1,"filter": { "surah": 2, "books": [1503] }}'
import requests res = requests.post("https://grep.getbayan.app/v1/search",json={"query": "الصبر عند المصيبة","mode": "keyword","rerank": False,"topK": 1,"filter": {"surah": 2, "books": [1503]},},timeout=30,)if not res.ok:error = res.json()["error"]raise RuntimeError(f"{res.status_code} {error['code']}: {error['message']}") answer = res.json()for passage in answer["results"]:print(passage["citation"]["text"], passage["source"]["reader"])
The answer, formatted (the service sends it on one line):
{"query": "الصبر عند المصيبة","language": "ar","translated": false,"results": [{"id": "1503000494","kind": "passage","book": {"id": 1503,"name": "تفسير ابن كثير - ط ابن الجوزي","edition": "الكتاب: تفسير القرآن العظيم\nالمؤلف: ابن كثير\nالمحقق: حكمت بن بشير بن ياسين\n(اختصر عمل الشيخ أبي إسحاق الحويني من أول الكتاب إلى الآية ١٤١ من سورة البقرة (وهو جـ ١ هذه الطبعة) ثم أكمل تحقيق الكتاب)\nالناشر: دار ابن الجوزي للنشر والتوزيع - السعودية\nالطبعة: الأولى، ١٤٣١ هـ\nعدد الأجزاء: ٧\n[ترقيم الكتاب موافق للمطبوع]"},"author": {"id": 3,"name": "ابن كثير","died": 774},"vol": "1","page": 379,"pageEnd": 381,"heading": ["تفسير سُورَةُ البَقَرَة","ذكر أقوال المفسرين (ببسط) ما ذكرناه:"],"ayahs": {"surah": 2,"from": 45,"to": 45},"text": "﴿وَاسْتَعِينُوا بِالصَّبْرِ وَالصَّلَاةِ وَإِنَّهَا لَكَبِيرَةٌ إِلَّا عَلَى الْخَاشِعِينَ (٤٥) الَّذِينَ يَظُنُّونَ أَنَّهُمْ مُلَاقُو رَبِّهِمْ وَأَنَّهُمْ إِلَيْهِ رَاجِعُونَ (٤٦)﴾.\nيقول تعالى آمرًا عبيده فيما يؤملون من خير الدنيا والآخرة بالاستعانة بالصبر والصلاة؛ كما قال مقاتل بن حيان في تفسير هذه الآية: استعينوا على طلب الآخرة بالصبر على الفرائض والصلاة؛ فأما الصبر فقيل: إنه الصيام، نص عليه مجاهد.\n[قال القرطبي وغيره: ولهذا يسمى رمضان شهر الصبر، كما نطق به الحديث].\nوقال سفيان الثوري، عن أبي إسحاق، عن جري بن كليب، عن رجل من بني سليم، عن النبي ﷺ؛ قال: \"الصوم نصف الصبر\".\nوقيل: المراد بالصبر الكف عن المعاصي؛ ولهذا قرنه بأداء العبادات؛ وأعلاها فعل الصلاة.\nقال ابن أبي حاتم: حدثنا أبي، حدثنا (عبيد الله) بن حمزة بن إسماعيل، حدثنا إسحاق بن سليمان، عن أبي سنان، عن عمر بن الخطاب ﵁؛ قال: الصبر صبران: صبر عند المصيبة حسن؛ وأحسن منه الصبر عن محارم الله.\n(قال): وروي عن الحسن البصري نحو قول عمر.\nوقال ابن المبارك، عن ابن لهيعة، عن (عطاء) بن دينار، عن سعيد بن جبير؛ قال: الصبر اعتراف العبد لله بما أصاب (منه)، واحتسابه عند الله، ورجاء ثوابه، وقد يجزع الرجل وهو يتجلد لا يرى منه إلا الصبر.\nوقال أبو العالية، في قوله (تعالى): ﴿وَاسْتَعِينُوا بِالصَّبْرِ وَالصَّلَاةِ﴾ قال: على مرضاة الله، وعلموا أنها من طاعة الله.","notes": null,"quotes": [{"surah": 2,"from": 45,"to": 46}],"citation": {"text": "ابن كثير (ت ٧٧٤هـ)، تفسير القرآن العظيم، ١/ ٣٧٩-٣٨١","author": "ابن كثير","died": 774,"diedLabel": null,"book": "تفسير القرآن العظيم","edition": "المحقق: حكمت بن بشير بن ياسين؛ الناشر: دار ابن الجوزي للنشر والتوزيع - السعودية؛ الطبعة: الأولى، ١٤٣١ هـ","vol": "1","page": 379,"pageEnd": 381,"printed": true},"source": {"reader": "https://app.turath.io/book/1503?page=434","pdf": {"url": "https://files.turath.io/pdf/ibnkatheer_jawzee/01_113015.pdf","page": 379},"provider": "turath.io","attribution": null},"score": 0.01639344262295082}],"ayahs": [{"surah": 2,"from": 45,"to": 46,"passages": 1}]}
Leave out mode and rerank to get the default: hybrid search, reranked when the service has a reranker. As configured it has none, so rerank changes nothing for now.
Request body
| Field | Type | Default | Rules |
|---|---|---|---|
query | string | required | 1 to 300 characters once spaces and line breaks at both ends are trimmed. Characters are counted as Unicode code points, so harakat count. Text with an unpaired surrogate is refused. |
mode | "hybrid", "semantic" or "keyword" | "hybrid" | Which searches run. See Search modes. |
topK | integer | 10 | 1 to 100. How many results to answer when they are not reranked. |
rerank | boolean | true | Whether the service's reranker orders the results. |
rerankLimit | integer | topK | 1 to 100, and not more than topK. How many results to answer when the reranker is called. |
minScore | number or null | none | 0 to 1. A floor on one score at a time. See minScore. |
filter | object or null | none | Limits which passages are searched. See filter. |
translate | boolean | true | Whether a query with no Arabic letter may be turned into Arabic keyword queries. See translate. |
- An unknown field is refused, and the message lists the allowed ones. A typo such as
topkis an error, never ignored. Fields from other search APIs, such asrerankModelorincludeMetadata, are refused the same way. nullin an optional field means the field is absent.- Integers must be JSON numbers with no fraction:
1.5and"10"are refused. - A request with several mistakes is refused for the first, checked in this order: unknown fields,
query,topK,rerank, the range ofrerankLimit,filter,minScore,mode,translate, and lastrerankLimitagainsttopK.
A body with every field, each at its default but filter:
const body = {query: "الصبر عند المصيبة",mode: "hybrid",topK: 10,rerank: true,rerankLimit: 10,minScore: null,filter: { surah: 2 },translate: true,};
filter
| Field | Type | Rules |
|---|---|---|
books | integer[] | Book ids, at most 20 different ones, each 1 or more. A repeated id counts once. An empty list filters nothing. |
authors | integer[] | Author ids, by the same rules. |
categories | integer[] | Category ids, by the same rules. Tafsir is category 3. |
surah | integer | 1 to 114. Only passages that the book's own structure places in this surah, whether or not they are mapped to one of its ayahs. |
ayah | integer | 1 to 286. Needs surah, and must be an ayah of that surah. Only passages whose ayah range includes it. |
quran | "include", "exclude" or "only" | "include" (the default): the Qur'an's own ayahs are searched beside the books. "exclude": they are left out. "only": they are searched alone. |
- The fields are combined with AND. A list matches any of its ids.
- The ids are turath.io's, the same ones the answers carry in
book.idandauthor.id.GET /v1/bookslists the books with their ids and categories. Filtering has examples. - A
surahfilter leaves out every passage the book does not place in a surah, and anayahfilter every passage not mapped to an ayah. Some books have no ayah structure at all, so anayahfilter leaves out the whole book. - The Qur'an is book 0, in category 0, with no author. The lists take ids from 1, so any list already leaves the Qur'an out, and
"only"besidebooks,authorsorcategoriesis refused.
minScore
minScore is held to one score between 0 and 1, which depends on how the results were ordered. A result exactly at the floor is kept.
| When | Compared with |
|---|---|
| Reranked, in any mode | rerankScore. |
semantic mode, not reranked | The vector match score, normalised to 0–1 as (1 + cosine similarity) / 2. This score is not in the answer. |
hybrid or keyword mode, not reranked | Nothing: minScore is not applied, because a fused or bm25 score is not between 0 and 1. |
"Not reranked" covers rerank: false, a service with no reranker configured, and a rerank that failed.
translate
The keyword index holds the scholars' Arabic, so a query with no Arabic letter cannot match it as typed. When the service names a language model for it (its TRANSLATE_MODEL setting, which is gemma-4, @cf/google/gemma-4-26b-a4b-it, as configured; agentic search has a switch of its own), it asks that model once for up to 3 Arabic keyword queries, worded as a classical tafsir would word them, and searches each in the keyword index while meaning search runs. Together, those lists weigh as much as the one keyword list of an Arabic query. The terms are never returned and never logged. translated in the answer says whether they were searched.
translate: falseturns this off for one request.- It never runs in
semanticmode, or for a query that has an Arabic letter. - The model is given 4 seconds. If it fails, times out, answers in the wrong shape or writes no query with an Arabic letter, a hybrid search goes on by meaning alone. In
keywordmode nothing is then left to search, and the answer is 503search_unavailable. - The terms for a query are kept for a day, so a repeated query does not call the model again in the same data centre.
Search modes
| Mode | What runs |
|---|---|
hybrid (default) | Keyword search and meaning search at the same time, merged by reciprocal rank fusion. |
semantic | Meaning search only. |
keyword | Keyword search only. The query is not embedded. |
Queries with no Arabic letter
Keyword search is skipped for a query with no Arabic letter, such as an English query or Arabic spelled in Latin letters (sabr), unless the query is translated (see translate). Tatweel, Arabic-Indic digits and Arabic punctuation on their own do not count as Arabic letters.
hybrid: the search runs by meaning alone.semantic: nothing changes.keyword: nothing can match. The answer is 200 with no results.
language in the answer is "ar" when the query has an Arabic letter and "other" when it has none.
Keyword search
Keyword search runs on SQLite FTS5 in Cloudflare D1, over a search form of each passage. The display text is never changed.
- The query and the passages are compared without harakat or Qur'anic marks. أ إ آ ٱ are read as ا, ى and ئ as ي, ؤ as و, ة as ه, and Arabic-Indic digits as 0–9. A query typed without harakat finds text printed with them.
- Each word matches as written or by its light stem (Larkey's light10 rules, except that the name of Allah is kept whole). An exact match weighs twice as much as a stem match in the bm25 ranking.
- 181 stopwords, common words such as من, في and عند, are dropped from the word tiers, unless the query has no other words.
- At most 12 words of the query are used.
Passages are found in three tiers, best first. Each passage appears once.
- Phrase: the query's first 12 words in a row, stopwords included, matched as written (not by stem). Only for a query of two or more words.
- Every word: passages that have every word of the query but the stopwords.
- Any word: only when the first two tiers find fewer than 10 passages. It looks for any of those words, at most the 3 rarest.
For الصبر عند المصيبة, the phrase tier looks for the three words in a row. The every-word tier looks for الصبر and المصيبة, as written or by their stems صبر and مصيب, because عند is a stopword.
Meaning search
The query, with harakat stripped and its letters left as written, is embedded by the service's embedding model and compared with the passages' vectors in Cloudflare Vectorize. As configured, the model is embeddinggemma-2 (@cf/google/embeddinggemma-2 on Workers AI), at 256 dimensions. A query's embedding is kept for a day. Meaning search can match across languages only as well as the model does.
How results are ranked
- Each search is asked for at least 50 passages, or
topKwhen it is larger, up to 100. - The lists are merged by reciprocal rank fusion with k = 60: a passage scores 1 / (60 + rank) in each list it is in, and the scores add up. Both searches weigh the same. Ties keep the order in which passages are first met, reading meaning search's list first. The best 30 are kept, or
topKwhen it is larger, up to 100. - The passages are read from the database in one query.
- When
rerankis true and the service has a reranker, the reranker reads the best 30 with the query (orrerankLimit, when it is larger), and the answer is its bestrerankLimit. Otherwise the answer is the firsttopK. minScoreis applied last.
As configured, there is no reranker (RERANKER is "none"): in the service's model test, bge-reranker-base lowered the quality of results. The service can be set to use bge-reranker-base (@cf/baai/bge-reranker-base on Workers AI) or Cohere's rerank-v5.0-fast. Each passage is given to a reranker without harakat and cut to 1,500 characters.
Every step has a time limit: 4 seconds for keyword search, 6 for meaning search, 3 for the reranker. See When part of a search fails, and Ranking for more on each step.
Very short passages of the books (under 40 characters, harakat not counted, or under 12 when the passage is mapped to an ayah) are kept for reading but are in neither index, so search does not return them. Every ayah of the Qur'an is indexed, the shortest too.
Response
Status 200, with a JSON object:
| Field | Type | Description |
|---|---|---|
query | string | The query as searched, trimmed. |
language | "ar" or "other" | "ar" when the query has an Arabic letter, "other" when it has none. |
translated | boolean | true when Arabic keyword queries a model wrote for the query were searched too. Those queries are never returned. |
results | Passage[] | The passages, best first. Empty when nothing matched. |
ayahs | AyahSummary[] | The ayahs the results point at, at most 10. See ayahs. |
Passage
| Field | Type | Description |
|---|---|---|
id | string | The passage id: the book id × 1,000,000 + the passage's position in the book, counted from 0. "1503000494" is book 1503's passage at position 494. An ayah's id is its place in the Qur'an, counted from 0: 2:156 is "162". |
kind | "passage" or "ayah" | "passage": a scholar's words from a book on turath.io. "ayah": an ayah of the Qur'an itself. |
book | object | id, name (turath's name for the book) and edition (turath's edition line, its lines separated by \n; for the Qur'an, Tanzil's title and credit; null when there is none). |
author | object or null | id, name, died (the Hijri year of death, or null when it is not known), and diedLabel, present only when turath marks the year as not exact: نحو (about), بعد (after) or ق (sometime in that century, and died is then the century's middle year). null for the Qur'an. |
vol | string or null | The volume, as the book labels it. |
page | integer or null | The first page. The page numbers are the printed edition's when citation.printed is true. |
pageEnd | integer or null | The last page. |
heading | string[] | The headings the passage sits under, outermost first, each as the page prints it, or as the table of contents words it where the heading has no line of its own. |
ayahs | AyahRange or null | The ayahs the passage explains, taken from the book's own structure: { surah, from, to }, both ends included. For an ayah, the ayah itself. null when the passage is not mapped to an ayah. |
text | string | The passage, cleaned of markup, its words unchanged. Paragraphs are separated by \n. Qur'an quotes are in ﴿…﴾. |
notes | string or null | The editor's footnotes. null unless the service is set to serve footnotes, which it is not as configured. |
quotes | AyahRange[] | The ayahs the passage's ﴿…﴾ quotes were matched to, in the Qur'an's order. Empty for an ayah. |
citation | Citation | Where the passage is in its book. See citation. |
source | PassageSource | Where to read it at its source. See source. |
score | number | The fused rank score. On every search result. |
rerankScore | number | 0 to 1, from the reranker. Only when the rerank succeeded. |
citation
| Field | Type | Description |
|---|---|---|
text | string | The reference in Arabic, with Arabic-Indic digits, built from turath's own records: author, year of death, title, volume and pages. In the example: ابن كثير (ت ٧٧٤هـ)، تفسير القرآن العظيم، ١/ ٣٧٩-٣٨١. A book of one volume is cited by ص and the page. When the page numbers are not known to be the printed edition's, the page is followed by (ترقيم النسخة الإلكترونية). An ayah is cited by surah and ayah: القرآن الكريم، سورة البقرة، الآية ١٥٦. |
author | string or null | turath's name for the author. null for the Qur'an. |
died | integer or null | The Hijri year of death. |
diedLabel | string or null | As author.diedLabel. null when the year is exact or not known. |
book | string | The title as the edition line gives it (its الكتاب: line), else turath's name for the book. |
edition | string or null | The editor, publisher and printing, worded as the edition line words them and joined with ؛. For the Qur'an, Tanzil's text and version. null when the line names none. |
vol, page, pageEnd | As on the passage. | |
printed | boolean or null | true: the page numbers are the printed edition's. false: turath numbers the book another way. null: turath does not say, and for the Qur'an. |
source
| Field | Type | Description |
|---|---|---|
reader | string or null | turath's reader, opened at the passage's first page as turath counts its pages, which is not the printed number (the example's printed page 379 is turath's page 434). For an ayah, Quran.com at the ayah. null for a passage with no position. |
pdf | object or null | turath's scan of the printed book: url, and page, the printed page to open it at, or null when the page numbers are not the printed edition's (the file then opens at its start). null when there is no scan to link to. |
provider | "turath.io" or "Tanzil Project" | Where the text comes from. |
attribution | string or null | For an ayah: Tanzil's credit, link and license. null for a scholar's passage. |
Scores
scoreis the reciprocal rank fusion score: the sum, over the lists that found the passage, of 1 / (60 + rank) times the list's weight. Each search weighs 1, and a translated query's keyword lists share one weight. With one list, the first result scores 1/61, which is the0.01639344262295082of the example. Compare scores within one answer only.rerankScoreis between 0 and 1. Cloudflare's page for bge-reranker-base says its score can be mapped to 0–1 by a sigmoid, but not whether the scores Workers AI answers already are, so when any score in an answer falls outside 0 to 1, every score in it goes through a sigmoid, which keeps their order. Cohere's scores are used as they come.- Neither scale has been checked on the live services yet: the reranker's, or that of Vectorize's cosine score, which the semantic-mode floor uses. Choose a
minScoreafter looking at real answers.
ayahs
Each AyahSummary is { surah, from, to, passages }: a range of ayahs the results point at, and how many results point into it.
- A result points at its own ayahs (the ayahs a tafsir passage explains, or the ayah itself) and at the ayahs it quotes.
- Ranges of one surah that overlap are merged into one.
- The ranges are ordered by the best-ranked result that points at each, its own ayahs before its quotes. There are at most 10.
In the example the passage explains 2:45 and quotes 2:45–46, so the summary is one range, 2:45–46, with one passage. Use the summary to show the ayahs themselves beside the scholars' passages.
Ayahs of the Qur'an in results
By default the Qur'an is searched with the books (filter.quran is "include"). An ayah comes back as a Passage with kind "ayah": book 0, no author, no volume or page, the surah as its heading, and its text is Tanzil's Uthmani text, word for word. In keyword mode, the example's query with filter: { quran: "only" } finds 2:156 first. Every field but text and score:
{"id": "162","kind": "ayah","book": {"id": 0,"name": "القرآن الكريم","edition": "Tanzil Quran Text (Uthmani, Version 1.1) — Tanzil Project, https://tanzil.net"},"author": null,"vol": null,"page": null,"pageEnd": null,"heading": ["سورة البقرة"],"ayahs": {"surah": 2,"from": 156,"to": 156},"notes": null,"quotes": [],"citation": {"text": "القرآن الكريم، سورة البقرة، الآية ١٥٦","author": null,"died": null,"diedLabel": null,"book": "القرآن الكريم","edition": "Tanzil Quran Text (Uthmani, Version 1.1) — Tanzil Project, https://tanzil.net","vol": null,"page": null,"pageEnd": null,"printed": null},"source": {"reader": "https://quran.com/2/156","pdf": null,"provider": "Tanzil Project","attribution": "Tanzil Quran Text (Uthmani, Version 1.1), Tanzil Project (https://tanzil.net). License: Creative Commons Attribution 3.0. Reproduced verbatim."}}
Tanzil's terms ask that every use of its text name Tanzil Project and link to tanzil.net. Show source.attribution with the ayah. Tanzil's whole copyright block, which its terms ask to go with verbatim copies, is the notice of GET /v1/books/0.
Types
The response, as the service types it:
interface LibrarySearchResponse {query: string;language: "ar" | "other";translated: boolean;results: Passage[];ayahs: AyahSummary[];} interface Passage {id: string;kind: "passage" | "ayah";book: { id: number; name: string; edition: string | null };author: AuthorRef | null;vol: string | null;page: number | null;pageEnd: number | null;heading: string[];ayahs: AyahRange | null;text: string;notes: string | null;quotes: AyahRange[];citation: Citation;source: PassageSource;score?: number;rerankScore?: number;} interface AuthorRef {id: number;name: string;died: number | null;diedLabel?: string;} interface AyahRange {surah: number;from: number;to: number;} interface AyahSummary extends AyahRange {passages: number;} interface Citation {text: string;author: string | null;died: number | null;diedLabel: string | null;book: string;edition: string | null;vol: string | null;page: number | null;pageEnd: number | null;printed: boolean | null;} interface PassageSource {reader: string | null;pdf: { url: string; page: number | null } | null;provider: "turath.io" | "Tanzil Project";attribution: string | null;}
Caching
The service keeps answers. The client should not.
- A complete answer is kept for one hour in Cloudflare's Cache API, in the data centre that answered it. The same request to that data centre within the hour gets the kept answer, and no search runs.
- "The same request" means the same request after validation: every default filled in, the query trimmed, each filter list's ids once each and smallest first, and empty lists dropped. A body that leaves the defaults out and one that spells them out share one kept answer.
- The key also holds the library's version, which changes whenever books are loaded, the service's embedder, reranker and footnote setting, and, for a translated query, the model that translates it and its prompt. A kept answer never outlives a change to any of them.
- The key is a SHA-256 hash. The query's words are not in it.
- An answer that a failure made worse is not kept (see When part of a search fails).
- The answer is sent with
Cache-Control: no-store. The service can tell when the library changes; an app cannot, so it should not keep answers of its own. - A kept answer still counts against the rate limit.
The service also keeps a query's embedding for a day, and the Arabic terms of a translated query for a day.
Rate limits
- 60 searches per 60 seconds per caller.
- The caller is the IP address Cloudflare reports. An IPv6 address counts as its /64, its first four groups (for example
2001:db8:a:b::/64), because a host is normally given a whole /64 and could send each request from a new address. An IPv4 address counts on its own. - A request is counted before its body is read, so malformed requests count, and so do requests answered from a kept answer.
- Agentic search (
POST /v1/search/guided, off as configured) counts as 5 searches against the same limit. - Over the limit, the answer is 429
rate_limitedwithRetry-After: 60. - Cloudflare's rate limiting keeps its counts per location.
The GET calls of the API have their own limit, 300 per 60 seconds, and only the requests the edge cache does not answer are counted.
Errors
Every error the service sends is JSON in one envelope, sent with Cache-Control: no-store:
{"error": {"code": "invalid_request","message": "rerankLimit cannot be larger than topK"}}
Branch on code. The message says what to fix.
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request | The body or one of its fields is wrong, and the message names it. Sending the same request again gives the same answer. |
| 404 | not_found | There is nothing at this path. Check the URL. |
| 405 | method_not_allowed | A method other than POST, OPTIONS included. The answer carries Allow: POST. |
| 413 | payload_too_large | The body is over 8,192 bytes. |
| 415 | unsupported_media_type | The Content-Type is not application/json. Parameters such as charset are allowed. |
| 429 | rate_limited | Too many requests from this caller. Wait the number of seconds in Retry-After, then try again. |
| 500 | internal | Something failed inside the service, such as a database error or a mistake in its configuration. The message says only "Something went wrong. Try again later." |
| 503 | search_unavailable | Every search that was tried failed or timed out, or a keyword-mode search had nothing left to search after its translation (see translate). Try again shortly. Nothing is kept, so the next request searches again. |
Validation messages
Every 400 message, word for word:
| Message | Cause |
|---|---|
A JSON body is required. | No body. |
The body is not valid JSON. | The body does not parse, or is not UTF-8. |
The body must be a JSON object. | An array, a string or another value. |
Unknown field topk. Allowed: query, mode, topK, rerank, rerankLimit, minScore, filter, translate. | A field the API does not take (here topk). |
query must be text of 1 to 300 characters. | Missing, not a string, empty after trimming, too long, or holding an unpaired surrogate. |
topK must be a whole number from 1 to 100. | Out of range, a fraction, or not a number. |
rerank must be true or false. | Not a boolean. |
rerankLimit must be a whole number from 1 to 100. | Out of range, a fraction, or not a number. |
filter must be an object. | An array, a string or another value. |
Unknown field filter.book. Allowed: filter.books, filter.authors, filter.categories, filter.surah, filter.ayah, filter.quran. | A filter field the API does not take (here book). |
filter.books must be a list of at most 20 ids (whole numbers above 0). | Not a list, an id below 1 or not an integer, or more than 20 different ids. The same for filter.authors and filter.categories. |
filter.surah must be a whole number from 1 to 114. | Out of range or not an integer. |
filter.ayah must be a whole number from 1 to 286. | Out of range or not an integer. |
filter.ayah needs filter.surah. | An ayah with no surah. |
Surah 1 has no ayah 8. | An ayah past the end of its surah (here 1:8). |
filter.quran must be one of include, exclude, only. | Any other value. |
filter.quran "only" cannot be combined with filter.books, filter.authors or filter.categories: the Qur'an is in none of them. | "only" beside a list. |
minScore must be a number from 0 to 1. | Out of range or not a number. |
mode must be one of hybrid, semantic, keyword. | Any other value. |
translate must be true or false. | Not a boolean. |
rerankLimit cannot be larger than topK | A rerankLimit above topK, or above 10 when topK is left out. |
When part of a search fails
A search carries on with what still works, and answers 503 only when nothing does.
- When one of the two searches fails or runs out of time and the other answers, the answer is 200 with what the other found.
- When the reranker fails or runs out of time, the results come in the merged order, cut to
rerankLimit, with norerankScore. - When a translation fails, a hybrid search goes on by meaning alone.
Such an answer is not kept, so the next identical request searches again. The answer does not say that part of it failed. After a failed rerank, the missing rerankScore shows it.