Search pages

Find the pages that answer your questions, each with its relevance, in one document or across many. Send them to your LLM, in place of whole documents.

In one document

Pass the document's id, as in Quick start: up to 10 questions at once, each with the pages likely to help, and more_pages, the next most relevant, to read if those do not answer. The document's pages are priced as pages.

Across documents

Leave the document out and give a scope: a collection, the documents whose metadata meets a filter, a list of documents, or all of yours (see Choose the documents). The documents likely to answer are found first, then the pages in them that do.

result = client.search(
    "What was capital expenditure in 2018?",
    collection=reports,      # or documents=[...]; leave both out for all your documents
    filter={"year": 2018},
)

for doc in result.results[0].documents:  # most relevant first
    print(doc.filename, doc.relevance, [(p.page, p.relevance) for p in doc.pages])
Response
{
  "object": "search",
  "id": "srch_…",
  "results": [
    {"question": "What was capital expenditure in 2018?",
     "documents": [{"document_id": "doc_60a07bcef3094b68806070f2", "filename": "3M_2018_10K.pdf", "page_count": 160,
                    "metadata": {"ticker": "MMM", "year": 2018}, "relevance": 1.0,
                    "pages": [{"page": 39, "relevance": 1.0}, …], "failed_pages": []}, …]}
  ],
  "failed_documents": [],
  "processing_documents": [],
  "usage": {"documents": …, "pages": …, "questions": 1, "cost_usd": …, "balance_usd": …},
  "seconds": …
}
  • max_documents: open at most this many documents a question (default 3, up to 10).
  • document_top_k: open exactly this many instead, the most relevant.
  • Each document searched is priced as a document, and each page of the documents opened as a page (see Pricing).

To see which documents answer before searching their pages, see Search documents. Every field: API reference.