How to attach document source in gpt openai

I am developing pdfGPT that reads pdf and we ask based on information from PDF that pdfGPT read before.
The PDFs we will use are increasingly dependent on the needs.
So, I want to add a link to download the file used for the answer.
How do I do the billing process?
To do the billing process you must… blablabla… (source: Billing Process.pdf)

For your use case, use embeddings.

Here’s a typical flow:

1. upload PDF file
2. extract text from PDF file
3. get embeddings for the extracted text
4. save result somewhere (e.g. database)
5. user asks query
6. get embeddings of query
7. process query embedding result with saved result from step 4
8. summarize result using chat api

There was a QnA sample before in OpenAI cookbook that shows your specification (including adding source document in result) but I cannot find it right now.

Thanks for the flow.
Any link will be appreciated.
I have searched all over but with no result

I checked the cookbook and they removed it. Maybe you can clone the cookbook site and, if possible, git restore the deleted apps folder and you can check file-q-and-a folder for the complete sample project.

Anyway, basically, you will need to pack the embedding result and file info in some data structure:

    url: URL.createObjectURL(file),
    type: file.type,
    size: file.size,
    expanded: false,
    embedding: meanEmbedding,
    extractedText: text,

and this is the one you will store in the database.

When you process the user query, you will loop through these stored file data to perform cosine similarity, etc. So you can see which file you are getting hits. You will then append the result later in your system prompt.

const filesString = fileChunks
        .map((fileChunk) => `###\n\"${fileChunk.filename}\"\n${fileChunk.text}`)
        .slice(0, MAX_FILES_LENGTH)

const system_prompt = `You are a helpful assistant.\n