Reputation: 61
I'm currently exploring the implementation of Retrieval-Augmented Generation (RAG) for text classification, but I'm facing a lack of comprehensive online resources to guide me through the process.
In this project, the task involves taking a sentence as input and categorizing it into one of three distinct classes. Rather than opting for fine-tuning, I'm keen on leveraging RAG. However, I'm grappling with the challenge of embedding test cases in a manner that allows for subsequent retrieval and classification by a large language model (LLM). I'm specifically looking for an embedding model that can create these embeddings while incorporating the associated class information for each sentence.
Upvotes: 0
Views: 3188
Reputation: 11
Don't use embeddings to contain class attributes. That will mess with retrieval quality.
Use metadata filters instead.
Retrieve Include classes in the metadata before feeding it to the rag. Then when you do a a retrieval, use the metadata filter to make a retrieval call for each class getting the top n for each class.
Prune (Optional) If all the results of a particular class don't pass a distance threshold (you as the developer will set this threshold), then you can remove all the retrieval results for that class. This simulates the pruning steps of some classifiers like ID3/C4.5
Creating and Sending Prompts Add your retrieval results to your prompt. The retrieval results should be class labeled. Ex. "{data: , label: }". That should allow you to add enhanced context in the prompt that will facilitate classification.
Note: Here's a sample of metadata-filter implem in llama
Upvotes: 1