Contextual Rag
Contextual RAG
Contextual Retrieval-Augmented Generation (RAG) is an advanced RAG technique that improves response relevance and efficiency by incorporating contextual compression during the retrieval process. Traditional RAG retrieves and sends full documents to the generation model, which may include irrelevant information, leading to higher costs and less accurate responses.
In Contextual RAG, the retrieved documents are processed through a Document Compressor before being passed to the language model. This compressor extracts and retains only the most relevant information for the query, or even discards entire irrelevant documents. This approach reduces the noise in the retrieved context, resulting in more precise, concise, and cost-effective responses from the generation model.
Reference: Contextual RAG
Initial Setup
Indexing
Retriever
Contextual Retriever
[Document(page_content='Discount points, also called mortgage points or simply points, are a form of pre-paid interest available in the United States when arranging a mortgage. One point equals one percent of the loan amount. By charging a borrower points, a lender effectively increases the yield on the loan above the amount of the stated interest rate. Borrowers can offer to pay a lender points as a method to reduce the interest rate on the loan, thus obtaining a lower monthly payment in exchange for this', metadata={'row': 1, 'source': './context.csv'}),
, Document(page_content="points is the concept of the 'no closing cost loan', in which the consumer accepts a higher interest rate in return for the lender paying the loan's closing costs up front. In some cases a purchaser can negotiate with the seller to get them to pay seller's points which can be used to pay mortgage points.", metadata={'row': 1, 'source': './context.csv'}),
, Document(page_content='Points may also be purchased to reduce the monthly payment for the purpose of qualifying for a loan. Loan qualification based on monthly income versus the monthly loan payment may sometimes only be achievable by reducing the monthly payment through the purchasing of points to buy down the interest rate, thereby reducing the monthly loan payment. Discount points may be different from origination fee, mortgage arrangement fee or broker fee. Discount points are always used to buy down the', metadata={'row': 1, 'source': './context.csv'}),
, Document(page_content='paying points will cost more than just paying the higher interest', metadata={'row': 1, 'source': './context.csv'})] RAG Chain
'Points on a mortgage, also known as discount points or mortgage points, are a form of pre-paid interest that borrowers can pay to lenders when arranging a mortgage in the United States. One point equals one percent of the loan amount. By paying points, borrowers can effectively reduce the interest rate on the loan, resulting in a lower monthly payment. Points can also be used to qualify for a loan or to have the lender pay the closing costs upfront. Points are different from origination fees, mortgage arrangement fees, or broker fees. The loan rate is typically reduced by a certain percentage when points are paid.'
Preparing Data for Evaluation
Evaluation in Athina AI
We will use Context Relevancy eval here. It Measures the relevancy of the retrieved context, calculated based on both the query and contexts. To learn more about this. Please refer to our documentation for further details
evaluating with [context_relevancy]
100%|██████████| 1/1 [00:01<00:00, 1.42s/it]
You can view your dataset at: https://app.athina.ai/develop/76c73e9b-7e13-4e2e-9cde-37565deefa56