Quick start
Upload a PDF, then ask questions about it. You get back, for each question, the pages likely to answer it.
1. Get a key and upload a PDF
Create an API key in the PageIndex Console, install the SDK and upload a PDF:
export PAGEINDEX_API_KEY="your-pageindex-key"
pip install -U pageindex
from pageindex import PageIndexClient
client = PageIndexClient(index="cloud") # reads PAGEINDEX_API_KEY
doc_id = client.submit_document("report.pdf", wait=True)["doc_id"] # wait: until it is ready to search
print(doc_id)
2. Search it
Ask up to 10 questions in one search; ten take about as long as one.
result = client.search(["What was capital expenditure in 2018?", "Who is the CEO?"], document=doc_id)
for answer in result["results"]:
print(answer["question"])
for page in answer["documents"][0]["pages"]:
print(" page", page["page"], page["relevance"])
What search() returns:
{
"id": "srch_51b0c2…",
"results": [
{"question": "What was capital expenditure in 2018?",
"documents": [{"id": "pi-cmwi3zsxk000109p6gspztvzb", "name": "report.pdf", "pageNum": 160, "relevance": null,
"pages": [{"page": 39, "relevance": 1.0, "read": "text"}, {"page": 126, "relevance": 1.0, "read": "text"}, {"page": 49, "relevance": 0.9, "read": "text"}, …],
"more_pages": […], "failed_pages": [], …}]},
{"question": "Who is the CEO?",
"documents": [{"id": "pi-cmwi3zsxk000109p6gspztvzb", "name": "report.pdf", "pageNum": 160, "relevance": null,
"pages": [{"page": 8, "relevance": 1.0, "read": "text"}, {"page": 134, "relevance": 1.0, "read": "text"}, …],
"more_pages": […], "failed_pages": [], …}]}
],
"failed_documents": [],
"processing_documents": [],
"usage": {"documents": 0, "billable_documents": 0, "pages": 160, "questions": 2, "billable_pages": 160, "credits": 1.92, "balance": 998.08},
"seconds": 0.88
}
Each question lists, under the document searched, the pages likely to help, most relevant first, each with its relevance from 0 to 1, to one decimal. It may list none, when no page is likely to help. Set top_k=5 to get exactly that many pages instead. usage.credits is what the search cost and usage.balance what is left; a credit is $0.01. Search the same document as often as you like: it is processed once.
Next
- Search pages: search across all your documents, a collection, or those whose metadata meets a filter.
- Search documents: find which documents answer, before searching their pages.
- Collections with metadata: group and tag documents, to search just the ones you mean.