Hi! I have been following the azure open ai search demo (available in github, but I couldn’t include link here). In the demo, AI is provided with system message to answer user’s questions based only on documents that are provided to it from Azure Cognitive search (and providing references from where each fact has been retrieved).
In the application, I have played around with the “chatreadretrieveread” approach and tried to limit the AI to use only certain sources. My system prompt is exactly the same as in the repository, except one added part at the end: “Use ONLY source named ‘PerksPlus.pdf’ to generate your answer”.
For some reason the AI model doesn’t seem to take this instruction into account, but uses that source anyway if it is available. Any tips or resources that might help me?
So, I’m assuming you’re programming on the API it sounds like? What exactly is wrong with the responses? Or rather, what is it currently outputting, and what would you like it to do instead?
This sounds like something where RAG and vector embeddings would be vital.
Also, you might have success in lowering the temperature, where it makes more deterministic responses based on the input and guidance.
Thanks! Yes, I am programming with the API using RAG-approach and vector embeddings are also included (the temperature is also set to 0). The implementation makes a hybrid search (vector and text search combined) to Azure Cognitive Search to retrieve relevant documents to the user’s question. After that, it is using the language model’s API to provide the AI the user’s original question and the text content of the fetched documents. AI should then answer the question based on the text content provided to it.
Each source/document is separated in the prompt, so that the AI can distinguish between sources and provide reference where the information is coming from. AI does this part very well, but when I tell it explicitly to use only a certainly named source, that instruction is not taken into account. Here is the full system message, which is working very well except the last sentence that I have added (rest of this is coming from the “azure open ai search” example Github repository):
“role”: “system”, “content”: “Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.Answer ONLY with the facts listed in the list of sources below. If there isn’t enough information below, say you don’t know. Do not generate answers that don’t use the sources below. If asking a clarifying question to the user would help, ask the question. For tabular information return it as an html table. Do not return markdown format. If the question is not in English, answer in the language used in the question. Each source has a name followed by colon and the actual information, always include the source name for each fact you use in the response. Use ONLY source named ‘PerksPlus.pdf’ to generate your answer”
So the AI model doesn’t follow the command not to include other sources than PerksPlus.pdf. If other documents are retrieved from the Azure Cognitive Search and provided to it, it will use them in the final response even though instructed otherwise.
Remember, these systems follow prompts as precisely as possible. You appended this line telling it to only pay attention to one source, however the rest of the entire prompt is telling it how to handle information from multiple sources. So, either give it a “list” of sources where that source is the only source on the list, or modify the prompt to explicitly ask it to retrieve information from that single source and nothing else. You can’t have it both ways. I’ve modified the sample prompt for you below in a way where it should only retrieve information from that source:
Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers. Answer ONLY with the facts listed in ‘PerksPlus.pdf’. If the information is not accessible from ‘PerksPlus.pdf’, say you don’t know. Do not generate answers that do not use this specific source. If asking a clarifying question to the user would help in generating a response, ask the question. For tabular information return it as an html table. Do not return markdown format. If the question is not in English, answer in the language used in the question. Use ONLY information from the source named ‘PerksPlus.pdf’ to generate your answer.
Go ahead and see if that works. Keep in mind, if you want this prompt to be more general-use, you would not modify the prompt, but the list of sources you provide it instead. That way, you make sure it adheres to only what’s on the list, and if only one item is on the list, well, then that’s all it’s going to pull from.
Great thanks! Yes, my final goal would be to enable the AI to either answer the question from a certain subset of the files or do comparisons between these subsets.
For example the list of the sources would include similar documents from different business units. The user could then ask the AI to just include documents from certain business unit or to make comparisons between them. The first use-case would probably be easier to implement by restricting the initial search to only a certain subset of the documents, but the latter one would probably require tuning quite heavily the system prompt. This restricting the answer to be generated only from one file was the starting point of this tuning
Have you heard of LangChain btw? You sound like you’re probably handling this for a business more so than play, but I would look into the framework regardless, because it might help simplify your end-goal with your project here by a significant degree. LangChain is designed for use cases like these. It makes organizing and working with different groups of docs or vectors far, far less of a headache while also allowing you to create prompt templates. For example, you could take my above prompt, turn your doc name into a variable like {this}, and now you have a way to get the AI to pull from whatever single source you want to put there.
What you bold seems like the source of your failure. Cognitive search results (embeddings) returns chunks of documents. It doesn’t include the source of a segment of text with the verbosity needed to say “I don’t know” - unless you have specifically augmented the return with metadata text yourself.
Also, “sources” should not mention (or be) “below”. They should be provided in an assistant role above the current user question upon which their search was based, and will work best with prefix like “Knowledge augmentation relevant to the following question”.
But expecting the AI to follow system message programming for its job and role is now something that you cannot expect to work reliably, as OpenAI apparent policy is continually attacking developers with reduced instruction-following model updates for any product that tries to be smarter than ChatGPT.