BETA

alRetrieval

Ingest documents and query them with natural-language semantic retrieval. Supports PDF, DOCX, PPTX, TXT, and Markdown files.

Path
/v1/alRetrieval
Key scope
alretrieval

Supported file formats

PDF, DOCX, PPTX, TXT, MD

PDFs are processed via OCR; DOCX, PPTX, TXT, and MD have text extracted directly — no OCR cost

Scope Required: All alRetrieval endpoints require an API key with the alretrieval scope. Pass it as a Bearer token in the Authorization header.

POSTRetrieve passages

Returns the passages most relevant to a query, without generating an answer. Use it to build your own prompt or show search results. Costs 1 request.

POST /v1/alRetrieval/collections/{collection_id}/retrieve

Parameters:

ParameterTypeDescription
querystringrequired — 1 to 4,000 characters, Arabic or English.
document_idsstring[]optional — search only these documents; omit to search every ready document.
top_kintegeroptional — 1 to 20, default 10.

Response (200 OK):

{
  "pipeline": "deep_tree",
  "document_ids": ["3146366e04ff"],
  "results": [
    {
      "document_id": "3146366e04ff",
      "document_title": "Leave policy",
      "text": "Document: Leave policy\nContext path: Chapter 2 / Article 5\n...",
      "score": 0.5773,
      "page_start": 4,
      "page_end": 5,
      "pages": [4, 5],
      "section": "Chapter 2: Leave / Article 5",
      "section_paths": ["Chapter 2: Leave / Article 5"],
      "is_direct_hit": true
    }
  ]
}

section is the heading path for citations (null for page results). pages lists the pages whose text is in text; page_start/page_end are its first and last, and a deep_tree result can skip pages in between. Compare score only within one response.

409 no_ready_documents No document in scope is ready yet.
409 document_not_ready A document in document_ids is not ready.
504 retrieval_timeout Retry, or narrow document_ids.

Code Examples:

retrieval_retrieve.py
import requests

headers = {"Authorization": "Bearer YOUR_API_KEY"}
r = requests.post("https://alapi.deep.sa/v1/alRetrieval/collections/COLLECTION_ID/retrieve",
                  json={"query": "كم مدة الإجازة السنوية؟", "top_k": 5}, headers=headers).json()
for p in r["results"]:
    print(p["document_title"], p["section"] or f"page {p['page_start']}", p["score"])

Ready to Get Started?

Generate an API key from your dashboard and start building

Activate account?

Activate this account?