Boosting results for RAG
Putting as many information as possible in your Knowledge Box is often tempting, "the more knowlege, the better the results", but it may also lead to a lot of noise in the results.
A common use case is when you have some kind of official and trustable information (let’s say user manuals), and some kind of user-generated content (like customer reviews). The user-generated content is often more verbose and contains more information, but it is also more noisy and less trustable.
The problem with a simple RAG approach is that it will try to find the answer in the most relevant paragraphs, and the most relevant paragraphs coming from customer reviews might drown the most relevant paragraphs coming from the user manuals. It happens because the customer reviews are excellent semantic matches regarding the question asked by the user, as they are very likely to be phrased the same way, using the same words, and the same concepts.
To solve this issue, you need to be able to boost some results over others. This is what the prequeries
RAG strategy can do.
The Prequeries RAG strategy
The prequeries
RAG strategy will run a set of queries before the main query to gather additional information that will be used to generate the answer. The results of these queries will be appended to the context.
Each prequery can have a specific weight that will be changing the final ranking of all the collected paragraphs.
In the use case described above, assuming your user manuals have a specific label, you can run the same query on the user manuals and on the customer reviews, and give a higher weight to the user manuals results.
{
"query": "How to replace the battery on C-3PO?",
"rag_strategies": [
{
"name": "prequeries",
"queries": [
{
"request": {
"query": "How to replace the battery on C-3PO?",
"filters": ["/classification.labels/doctype/product_manuals"]
},
"weight": 5
},
{
"request": {
"query": "How to replace the battery on C-3PO?",
"filters": ["/classification.labels/doctype/customer_reviews"]
},
"weight": 1
}
]
}
]
}