Friday, May 9, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

How to Improve LLMs with RAG | by Shaw Talebi

March 9, 2024
in AI Technology
Reading Time: 2 mins read
0 0
A A
0
Share on FacebookShare on Twitter



To set up our knowledge base, we begin by installing and importing necessary Python libraries using HTML tags. The following code snippet demonstrates how to install the required libraries:

“`html

Imports

“`

We start by installing and importing necessary Python libraries:

“`html

!pip install llama-index
!pip install llama-index-embeddings-huggingface
!pip install peft
!pip install auto-gptq
!pip install optimum
!pip install bitsandbytes

# if not running on Colab ensure transformers is installed too
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.core import Settings, SimpleDirectoryReader, VectorStoreIndex
from llama_index.core.retrievers import VectorIndexRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.postprocessor import SimilarityPostprocessor

“`

Next, we can configure our knowledge base by defining our embedding model, chunk size, and chunk overlap. We use the ~33M parameter bge-small-en-v1.5 embedding model from BAAI, which is available on the Hugging Face hub. Other embedding model options are available on this text embedding leaderboard. The following snippet of code demonstrates how to set up the knowledge base:

“`html

Setting up Knowledge Base

“`

We start by configuring our knowledge base with the following settings:

“`html

Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
Settings.llm = None
Settings.chunk_size = 256
Settings.chunk_overlap = 25
```

Then, we load our source documents from a folder called "articles" containing PDF versions of 3 Medium articles on fat tails. For each file in the folder, the code reads the text from the PDF, splits it into chunks, and refines the chunks by removing irrelevant text. Finally, the refined chunks are stored in a vector database. The code snippet below demonstrates this process:

```html

Next, we load our source documents

```

```html

documents = SimpleDirectoryReader("articles").load_data()

for doc in documents:
if "Member-only story" in doc.text:
documents.remove(doc)
continue
if "The Data Entrepreneurs" in doc.text:
documents.remove(doc)
if " min read" in doc.text:
documents.remove(doc)
```

Finally, we can create a retriever using LlamaIndex's VectorIndexRetriever and define a query engine that uses the retriever to return relevant chunks based on a user query. The following code snippet demonstrates how to set up the retriever and query engine:

```html

Setting up Retriever

```

```html

top_k = 3

retriever = VectorIndexRetriever(index=index, similarity_top_k=top_k)

query_engine = RetrieverQueryEngine(retriever=retriever, node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.5)])

```

Now, with our knowledge base and retrieval system set up, we can use it to return chunks relevant to a query. By passing a technical question to the query engine, we can retrieve relevant information. The code snippet below demonstrates how to use the query engine:

```html

Use Query Engine

```

```html

query = "What is fat-tailedness?"
response = query_engine.query(query)
```

The above code will return a response object containing relevant chunks of text. This information can be further processed and displayed for readability.



Source link

Tags: improveLLMsRAGShawTalebi
Previous Post

Welcome to the Valley of the Creepy AI Dolls

Next Post

Inflection AI presents Inflection-2.5: An Upgraded AI Model that is Competitive with all the World’s Leading LLMs like GPT-4 and Gemini

Related Posts

How insurance companies can use synthetic data to fight bias
AI Technology

How insurance companies can use synthetic data to fight bias

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset
AI Technology

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
How Game Theory Can Make AI More Reliable
AI Technology

How Game Theory Can Make AI More Reliable

June 9, 2024
Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper
AI Technology

Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper

June 9, 2024
Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs
AI Technology

Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs

June 9, 2024
Deciphering Doubt: Navigating Uncertainty in LLM Responses
AI Technology

Deciphering Doubt: Navigating Uncertainty in LLM Responses

June 9, 2024
Next Post
Inflection AI presents Inflection-2.5: An Upgraded AI Model that is Competitive with all the World’s Leading LLMs like GPT-4 and Gemini

Inflection AI presents Inflection-2.5: An Upgraded AI Model that is Competitive with all the World's Leading LLMs like GPT-4 and Gemini

Centre plans to increase supply of essential commodities under Bharat brand

Centre plans to increase supply of essential commodities under Bharat brand

If I Could Only Buy 2 High Dividend Yield Companies In March 2024

If I Could Only Buy 2 High Dividend Yield Companies In March 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

April 10, 2024
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In