RAG Drift Detection - #1922
Open
MasemeneMatlakanaBenny wants to merge 24 commits into
Open
RAG Drift Detection#1922MasemeneMatlakanaBenny wants to merge 24 commits into
MasemeneMatlakanaBenny wants to merge 24 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces topic-based drift and alignment metrics for RAG systems.
The goal is to evaluate whether the topics present in a RAG knowledge base are aligned with the topics appearing in user queries, as well as to detect topic-level changes between reference and analysis content.
What's Included
Added topic distribution extraction using BERTopic.
Added
TopicContentQueryDriftfor measuring topic alignment between:Added
TopicSemanticContentDriftfor comparing topic distributions between:Added topic-word extraction and dataframe representations for downstream analysis.
Added topic mismatch detection.
Integrated categorical similarity metrics:
Added unit tests covering topic distribution, topic extraction, mismatch detection, dataframe generation, drift construction, and similarity metric delegation.
Motivation
Traditional RAG evaluation often focuses on retrieval relevance or answer quality. This PR adds another dimension by looking at the topic space of the system.
This allows us to answer questions such as:
The intention is to provide a higher-level signal for monitoring RAG topic alignment, coverage, and semantic drift.
Testing
Unit tests were added for the new functionality, with external topic-model behavior mocked to keep the tests deterministic and independent of BERTopic model training.