Implement Document question answering
You can implement the Document question answering API in the following way:- Pass the question and the list of file IDs to the Semantic search API and get a list of passages back.
- Construct a prompt from the original question and the list of passages.
- Pass the prompt to an LLM and get a natural language answer.
- Return the answer from the LLM.
1
Upload PDF
You can upload a PDF file to CDF one of the following ways:
- Go to CDF > Industrial tools > Canvas and drag your PDF file to the canvas or upload existing files by selecting + Add data.
- Go to CDF > Industrial tools > Data explorer > Files and select Upload.
- Use the Python code.
2
Ask questions
Once the document is uploaded, we can start asking our questions.It may take some time before the document has been fully processed
and ready so we wrap the API call in a while loop, so that we can
retry until we get our answer.See the response for the test file.The response is more than a simple textual answer. The response structure allows for a multi-part answer, where each part of the answer can have one or more references to the document locations that were used to build the answer. If you are not interested in showing these references, you can iterate over the
content array and combine all the text fields.