Retrieval, rerankers, and RAG tips and tricks | Data Brew | Episode 39
Summary
- RAG fundamentals: Retrieval Augmented Generation injects relevant external information into language model prompts, enabling accurate responses to complex domain-specific questions.
- Optimization techniques: Master document chunking, embedding selection, query generation, and fine-tuning to build retrieval systems that deliver high-quality, contextual results.
- Advanced retrieval strategies: Enhance results using rerankers and diagnostics to improve search quality, then apply these patterns to enterprise AI applications.
Retrieval, rerankers, and RAG tips and tricks | Data Brew | Episode 39

In this episode, Andrew Drozdov, Research Scientist at Databricks, explores how Retrieval Augmented Generation (RAG) enhances AI models by integrating retrieval capabilities for improved response accuracy and relevance.
Highlights include:
- Addressing LLM limitations by injecting relevant external information.
- Optimizing document chunking, embedding, and query generation for RAG.
- Improving retrieval systems with embeddings and fine-tuning techniques.
- Enhancing search results using re-rankers and retrieval diagnostics.
- Applying RAG strategies in enterprise AI for domain-specific improvements.
Connect with Andrew Drozdov:
Chapters
0:00Introduction to RAG1:17Optimizing RAG queries5:38Personalization and IR12:47Evaluation techniques18:00Crafting effective prompts22:32Fine-tuning embeddings29:31RAG bottleneck analysis33:50Reranking strategies
FAQs
What is Retrieval Augmented Generation and why does it matter?
RAG enhances language models by injecting relevant external information into prompts, enabling them to answer latest, most difficult questions correctly despite knowledge cutoff limitations.
What's the most common mistake people make with RAG?
A simple RAG setup often just embeds all documents without optimization; this video covers best practices for document chunking, embedding selection, and query generation to improve results.
What are best practices for retrieval-augmented generation and reranking?
This Data Brew episode explores advanced techniques for improving retrieval-augmented generation systems on the Databricks Data and AI platform, including reranking strategies and vector search optimization. The video demonstrates how Databricks enables storing and retrieving dense vectors for semantic search while maintaining governance over document embeddings. Best practices include tuning reranking models to balance precision and recall, leveraging semantic similarity effectively, and managing computational costs.
How do rerankers improve retrieval quality?
Rerankers take initial retrieval results and reorder them by relevance, significantly improving the quality of context passed to language models for more accurate final responses.
Full transcript
0:00 Introduction to RAG
Welcome to day Brew by data bricks with and the series allows us to explore various topics in the data and AI Community whether we're talking about data engineering or data science we're going to interview subject matter experts to dive deeper into these topics meanwhile while we're enjoying our morning Brew I'm a principal developer advocate here at datab bricks and one half of data BR hi and director of our machine learning practice at datab bricks and the other half of datab brew and today we are thrilled to have drov a research scientist at datab bricks with a focus on Rag and in particular retrieval to tell us all of the things about how to be doing Rag and retrieval better so welcome y yeah hi and Demi it's great to be here um I know you all through work but it's kind of fun to have a another opportunity to hang out and try about interesting things definitely has been super helpful with uh helping my team out on customer engagements and customer projects and today I'm hoping you can Enlighten all of our listeners about what are some tips and tricks for doing rag well and perhaps let's just start off with what is Rag and what are the main areas that people can be looking to improve their rag systems totally so yeah rag is retrieval augmented generation for folks that uh don't know the abbreviation um it's it's pretty cool I'm like really excited about rag um you know fortunately we have these really cool AI models like these large language models and they've been trained with lots of data but they haven't been training on everything and they're kind of out of date as soon as they're released so yeah rag lets us um kind of inject useful information into the prompts so that language models actually have a chance of uh getting you know things correct about uh the latest most difficult and interesting questions that we're asking them M and so to be able to retrieve this context to then pass into a generative model what is the first thing that people typically do wrong would love for this to just be a learning session like what do people people typically do wrong when they're embedding their documents chunking them there's like really a lot of different components to rag um I think in the simplest setup you would um you know embed all of your documents like we're just talking about maybe a simple setting you're not doing web scale search you just want to search over a few of your documents for your team or your maybe the documentation of like some new coding library that you're using and you would embed uh all these documents and let's keep it simple let's just say they're already nicely organized and simple to embed yeah we'll pretend it's actually clean data let's just forsake argument yes yeah let's pretend so um um next uh you want to ask a question and generate an answer and what you'll do is uh embed your query now compare that against like the document embeddings find relevant documents and then take a a few of those like the text for those documents put it in the prompts and um with the original question and then generate an answer um so I've kind of described high level kept it very simple right clean data um one of the things that immediately you can start doing a little bit better is to generate like a better query and this is like the type of stuff I'm really excited about like I I found that one of the major bottlenecks in rad applications is you're just not finding the right thing and it's I think it's hard both for um like practitioners who are like using the latest greatest tools and they're trying to figure out how to get good quality out of their rack system but it's also hard for AI people where they're used to training you know mo like simple input output models um and they're maybe less familiar with a ir and they're used to you know tuning hyperparameters and looking like at loss numbers go down um but but kind of the magic about search and IR is if you find like the right piece of information that's like 99% like you're you're basically there now and it's kind of amazing how so many questions that we have it's not really like you need to aggregate information from lots of sources it's just like that you know the answer to your question is just like in a document somewhere it's just there you almost need to like copy it from that document to the output like like a huge chunk of the time so uh long answer to simple question of you know how to improve the rag pipeline but if you can just like improve your query um maybe uh use the language model to actually rewrite your query so it looks more like a query um that's already a pretty good way because like people you know they they get very conversational right they're like hi chat GPT or hi you know dbrx how are you doing I have this question today um you know they get very detailed and um there you really some just need a few keywords uh from that um to find the document that you care about yeah I'm curious though but I was under the impression that for example you sometimes do though want to provide a little bit too much a little bit more detail for example I mean the fun one that I use is when I when I con my my version of testing in LM by the way is the what I what called The Bagel test um you being in New Yorker will disagree with wholeheartedly with what I'm about to say was which just basically I'll ask storx or llama 3 you know which bagel's better New York versus Montreal if they answer Montreal then I know it's it's the correct you know it's the correct L the LM is actually worth me working with now and then so I'm not trying to start a debate but I have but I have I realized that but then also like to my actual question outside of just you know pegging you on here right is like for example you I I go ahead and toss it a system PR says hey go ahead and answer this question like your athlete Bordain so that way there's a lot of snark and sarcasm so I'm just curious from your perspective like what's that balance of like sometimes just like you said sometimes providing the right amount of information so that way it's like an IR Pro problem versus sometimes you actually do need to provide additional information that actually still somewhat helpful as opposed to uh making things worse right in terms of when you're doing that information retrieval right so by the way immediately no matter what I say now uh this isn't even about the bagel thing of course that's that's part of it too um I I'll just I'll just treat like a generic problem and not a I'll pretend like I'm not a domain expert here uh yeah so but no matter what I say we're all going to get in trouble because like we're calling it like an IR thing and now this is me getting pedantic of okay fair enough fair enough uh you know I I started going to IR conferences uh somewhat recently like within the last couple years and IR like the IR world is like so it's a lot bigger than like just search I guess or they think of search like encompassing a lot of different tools and Technologies including things like personalization um so like um I just want to make sure we're not oversimplifying here you know so but uh I I think to your point of like how much how much Det detail do you want to provide so you get like kind of a personalized response um um so that's really interesting I I do feel like I might have I missed like some parts of the question so um because you know there's many ways you can now personalize uh your compound AI system as we call it at data bricks um you could personalize the generation part right so it sounds like you might have been referring partially to that but you can also personalize the search part um so you know some people might prefer to find documents from Wikipedia versus documents from like Community forums or internal uh documents or long or short documents um so um that's also something that can be heavily personalized and we have lots of different options for how to uh incorporate that personalization um so how much of it should you include is also a super interesting question right so there's like how how would you actually do the personalization and how much detail should you provide and this is also super one I I um I don't know if I mentioned in my previous chats but I have some experience uh doing recommendation systems at eBay um and one of the cool things I worked on there was um we would we would basically recommend things for you to buy um so similar to like you know if you're using eBay or Amazon and you just bought bought something um and or you're you're about to buy something and there's a bunch of items that you might be interested in getting um you know recommend things that are other people bought uh you know like if you're looking and it's a hard problem because similarity search isn't always sufficient so if you're looking at like a PlayStation for example you probably don't want to buy another PlayStation it's like how many PlayStations do you really need um but you might want to buy like a game or like a controller um so you know that's but but it can also be confusing if you want to just provide recommendations based on like the person's purchase history um because when people are buying stuff on eBay and Amazon these aren't like specialized stores right they provide um you know you you can buy like anything right so um you might want to buy toothpaste and then buy your PlayStation and then buy a car like it's really you have a lot of or a house I don't know you can buy whatever you want um or or some swag so um uh it this history that's like one type of personalizations that's built into this specific application um and one of the challenging parts of that problem is is like how much weight do you want to provide to previously purchased items right so things that were purchased recently maybe you want to provide more weight and you kind of have to try to figure how how to disentangle things um if someone's buying a lot of things like right after each other um you know I think if you're just retrieving over your own documents it's a whole different type of personalization or you want to provide some snark um that's a whole other kind of personalization but uh I can go on and on like this so uh is this uh am I at least touching on some of the things you're you're Loosely curious about no no I I think you are I mean I think the quick context is you know if I was to sort of quickly summarize this that there are different points in which we can filter or direct how you want to personalize whether it's at the point of generation or the point of retrieval or any point in that complex a system and I and I I guess the the quick context is more a matter of like it how do you find that right balance between being super specific in order to get to just like said that particular document versus where you want to be a little bit more descriptive to be able to uh for it to be more uh imaginative with his responses I guess that's the upon risking hallucination yeah like I guess that's one to context on I would ask I mean I can talk kind of still a bit generally about maybe like the philosophy we have it uh on the rack team or or at data bricks and um I think we know we're we're really focused on like doing evil so that you know it kind of end up being the answer to everything it's like you just create an evaluation and this will tell you how much you need to do anything it's it's kind of beautiful yeah um so and I think also for the type of rag that we care about we want to we don't want to hallucinate too much but oh it's such an interesting problem now right um because once creativity gets involved but um you basically don't want to we want to avoid saying too much factual information or any any factual information that's not grounded on some type of uh document um yeah and so on the topic of evals I know most of the current evals are very generic but Enterprises don't really care about the generic benchmarks like they don't care how well you can complete the like ABCD tasks of helis Swag so how do people actually create meaningful ebal sets oh man that's I don't know well but I uh apparently we really like to throw the hard questions today yeah yeah sowh I I feel I'm feeling very I'm in like a very pedantic mood for some reason I don't know what it is I think it's like I did a lot of paper writing recently so fair enough fair enough I'm like a little uh hyper focused on on on saying things that are factually right so um I need to turn up my temperature I need to I need to start hallucinating a bit so um um I I think the part that I focused on what you said was like something about meaningful eals so it's like anybody can create an eal but how do you create like a meaningful eval um and I think the one of the reasons I say it's I don't know is because it's just like so hard to convince people to make their own eval um yeah it's just like it's a lot of work and I feel like it's super frustrating because yeah you don't know what's the meaningful part like you like why would someone to put in all this work if they don't feel like it's going to push the needle uh you know for their application um I I will say like I you know I when I was doing my PhD I worked with some people who were like cared very deeply about Evo um care very deeply about looking at data uh you know looking at the model outputs not just looking at loss curves um and although that you know it can be pretty fun to do that too um so and I feel like the things we focused on was coming up with specific capabilities and like challenging like finding specifically challenging instances um and seeing how models do on that um so um um but I don't I want to drift off topic uh so maybe we'll treat that as like background um I think that one of the things I'm really excited about these days are using language models to assist in Evo um so it I really think they're great for this problem like it's such a chore sometimes to go through data and like come up with questions and then it's an additional chore to like check uh all the model generations and like see how the model did and it's kind of amazing we can like models are like sort good enough or like almost good enough where you can automate kind of both sides of this quite a lot um so it is kind of something it's like with great power comes great responsibility type thing of uh so you got to be careful like you got to know that a lot of the you know if you're if you're using your model to automatically generate lots of questions and the answers and then also check if it can generate the answers to those questions it just you know generated both then uh uh there's going to be some noise and it's going to make mistakes um but you know I think within data breaks we're we're really looking at ways to improve the technology in the space um in in the rag setting specifically um if you care about things like search one of the fun things you can do is called question generation so you can take a document like any document it can be um some code it can be like a news article as the model to generate like let's say five questions um and maybe do like self-consistency so like ask it to generate five questions 20 different times and take the ones that come up the most frequently um and treat that as like a ground Truth for retrieving that specific document so this is nice because it takes a little bit of the answer generation part out of it right because we we kind of know the question is grounded on this document there are still some problems because sometimes a question is like a little bit underspecified so if you're like you know generating a question for like a mystery uh you know story and the question is like who did it like that's just not a very specific question that's going to you know if you type that into a search engine you're going to get lots of hits to totally random documents right so you got to make sure it's like a little bit specific so there's different things you can do like basically you run withal right after you generate and see if you're getting within ballpark and in terms of crafting the prompts so just going back to like the very initial phases of rag I know we haven't even gotten really to the retrieval side like we did prompts evil we'll get there um how many examples should you consider putting in uh I know you had some recent research about n shot examples do you do zero shot one shot eight shot just curious what your general recommendations are in terms of length and descriptiveness of problem yeah sure this might be another place where I can get into trouble also um so I just I really love uh I like the space a lot like I um think it's really cool that we can just like use examples to almost teach the model how to do something um without having to update the model parameters um so you can you can really the reason I'll get in trouble is because like I've thought really deeply about this problem so some things I might say really shouldn't be a general recommendation they're still very much in like the research bucket um but I I'm I'm really a proponent of just starting with like randomly sampling a few examples and putting them in your prompt um I feel like if you're not doing any of that's like a great starting point um and you know you can take that even a little bit further like if you're going to if you're focused on something like question generation where it's something you're going to run offline so you don't have like a big latency concern um then you can sample let's say like five things to put in the prompt and you can do that like five or 10 times and this is a way to not only improve the response you're going to get but get some like diversity in your responses um so that's pretty nice um so also it's really hard to pick good things so starting with random is a is just like you'll see if it's even like possible to improve things and again that's another reason to like try not just one set of random things but like a few and see if if it helps yeah that almost feels like the grid search versus random search analogy of like hyperprime re so like we all think we're so good about it random is just better sometimes yeah that's such a yeah so well said yeah if you want to get really extreme about it you can then try to like do automatic selection right so it's kind of things can get really meta really fast here cuz let's say we want to train an embedding model right so we've got some documents like a customer gives us some documents and they don't have any they they're you know they're really busy they're they're busy being a Fortune 500 company and they're really focused on you know they have a lot going on and they don't have clear signal on how to improve their embeddings so they're going to use the language model to do question generation and um they yeah they maybe start by sampling some few shot demonstrations and they do this a lot and now they have an implied label um so it's like a fun thing you can people can like kind of explore if they're feeling more experimental um they kind of know like oh this demonstration helps in some cases and maybe it didn't help in other cases and now you can even train an embedding model to find demonstrations in order to train an embedding model just to do the task that you're going to care about um so again this I I said I I could run into uh into trouble but uh the this is just one example of how you could uh push this to be a little further um but I'm really supportive of trying lots of different sets of demonstrations um it it's like one of the nice intuitions that I've tried to um kind of shout my in some of my recent papers is that um if you're just providing a demonstration that the model knows about then it might not be like a super useful signal um so one of the things I like to do is try to find hard demonstrations um so anyway um I'll I'll take a pause here and so I don't get into too much more trouble no it's okay don't worry I'll make sure to cause you trouble another way so I'll take sound great no but actually talking about embedding models one thing I'd like to understand better you know we had a side conversation about this idea of fine-tuning the embeddings as well and could you clarify that try to explain because yeah you know I'm still relatively new to this whole space and the idea is like I'm going to I you know I sort of understood this idea of fine tuning the large language model itself and you're saying no no we can actually in order to improve retrieval actually find through the embedding model so could you sort of clarify and explain that to yeah absolutely to somebody like me you know I'm sure you already understand it very deeply so um but it's it's super fun that we even have embeddings to play with these days so um I you know I think I mentioned right I I've been slowly getting more involved in the IR world and one of the favorite like INF foration retrieval baselines for search is a method called bm25 um so it's like super it's been around for a while I think like 2010 or something like that maybe earlier and it's a method that doesn't involve any neural networks um it's based off bag of words so very simple interactions uh between uh tokens um and it's basically measuring like how many words overlap in your query and your document um it has some normalization it has some things to make sure um you know duplicate words don't like artificially push up the score and stuff like that but um this this like really simple Baseline for search works really well um and if you I I like made a tweet joking about how it's such a strong model and like one of the top like IR influencers on Twitter said it should be nominated for a tweet of the year it's just like such a meme it's such a like everyone in the IR world knows how strong the Baseline it is and it's worth mentioning because I think a lot of people um again AI world and practitioners often ignore it it's like such a strong Baseline but it's so effective sorry such a simple Baseline but it's so effective recently you know people realized um you can also use neural networks uh for search so one of the things you can do is train like an unsupervised embeding um you know a lot of great deep learning folks have these unsupervised learning uh techniques to to learn representations of stuff of like text of images and they they mostly represent some degree of like similarity um so like in the image space if you were to take a picture of something um and rotate it and you were to convert both of those things into an embedding you would want those things to be similar um in text um maybe you want like the title to be similar to a document um that it came from or you want to be able to detect paraphrases of piece of text um there's all sorts of ways you can train this model on a large scale with like an unsupervised um like objective but they pretty much represent some definition of similarity or some definition of relevance that you have very little control over now if you're a specialist right and you want include search um so I'm I'm trying to think of an application in my mind but uh I don't know code I'm using Code a lot today so you want to do like um search to help you generate um some useful code and you might start by using something like bm25 or you might start by using one of these like offthe shelf we call them like dense edings that come from neural networks that were trained on lots of data and un supervised way um you you can start with that um but you're going to type in some code and that's your query now uh and if you're not doing this like query rewriting step that I mentioned earlier um you're just going to find other similar pieces of code and if you the code you're writing relies on like some documentation that wasn't mentioned in these like other similar pieces of code then one there's just like no way you're going to possibly find the right information using something that's just like similarity search and because of that you're not going to find the key piece of information so now we're getting back to the things I was mentioning about earlier where it's like search ends up becoming um the bottleneck like so we don't have to get totally stuck here we have some options now um I mentioned clear understanding is like one option so maybe you can rewrite it and like mention that oh I need some help uh figuring out how to sort lists or something like that so that's one option and then something like bm25 or your neural network could be um could have like the chance of finding the right piece of documentation but that's like a component that you now have to like manage and that's like latency right and in co- search like if you want to generate something um like like if you're if you're typing some code you don't want to like wait a long time you want right or if you're writing an email right you don't have to wait like 5 10 seconds to get like a recommendation of what you want us you know right next um so it's good to like remove pieces in this pipeline so we can just like bypass the query understanding like the query writing step by fine-tuning inets so I'm finally mentioning fine tuning Tings which I think that's what the question was about um so yeah so if if you if you have like a data set of this is the right document for this question which we know we can use language models generate by the way um we could just train a neural network like uh to match those two things right um so and we don't need there to be any overlapping text between the query and the document anymore they could look totally different they could be in different formats um we can just use the typical supervised learning stack use like contrastive learning uh this stuff is used in lots of places um and just like fine-tune the embedding to actually match queries to documents that we care about just so we have a chance and sometimes like a really good chance now of finding the information that we care about and so when would you recommend that somebody find tune embeddings always never it depends um oh great question I mean if I think about it in like the list of things you can try it's like very high on the list right so if you have a rag application and you want to get better quality whatever you know however you're evaluating that quality um then I would put it very high on the list because I often think with my IR hat on and I think of search as like the bottleneck so it's also like surprisingly straightforward uh I think yeah folks often they want to just like take a model and just use it as it is um but there's a lot of libraries for doing embedding funing specifically um so you can start with like a pretty good embedding model already um and do some like automatic question generation maybe on your on your data and then just like fine-tune even a small embedding model um like you could just open a collab or or a data breaks notebook and do some fine tuning um so I'm like dancing around the question um but I I feel like yeah you should just try it like I don't I don't think it's like that it it just if you're able to write code in a notebook I feel like you should do embedding fine tuning um you can take it further right you can like really um work on building strong question generation pipelines um you can work on doing like large batch size inv betting finetuning uh you can work on mining really good negatives um but you can often get by without doing any of those things like you just start with some labeled data um maybe like a few thousand examples that were like just created from a language model um and find an embedding model and um I would be hard pressed to find a specific domain where I don't think that would help like maybe things that are like really adversarial so like really long text um or like things that have I don't just like super strange text that maybe it it's like so unusual I can't even like think of an example but like like it's like you invented your own language that yeah like if I if I embed if I place Klingon in there I don't know everyone's like into Kling on now so oh it's true actually okay point take it okay but uh one of the things that is really funny to me is that there's like this dynamic between embeddings and bm25 so I think some folks might start with being 25 if they're familiar with it um and then see that you know it's based on this like simple like word matching between query and document so they'll see like it misses out on synonyms and some basic stuff like that feels like it should like if you misspell something it could screw up bm25 right so those are things where like a neural network would would be more like robust so then they switch to a neural network but then the neural network misses out on like product codes and like identifiers uh for you know whatever right and things that like bm25 would do really well so I I actually feel that if you hit that situation that is also a really good opportunity for embedding fineing because it'll just kind of ideally you're teaching the model like it should actually do this product code magic yeah and I definitely like your point of retrieval is the Crux of the whole system it's like garbage in garbage out doesn't matter how amazing your 40 gener model is if you can't retrieve the right context um even if it has a lot of snark I mean exactly yeah um and so speaking of retrieval I know there's also some work done in the field of rankers and so curious to get your take on just pure retrieval versus incorporating rankers like will this improve the quality of my overall rag system oh this is fun so this is something I work uh pretty actively on for folks listening who maybe don't know what reranking is um it's when you start with something efficient like bm25 or dense embedding uh these are both representations that are really fast um and they often don't need very expensive models and so so they're fast for two reasons because the models are usually a little bit um more efficient already and also because they usually just entangle the queer the and a document representation so you can pre-compute um all of the uh document representations um saving you kind of work at search time um so you start with the fast thing you get like a list of 10 uh candidate documents or 100 or or more and what you know now you have like an opportunity to use something more expensive uh so because you yeah you um um you've already done a lot of the like groundwork you've already found like uh you know the like a pool of interesting items um so now you can use like an expensive model to rerank um um that list so ranker is uh basically another term for these like expensive models that are specialized for um sorting this like candidate list that came from your first stage uh embedding or or bm25 so I again I'm kind of like repeating things today think that both practitioners and folks in AI um are kind of like misunderstanding the whole search process like they think it's just embeddings like maybe they think it's just unsupervised and they don't have to fine tune or maybe they fine tune and they're like okay we're done and they don't realize you can do these other things like improve your question generation pipeline um and I think a lot of people are aren't jumping to reranking because that's now like another uh component but it's probably easier to reranking now than it ever has been so there are now some amazing uh ranking apis um so there's also a bunch of reranking models on hugging face that anybody can just go ahead and try and they can give such a huge boost to numbers like recall and ndcg like typically I see something like 10 to 20% Improvement on those metrics so that's like a and if we think of search as the bottleneck so if you're getting like 50 60% uh recall at 10 let's say and then you add a ranker um even if it's it's like a not necessarily like state of the stateof the-art but it's like a decent re ranker from like hugging face you can probably bump that by 10 to 20% so now you're at like maybe 60 plus LR like 50 to 60 recall 10 um and that's I think that's that's a if like that's a big bump right um so I also think like language models are one way you can do ranking that people are still like sleeping on a little bit um so I I published a paper um when I was at Google about using uh language models for reranking um and happy to talk about that or you know yes we' love you to dive into yeah again this is where things can get very meta so we were uh um um so in the IR world there's been this you know people have looked at rag right and they see how retrieval is helping generation but in the IR worlds they're also looking the other direction they want to see how can language models help retrieval I already mentioned one way which is through question generation and that is like really powerful technique but you can actually just use the language model already to do search um one really simple thing you can do and it's kind of mind-blowing how simple it is is that you can just have the model output a relevant score for you give a query and a document you put them both in the prompts and that surprisingly works a lot of the time um so that's all so pretty much what the reranking architecture is by the way I I was kind of hinting at how the reranking architecture is like more expensive the way it's usually more expensive is that instead of just taking a query and document separately and outputting something the re ranker takes the query and document together and then jointly um kind of encodes the information um so it it has like more context uses more computation because it has like a longer input and because of all things like a more expressive model right so that's what a r ranker or architecture usually looks like the language model is the same thing right where you're putting the query and a document together in the prompt and we're outputting something when I was at Google we weren't just outputting the score we were looking at the logits so this is a little bit more advanced now I think a lot of apis sometimes like they decided they're going to turn off logit access for customers it depends on the company um I think it is also it's just more advanced from like a a customer standpoint people are used to de with tokens there you know token probabilities that's a whole that's a whole new thing but um when I was at Google we incorporated a f shot prompting to make this better so we would provide examples of questions and matching documents in the prompt so that when it's generating this relevant score it had a better chance of getting it right and we used retrieval to find those examples so we had our heris like retrieval that would find um the signal in our retriever was difficulty so we were trying to find the most difficult examples and include those in the prompt and we found that gave um a bigger like that would work that was more effective than random in our use case um so I can even talk about another can I preview another paper that I'm working on sure okay okay so this is like my first paper since I've joined datab bricks and I'm really excited about it so um we had an intern Last Summer with the rag team and we were really looking at the reranking problem and trying to understand ranker is better and one other things I think we care a lot about at data bricks are like cost quality tradeoffs so that comes up a lot in Rag and reranking because like say you use an embedding model and you're getting a good recall of 10 at like 50 documents um so that means you're going to include all 50 documents in the prompt and that's like a really long prompt now so it's going to be expensive and slow when you're generating the response if you could get that same recall with like 10 documents instead of 50 you could end up with a shorter prompt and that's like where reranking can get involved even though it's a more expensive model there could be a good tradeoff where you're you know using some of the cost on the ranker and less so on in Generation Um so that's what we were starting that's what we were exploring um but we found something really interesting and surprising which was that we we were like trying to push the boundary so we were trying to see how many um what would happen if we were ranked not like a hundred but like a thousand or even like 10,000 documents or even like the whole data set um so we're just going to take the most expensive model which we think about as like richer and like more accurate than the embedding model and just use the output from that um instead of doing this like two-stage Pipeline and we found like the ranker was actually worse so that was kind of surprising so so we saw these two things we saw one if we were reranking like 10 or 50 documents that was good but once we hit like a 100 or 500 or like a thousand it started getting worse and sometimes would actually get worse than just using the embedding um and then we did this like Fair competition where we just like use the ranker on the whole data set so now there's no like two-stage pipeline to cause noise and we and we found that even in that situation things are worse so the reason I'm so excited about this is because I think this points out people are not only just sleeping on the application of rer rankers but they're sleeping on like how do you train rankers properly um so I think of this as like a diagnostic maybe something like lost in the middle right like that was such a huge finding I think when people realize that language models they miss information in the middle of the prompt and then all the companies and researchers came up with techniques to fix that problem I think of um what we found as like a new diagnostic for rankers where we want to you know when you when you put an embedding head-to-head with the ranker you definitely expect the ranker to be better um so I I kind of like ripped but I'm yeah I'm basically really excited about this paper and just about doing more more research uh in room rers so but but I I want to just like say a couple ending pieces here which is that I do think folks should keep exploring your rankers even the ones that are off the shelf now it's so amazing how you can get an improvement on on search and in many cases it does make sense to trade off costs for like more accurate search so you can includes Le less documents um but just you know be careful like not too careful but just like be be be aware that like this is like kind of a hyper parameter how many documents you're reranking and I know my team has definitely applied these tips and tricks that you recommended one of the fun ones was uh we were working with a customer we're using llama uh lava 3.
33:50 Reranking strategies
1 70b for the final generative step and it was just too slow we were passing in way too much context in the prompt and so we took your advice of let's use a language model to assess whether or not the context is actually relevant so we could pass in less context and we're able to use a smaller model like an 8B model for evaluating that and so Nets net net was it was actually cheaper uh faster and higher quality oh man I love that's so that's so great to hear and yeah I mean I I already knew this we talked about it but um hey it's still great to hear again um and that but that's exactly what I'm talking about right um it's it's knowing that you even have this option um can really make a big impact um so so if you know if we had a better ranker you think the team would be interested absolutely okay cool well thank you so much today for chatting about uh information retrieval rag systems and how you can overall get better Enterprise quality uh llm application so thank you again of course yeah thank you thank you
Learn more about the Databricks Data and AI platform.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.