News for hackers. Stuff that matters.
Re:Solving the out-of-context chunk problem for RAG by bob1029 on Wednesday July 24, 2024 @10:54AM (#41057738)
I've found the best approach is to start with traditional full text search. Get it to a point where manual human searches are useful - Especially for users who don't have a stake in the development of an AI solution. Then, look at building a RAG-style solution around the FTS.

I never could get much beyond the basic search piece. I don't see how mixing in a black box AI model with probabilistic outcomes could add any value without having this working first.

Re:Solving the out-of-context chunk problem for RAG by petercooper on Wednesday July 24, 2024 @11:22AM (#41058008)
You're right, and it's also possible to still use LLMs and vector search in such a system, but instead you use them to enrich the queries made to traditional, pre-existing knowledge bases and search systems. Arguably you could call this "generative assisted retrieval" or GAR.. sadly I didn't coin the term, there's a paper about it ;-) https://aclanthology.org/2021.acl-long.316/
Re:Solving the out-of-context chunk problem for RAG by k__ on Wednesday July 24, 2024 @11:11AM (#41057895)
I always wondered why a RAG index has to be a vector DB.

If the model understands text/code and can generate text/code it should be able to talk to OpenSearch no problem.

Re:Solving the out-of-context chunk problem for RAG by simonw on Wednesday July 24, 2024 @11:17AM (#41057957)
It doesn't have to be a vector DB - and in fact I'm seeing increasing skepticism that embedding vector DBs are the best way to implement RAG.

A full-text search index using BM25 or similar may actually work a lot better for many RAG applications.

I wrote up some notes on building FTS-based RAG here: https://simonwillison.net/2024/Jun/21/search-based-rag/

Re:Solving the out-of-context chunk problem for RAG by rcarmo on Wednesday July 24, 2024 @12:23PM (#41058679)
I've been using SQLite FTS (which is essentially BM25) and it works so well I haven't really bothered with vector databases, or Postgres, or anything else yet. Maybe when my corpus exceeds 2GB...
Re:Solving the out-of-context chunk problem for RAG by ianbutler on Wednesday July 24, 2024 @01:16PM (#41059357)
In 2019 I was using vector search to narrow the search space within 100s of millions of documents and then do full text search on the top 10k or so docs.

That seems like a better stacking of the technologies even now

Re:Solving the out-of-context chunk problem for RAG by ramoz on Thursday July 25, 2024 @06:36AM (#41066951)
Interesting. Why did you need to “narrow” the search space using vector space? Did you build custom embeddings and feel confident about retrieval segments?

I did similar in 2019 but typically in reverse, FTS, and a dual tower model to rerank. Vector search was an additional capability but never augmented the FTS.

Re:Solving the out-of-context chunk problem for RAG by ianbutler on Saturday July 27, 2024 @12:25AM (#41084457)
It was in consideration of how slow our FTS at the time was over large amount of documents and the window we wanted to keep response times in and you're correct, we had custom embeddings and we had a reasonably high confidence.

So vector search would reduce the space to like 10k documents and then we'd take the document ids and FTS acted as the final authority on the ranking.

Re:Solving the out-of-context chunk problem for RAG by niam on Wednesday July 24, 2024 @01:31PM (#41059527)
What are the arguments for embedded vector DBs being suboptimal in RAG, out of curiosity?
Re:Solving the out-of-context chunk problem for RAG by simonw on Wednesday July 24, 2024 @01:53PM (#41059755)
The biggest one is that it's hard to get "zero matches" from an embeddings database. You get back all results ordered by distance from the user's query, but it will really scrape the bottom of the barrel if there aren't any great matches - which can lead to bugs like this one: https://simonwillison.net/2024/Jun/6/accidental-prompt-injec...

The other problem is that embeddings search can miss things that a direct keyword match would have caught. If you have key terms that are specific to your corpus - product names for example - there's a risk that a vector match might not score those as highly as BM25 would have so you may miss the most relevant documents.

Finally, embeddings are much more black box and hard to debug and reason about. We have decades of experience tweaking and debugging and improving BM25-style FTS search - the whole field of "Information Retrieval". Throwing that all away in favour of weird new embedding vectors is suboptimal.

Re:Solving the out-of-context chunk problem for RAG by kgeist on Thursday July 25, 2024 @01:41AM (#41065077)
>but because embeddings search orders by similarity score it will ALWAYS return results, really scraping the bottom of the barrel if it has to

Why not have a similarity threshold? Say, if the distance is below 0.7, do not accept the search result.

Re:Solving the out-of-context chunk problem for RAG by simonw on Thursday July 25, 2024 @02:24AM (#41065315)
It turns out picking that threshold is extremely difficult - I've tried! The value seems to differ for different searches, so picking eg 0.7 as a fixed value isn't actually as useful as you would expect.
Re:Solving the out-of-context chunk problem for RAG by zmccormick7 on Thursday July 25, 2024 @11:08AM (#41069576)
Agreed that thresholds don't work when applied to the cosine similarity of embeddings. But I have found that the similarity score returned by high-quality rerankers, especially Cohere, are consistent and meaningful enough that using a threshold works well there.
Re:Solving the out-of-context chunk problem for RAG by kgeist on Monday July 29, 2024 @06:04AM (#41099279)
I use similarity threshold (to remove absolutely irrelevant results) and then use a reranker to get Top N.
Re:Solving the out-of-context chunk problem for RAG by jairuhme on Thursday July 25, 2024 @11:11AM (#41069610)
I'll add to what the other commenter noted, but sometimes the difference between results get very granular (i.e. .65789 vs .65788) so deciding on where that threshold should be is little trickier.
Re:Solving the out-of-context chunk problem for RAG by te_chris on Wednesday July 24, 2024 @11:17AM (#41057955)
Honestly you clocked the secret: it doesn’t.

It makes sense for the hype, though. As we got LLM’s we also got wayyyy better embedding models, but they’re not dependencies.

Re:Solving the out-of-context chunk problem for RAG by verdverm on Wednesday July 24, 2024 @12:45PM (#41058940)
You can view RAG as a bigger word2vec. The canonical example being "king - man + woman = queen". Words, or now chunks, have geometric distribution, cluster, and relationships... on semantic levels

What is happening is that text is being embedded into a different space, and that format is an array of floats (a point in the embedding space). When we do retrieval, we embed the query and then find other points close to that query. The reason for Vector DB is (1) to optimize for this use-case, we have many specialized data stores / indexes (redis, elastic, dolt, RDBMS) (2) often to be memory based for faster retrieval. PgVector will be interesting to watch. I personally use Qdrant

Full-text search will never be able to do some of the things that are possible in the embedding space. The most capable systems will use both techniques

Re:Solving the out-of-context chunk problem for RAG by k__ on Saturday July 27, 2024 @10:11AM (#41086723)
"When we do retrieval, we embed the query and then find other points close to that query."

To me that just sounds like OpenSearch with extra steps.

How is this different/better than a search engine?

Re:Solving the out-of-context chunk problem for RAG by benreesman on Wednesday July 24, 2024 @08:03PM (#41063517)
Inner product similarity in an embedding space is often a very valuable feature in a ranker, and the effort/wow ratio at the prototype phase is good, but the idea that it’s the only pillar of an IR stack is SaaS marketing copy.

Vector DBs are cool, you want one handy (particularly for recommender tasks). I recommend FAISS as a solid baseline all these years later. If you’re on modern x86_64 then SVS is pretty shit hot.

A search engine that only uses a vector DB is a PoC.

For folks who want to go deeper on the topic, Lars basically invented the modern “news feed”, which looks a lot like a production RAG system would [1].

1. https://youtu.be/BuE3DIJGWOw

Re:Solving the out-of-context chunk problem for RAG by alexmolas on Wednesday July 24, 2024 @11:31AM (#41058099)
But with FTS you don't solve the "out-of-context chunk problem". You'll still miss relevant chunks with FTS. You still can apply the approach proposed in the post to FTS, but instead of using similarity you could use BM25.
Re:Solving the out-of-context chunk problem for RAG by zby on Wednesday July 24, 2024 @04:24PM (#41061631)
Traditional FTS returns the whole document - people take over from that point and locate the interesting content there. The problem with RAG is that it does not follow that procedure - it tries to find the interesting chunk in one step. Even though since ReAct we know that LLMs could follow the same procedure as humans.

But we need an iterative RAG anyway: https://zzbbyy.substack.com/p/why-iterative-thinking-is-cruc...

Re:Solving the out-of-context chunk problem for RAG by mediaman on Thursday July 25, 2024 @02:16AM (#41065261)
For my application we do a land-and-expand strategy, where we use a mix of BM25 and semantic search to find a chunk, but before showing it to the LLM we then expand to include everything on that page.

It works pretty well. It might benefit from including some material on the page prior and after, but it mostly solves the "isolated chunk" problem.