Avi Chawla Profile picture
Dec 26 7 tweets 2 min read Read on X
Traditional RAG vs. HyDE, clearly explained (with visuals):
Questions are not semantically similar to their answers.

As a result, several irrelevant contexts get retrieved due to a higher cosine similarity. Image
HyDE attempts to solve this.

The following visual depicts how it differs from traditional RAG and HyDE.
- Use an LLM to generate a hypothetical answer H for the query Q.

- Embed the answer using a contriever model to get E.

- Query the vector database and fetch relevant context (C) using E.

- Pass the retrieved-context C + query Q to the LLM to produce an answer. Image
of course, the hypothetical generated will contain hallucinated details.

The contriever model tries to handle this.

It is trained using contrastive learning to function as a near-lossless compressor whose task is to filter out the hallucinated details.
Several studies have shown that HyDE improves the retrieval performance compared to the traditional embedding model.

But this comes at the cost of increased latency and more LLM usage. Image
That's a wrap!

If you enjoyed this tutorial:

Find me → @_avichawla

Every day, I share tutorials and insights on DS, ML, LLMs, and RAGs.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Avi Chawla

Avi Chawla Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @_avichawla

Dec 24
What is Temperature in LLMs, clearly explained (with code demo):
Let's prompt OpenAI GPT-3.5.

A low temperate value produces identical responses from the LLM (shown below): Image
But a high temperate value produces gibberish

Let's understand what's going on. Image
Read 9 tweets
Dec 23
Tool calling in LLMs, clearly explained (with code):
When generating text, the LLM may need to invoke external tools or APIs to perform specific tasks beyond their built-in capabilities.

This is known as tool calling, and it turns the AI into more like a coordinator. Image
The process is:

• Recognize when a task requires external assistance.

• Invoke the appropriate tool or API for that task.

• Process the tool's output and integrate it into its response.

Let's implement tool calling by building a stock price retrieval assistant.
Read 9 tweets
Dec 18
Prompting vs. RAG vs. Finetuning, which one is best for you, clearly explained:
When building LLM-based apps, it is unlikely you can start using the model right away without adjustments. To maintain high utility, you either need:

• Prompt engineering
• Fine-tuning
• RAG
• Or a hybrid approach (RAG + fine-tuning)

This visual will help you decide: Image
Two important parameters guide this decision:

• The amount of external knowledge required for your task.

• The amount of adaptation you need.
↳ Adaptation means changing the behavior of the model, its vocabulary, writing style, etc.
Read 6 tweets
Mar 5
Sigmoid and softmax are not implemented the way most people think:
The most common way one would write a custom implementation for Sigmoid is as follows:

However, there is a big problem with this specific implementation, which is why most frameworks don’t implement it this way.Image
More specifically, if the input to this function is a large negative value, it can raise overflow errors/warnings:

The issue is quite obvious to identify as for large negative inputs, the exponent term in the function (e^(-z)) becomes increasingly large.Image
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(