• About TC
  • Affiliate Disclaimer
  • Privacy Policy
  • TOS
  • Contact
Tuesday, July 1, 2025
Techcratic
  • TC
  • AI
    Artificial Intelligence

    EgoDex: Learning Dexterous Manipulation from Large-Scale Egocentric Video

    Artificial Intelligence

    Instruction-Following Pruning for Large Language Models

    Artificial Intelligence

    How to Combine Streamlit, Pandas, and Plotly for Interactive Data Apps

    Artificial Intelligence

    Tailor responsible AI with new safeguard tiers in Amazon Bedrock Guardrails

    Artificial Intelligence

    Automate Data Quality Reports with n8n: From CSV to Professional Analysis

    Artificial Intelligence

    NewDay builds A Generative AI based Customer service Agent Assist with over 90% accuracy

    Artificial Intelligence

    5 Things You Need to Know About Agentic AI

    Artificial Intelligence

    Normalizing Flows are Capable Generative Models

    Artificial Intelligence

    Update on the AWS DeepRacer Student Portal

  • App Zone
    Top 3 Launcher Apps for Apple: Features, Pros, and Cons

    Top 3 Launcher Apps for Apple: Features, Pros, and Cons

    Top 3 Launcher Apps for Android: Features, Pros, and Cons

    Top 3 Launcher Apps for Android: Features, Pros, and Cons

    Top 3 Card Game Apps of 2025: Features, Pros, and Cons

    Top 3 Card Game Apps of 2025: Features, Pros, and Cons

    Top 3 Medical Apps of 2025: Features, Pros, and Cons

    Top 3 Medical Apps of 2025: Features, Pros, and Cons

    Top 3 Travel Apps of 2025: Features, Pros, and Cons

    Top 3 Travel Apps of 2025: Features, Pros, and Cons

    Top 3 Casual Game Apps for 2025: Features, Pros, and Cons

    Top 3 Casual Game Apps for 2025: Features, Pros, and Cons

    Top 3 Food Apps for 2025: Features, Pros, and Cons

    Top 3 Food Apps for 2025: Features, Pros, and Cons

    Top 3 Sport Apps for 2025: Features, Pros, and Cons

    Top 3 Sport Apps for 2025: Features, Pros, and Cons

    Top 3 Productivity Apps for 2025: Features, Pros, and Cons

    Top 3 Productivity Apps for 2025: Features, Pros, and Cons

  • Apple
    SwitchBot Hub 3 gains ‘Works with Apple Home’ certification

    SwitchBot Hub 3 gains ‘Works with Apple Home’ certification

    July 1, 2025 – Apple AI rumors, 10 years of Apple Music

    Will the iPhone 17 lineup really have higher refresh rate displays?

    The biggest iPhone 17 mystery left could swing a lot of upgrade decisions

    Apple hit with $110M damages in 3G patents lawsuit

    Apple hit with $110M damages in 3G patents lawsuit

    Photos iOS 26 vs iOS 18: Compared

    Photos iOS 26 vs iOS 18: Compared

    Here’s everything new for Apple Photos in iOS 26

    Here’s everything new for Apple Photos in iOS 26

    Apple gains ground with new Macs despite market challenges

    Apple gains ground with new Macs despite market challenges

    Anker Power Bank, Zolo, MagGo, recall

    Anker Power Bank, Zolo, MagGo, recall

    Developer for Linux on Apple Silicon Macs resigns, citing ‘major failure of leadership’

    New ‘MacBook’ rumor sounds like Apple’s taking the iPad approach

  • Retro Rewind
    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 57 April 1994

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: Computer Gaming World Magazine Issue 73 December 1998

    Retro Rewind: Computer Gaming World Magazine Issue 73 December 1998

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

  • Tech Deals
    Skytech King 95 Gaming PC Desktop, Intel i7 14700F 2.1 GHz (5.3GHz Turbo), NVIDIA RTX…

    Skytech King 95 Gaming PC Desktop, Intel i7 14700F 2.1 GHz (5.3GHz Turbo), NVIDIA RTX…

    ASRock – B550M PRO SE – ASRock B550M Pro SE Gaming Desktop Motherboard – AMD PRO565…

    ASRock – B550M PRO SE – ASRock B550M Pro SE Gaming Desktop Motherboard – AMD PRO565…

    Soundcore A30i by Anker, Smart Noise Cancelling Earbuds, Lipstick-Shaped Stylish Design,…

    Soundcore A30i by Anker, Smart Noise Cancelling Earbuds, Lipstick-Shaped Stylish Design,…

    ADATA Premier 256GB MicroSDHC/SDXC UHS-I Class 10 V10 A1 Memory Card with Adapter Read…

    ADATA Premier 256GB MicroSDHC/SDXC UHS-I Class 10 V10 A1 Memory Card with Adapter Read…

    acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable DPI Office Cordless…

    acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable DPI Office Cordless…

    STGAubron Gaming PC Computer Desktop, GeForce GTX 1660 Ti 6G, Intel Core I7 up to 3.9…

    STGAubron Gaming PC Computer Desktop, GeForce GTX 1660 Ti 6G, Intel Core I7 up to 3.9…

    Sonic & SEGA All-Stars Racing – Xbox 360

    Sonic & SEGA All-Stars Racing – Xbox 360

    Carnival Games – Nintendo Wii (Renewed)

    Carnival Games – Nintendo Wii (Renewed)

    Transformers Devastation – PlayStation 3

    Transformers Devastation – PlayStation 3

  • Tech Eats
    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Oreo Mug Cake: 2-Minute Cookie & Cake Combo!

    Oreo Mug Cake: 2-Minute Cookie & Cake Combo!

    Tiramisu Mug Cake: Coffee Lover’s Dream in 2 Minutes!

    Tiramisu Mug Cake: Coffee Lover’s Dream in 2 Minutes!

  • Tesla
    Airpod Holder for Tesla MagSafe Wireless Charger- Fits All Airpods and All Model 3, X,…

    Airpod Holder for Tesla MagSafe Wireless Charger- Fits All Airpods and All Model 3, X,…

    Tesla unveils its LFP battery factory, claims it’s almost ready

    Tesla unveils its LFP battery factory, claims it’s almost ready

    Garmin GPS Mount – Ultra-Sticky Dash Holder for Car & Truck Dashboard & Windshield,…

    Garmin GPS Mount – Ultra-Sticky Dash Holder for Car & Truck Dashboard & Windshield,…

    Elon Musk goes from sleeping on Tesla’s factory floor to sleeping in sales office

    Elon Musk goes from sleeping on Tesla’s factory floor to sleeping in sales office

    2 PCS H13/9008 Car LED Light Canbus Error-free Decoder, Plug-and-play Retrofit Radio…

    2 PCS H13/9008 Car LED Light Canbus Error-free Decoder, Plug-and-play Retrofit Radio…

    Tesla fires Musk’s chief of staff who became head of North America and Europe

    Tesla fires Musk’s chief of staff who became head of North America and Europe

    Wireless Charge Mat for 2024 2025 Tesla Cybertruck,Center Console Wireless Charger…

    Wireless Charge Mat for 2024 2025 Tesla Cybertruck,Center Console Wireless Charger…

    Truck Bed Cargo Mesh Net for Tesla Cybertruck 2024,with 6 Carabiners Stretchable Storage…

    Truck Bed Cargo Mesh Net for Tesla Cybertruck 2024,with 6 Carabiners Stretchable Storage…

    Motor Trend Premium FlexTough Deep Dish Rear Rubber Floor Mat Liners, Heavy Duty…

    Motor Trend Premium FlexTough Deep Dish Rear Rubber Floor Mat Liners, Heavy Duty…

  • UFO
    3 Hours of Alien Paradoxes to Fall Asleep to

    3 Hours of Alien Paradoxes to Fall Asleep to

    Funny Bigfoot Sasquatch Alien Spaceship UFO Introvert Bruh T-Shirt

    Funny Bigfoot Sasquatch Alien Spaceship UFO Introvert Bruh T-Shirt

    The Most Terrifying Unsolved UFO Mysteries | Best of Close Encounters

    The Most Terrifying Unsolved UFO Mysteries | Best of Close Encounters

    FINALLY! Biggest ALIEN SEARCH OPERATION's Results are Out | Breakthrough Listen Project Results

    FINALLY! Biggest ALIEN SEARCH OPERATION's Results are Out | Breakthrough Listen Project Results

    CINOTON 160W UFO LED High Bay Light, Aluminum LED Shop Lights with 24000LM, 5000K Commercial Bay Lighting for Warehouse Garage Workshop Factory Hall, 6′ Cable & Safety Rope, ETL Listed 2 Pack

    CINOTON 160W UFO LED High Bay Light, Aluminum LED Shop Lights with 24000LM, 5000K Commercial Bay Lighting for Warehouse Garage Workshop Factory Hall, 6′ Cable & Safety Rope, ETL Listed 2 Pack

    MindBlowing Alien Encounter Giant Mouse Discovered on Mars

    MindBlowing Alien Encounter Giant Mouse Discovered on Mars

    Franco Collectibles Adventure Time Bedding Super Soft Cozy Plush Throw, 46 in x 60 in, (Officially Licensed Product)

    Franco Collectibles Adventure Time Bedding Super Soft Cozy Plush Throw, 46 in x 60 in, (Officially Licensed Product)

    Alien 3's Workprint: What Else Was Cut From the Film?

    Alien 3's Workprint: What Else Was Cut From the Film?

    Simple Area 51 Minimal UFO Tattoo Line Art Graphic Tee UFO T-Shirt

    Simple Area 51 Minimal UFO Tattoo Line Art Graphic Tee UFO T-Shirt

No Result
View All Result
  • TC
  • AI
    Artificial Intelligence

    EgoDex: Learning Dexterous Manipulation from Large-Scale Egocentric Video

    Artificial Intelligence

    Instruction-Following Pruning for Large Language Models

    Artificial Intelligence

    How to Combine Streamlit, Pandas, and Plotly for Interactive Data Apps

    Artificial Intelligence

    Tailor responsible AI with new safeguard tiers in Amazon Bedrock Guardrails

    Artificial Intelligence

    Automate Data Quality Reports with n8n: From CSV to Professional Analysis

    Artificial Intelligence

    NewDay builds A Generative AI based Customer service Agent Assist with over 90% accuracy

    Artificial Intelligence

    5 Things You Need to Know About Agentic AI

    Artificial Intelligence

    Normalizing Flows are Capable Generative Models

    Artificial Intelligence

    Update on the AWS DeepRacer Student Portal

  • App Zone
    Top 3 Launcher Apps for Apple: Features, Pros, and Cons

    Top 3 Launcher Apps for Apple: Features, Pros, and Cons

    Top 3 Launcher Apps for Android: Features, Pros, and Cons

    Top 3 Launcher Apps for Android: Features, Pros, and Cons

    Top 3 Card Game Apps of 2025: Features, Pros, and Cons

    Top 3 Card Game Apps of 2025: Features, Pros, and Cons

    Top 3 Medical Apps of 2025: Features, Pros, and Cons

    Top 3 Medical Apps of 2025: Features, Pros, and Cons

    Top 3 Travel Apps of 2025: Features, Pros, and Cons

    Top 3 Travel Apps of 2025: Features, Pros, and Cons

    Top 3 Casual Game Apps for 2025: Features, Pros, and Cons

    Top 3 Casual Game Apps for 2025: Features, Pros, and Cons

    Top 3 Food Apps for 2025: Features, Pros, and Cons

    Top 3 Food Apps for 2025: Features, Pros, and Cons

    Top 3 Sport Apps for 2025: Features, Pros, and Cons

    Top 3 Sport Apps for 2025: Features, Pros, and Cons

    Top 3 Productivity Apps for 2025: Features, Pros, and Cons

    Top 3 Productivity Apps for 2025: Features, Pros, and Cons

  • Apple
    SwitchBot Hub 3 gains ‘Works with Apple Home’ certification

    SwitchBot Hub 3 gains ‘Works with Apple Home’ certification

    July 1, 2025 – Apple AI rumors, 10 years of Apple Music

    Will the iPhone 17 lineup really have higher refresh rate displays?

    The biggest iPhone 17 mystery left could swing a lot of upgrade decisions

    Apple hit with $110M damages in 3G patents lawsuit

    Apple hit with $110M damages in 3G patents lawsuit

    Photos iOS 26 vs iOS 18: Compared

    Photos iOS 26 vs iOS 18: Compared

    Here’s everything new for Apple Photos in iOS 26

    Here’s everything new for Apple Photos in iOS 26

    Apple gains ground with new Macs despite market challenges

    Apple gains ground with new Macs despite market challenges

    Anker Power Bank, Zolo, MagGo, recall

    Anker Power Bank, Zolo, MagGo, recall

    Developer for Linux on Apple Silicon Macs resigns, citing ‘major failure of leadership’

    New ‘MacBook’ rumor sounds like Apple’s taking the iPad approach

  • Retro Rewind
    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 57 April 1994

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: Computer Gaming World Magazine Issue 73 December 1998

    Retro Rewind: Computer Gaming World Magazine Issue 73 December 1998

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

  • Tech Deals
    Skytech King 95 Gaming PC Desktop, Intel i7 14700F 2.1 GHz (5.3GHz Turbo), NVIDIA RTX…

    Skytech King 95 Gaming PC Desktop, Intel i7 14700F 2.1 GHz (5.3GHz Turbo), NVIDIA RTX…

    ASRock – B550M PRO SE – ASRock B550M Pro SE Gaming Desktop Motherboard – AMD PRO565…

    ASRock – B550M PRO SE – ASRock B550M Pro SE Gaming Desktop Motherboard – AMD PRO565…

    Soundcore A30i by Anker, Smart Noise Cancelling Earbuds, Lipstick-Shaped Stylish Design,…

    Soundcore A30i by Anker, Smart Noise Cancelling Earbuds, Lipstick-Shaped Stylish Design,…

    ADATA Premier 256GB MicroSDHC/SDXC UHS-I Class 10 V10 A1 Memory Card with Adapter Read…

    ADATA Premier 256GB MicroSDHC/SDXC UHS-I Class 10 V10 A1 Memory Card with Adapter Read…

    acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable DPI Office Cordless…

    acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable DPI Office Cordless…

    STGAubron Gaming PC Computer Desktop, GeForce GTX 1660 Ti 6G, Intel Core I7 up to 3.9…

    STGAubron Gaming PC Computer Desktop, GeForce GTX 1660 Ti 6G, Intel Core I7 up to 3.9…

    Sonic & SEGA All-Stars Racing – Xbox 360

    Sonic & SEGA All-Stars Racing – Xbox 360

    Carnival Games – Nintendo Wii (Renewed)

    Carnival Games – Nintendo Wii (Renewed)

    Transformers Devastation – PlayStation 3

    Transformers Devastation – PlayStation 3

  • Tech Eats
    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Oreo Mug Cake: 2-Minute Cookie & Cake Combo!

    Oreo Mug Cake: 2-Minute Cookie & Cake Combo!

    Tiramisu Mug Cake: Coffee Lover’s Dream in 2 Minutes!

    Tiramisu Mug Cake: Coffee Lover’s Dream in 2 Minutes!

  • Tesla
    Airpod Holder for Tesla MagSafe Wireless Charger- Fits All Airpods and All Model 3, X,…

    Airpod Holder for Tesla MagSafe Wireless Charger- Fits All Airpods and All Model 3, X,…

    Tesla unveils its LFP battery factory, claims it’s almost ready

    Tesla unveils its LFP battery factory, claims it’s almost ready

    Garmin GPS Mount – Ultra-Sticky Dash Holder for Car & Truck Dashboard & Windshield,…

    Garmin GPS Mount – Ultra-Sticky Dash Holder for Car & Truck Dashboard & Windshield,…

    Elon Musk goes from sleeping on Tesla’s factory floor to sleeping in sales office

    Elon Musk goes from sleeping on Tesla’s factory floor to sleeping in sales office

    2 PCS H13/9008 Car LED Light Canbus Error-free Decoder, Plug-and-play Retrofit Radio…

    2 PCS H13/9008 Car LED Light Canbus Error-free Decoder, Plug-and-play Retrofit Radio…

    Tesla fires Musk’s chief of staff who became head of North America and Europe

    Tesla fires Musk’s chief of staff who became head of North America and Europe

    Wireless Charge Mat for 2024 2025 Tesla Cybertruck,Center Console Wireless Charger…

    Wireless Charge Mat for 2024 2025 Tesla Cybertruck,Center Console Wireless Charger…

    Truck Bed Cargo Mesh Net for Tesla Cybertruck 2024,with 6 Carabiners Stretchable Storage…

    Truck Bed Cargo Mesh Net for Tesla Cybertruck 2024,with 6 Carabiners Stretchable Storage…

    Motor Trend Premium FlexTough Deep Dish Rear Rubber Floor Mat Liners, Heavy Duty…

    Motor Trend Premium FlexTough Deep Dish Rear Rubber Floor Mat Liners, Heavy Duty…

  • UFO
    3 Hours of Alien Paradoxes to Fall Asleep to

    3 Hours of Alien Paradoxes to Fall Asleep to

    Funny Bigfoot Sasquatch Alien Spaceship UFO Introvert Bruh T-Shirt

    Funny Bigfoot Sasquatch Alien Spaceship UFO Introvert Bruh T-Shirt

    The Most Terrifying Unsolved UFO Mysteries | Best of Close Encounters

    The Most Terrifying Unsolved UFO Mysteries | Best of Close Encounters

    FINALLY! Biggest ALIEN SEARCH OPERATION's Results are Out | Breakthrough Listen Project Results

    FINALLY! Biggest ALIEN SEARCH OPERATION's Results are Out | Breakthrough Listen Project Results

    CINOTON 160W UFO LED High Bay Light, Aluminum LED Shop Lights with 24000LM, 5000K Commercial Bay Lighting for Warehouse Garage Workshop Factory Hall, 6′ Cable & Safety Rope, ETL Listed 2 Pack

    CINOTON 160W UFO LED High Bay Light, Aluminum LED Shop Lights with 24000LM, 5000K Commercial Bay Lighting for Warehouse Garage Workshop Factory Hall, 6′ Cable & Safety Rope, ETL Listed 2 Pack

    MindBlowing Alien Encounter Giant Mouse Discovered on Mars

    MindBlowing Alien Encounter Giant Mouse Discovered on Mars

    Franco Collectibles Adventure Time Bedding Super Soft Cozy Plush Throw, 46 in x 60 in, (Officially Licensed Product)

    Franco Collectibles Adventure Time Bedding Super Soft Cozy Plush Throw, 46 in x 60 in, (Officially Licensed Product)

    Alien 3's Workprint: What Else Was Cut From the Film?

    Alien 3's Workprint: What Else Was Cut From the Film?

    Simple Area 51 Minimal UFO Tattoo Line Art Graphic Tee UFO T-Shirt

    Simple Area 51 Minimal UFO Tattoo Line Art Graphic Tee UFO T-Shirt

No Result
View All Result
Techcratic
No Result
View All Result
Home AI

Gemini RAG Recipe with Query Enhancement

AI by AI
April 8, 2025
in AI
Reading Time: 11 mins read
123
A A
0

Cornellius Yudha Wijaya
2025-04-08 12:00:00
www.kdnuggets.com

Gemini RAG Recipe with Query Enhancement
Image by Editor | Midjourney & Canva

 

Introduction

 
Generative AI is everywhere; however, a common criticism is that LLMs sometimes fail to accurately respond to user inputs, a phenomenon known as hallucination. This is where Retrieval augmented generation (RAG) can be helpful.

RAG has become the universally go-to technique for improving LLM model outputs. It enhances output by integrating external knowledge that the model might not have in its training data. RAG is handy in use cases requiring specific domain knowledge and data privacy.

To learn more about RAG, let’s implement a RAG recipe, one that you can implement on your local computer. During this exercise, you will learn how to implement RAG systems in a way you can later adapt and use in your own projects and even in production.

 

Our RAG Recipe

 
There are many ways to implement a RAG system; from scratch vs. with a framework; local vs. hosted LLM; hosted vector database vs. local implementation. You can use any of the common RAG approaches that suit your needs, so long as is the result is stable, sufficiently accurate, and does not cause high technical debts.

For our implementation, we will use a standard RAG setup with query enhancement in order to improve results. We will implement our system using a local vector database along with a hosted language model. Our recipe can be seen in the image below.

 
Gemini RAG Recipe with Query Enhancement
 

We will use the contents of a PDF file as our knowledge base, and store it in the ChromaDB vector database. For embedding and generative AI, we will use the Gemini family products; for that reason, you should get a Google API key. Additionally, we will use query rewriting and hypothetical document embedding to improve our generated results.

Query rewriting is a technique for improving the query passed for retrieval by making it more specific and detailed. Using an LLM, we pass the query and reformulate it into a better one.

Hypothetical document embedding (HyDE), on the other hand, is a technique for improving queries by transforming them into hypothetical documents containing potential answers. It’s intended to bridge the semantic gap between queries and documents in vector space by enhancing the query into hypothetical documents using an LLM, which we use for document retrieval. For simplicity, we will also use Jupyter Notebook instead of a classic IDE, but feel free to follow along as you see fit.

 

Cooking Up the Recipe

 
Let’s set up everything you need to implement our RAG recipe.

Let’s first set up a virtual environment:

python -m venv your-virtual-env-name

 

Activate the virtual environment by using the .\Scripts\activate command. Then, install all the packages required for our implementation to work correctly:

pip install PyPDF2 langchain google-generativeai chromadb

 

In your local directory, create a Python file called main.py and download the PDF we will use as a knowledge database. I will use this insurance handbook, but you can try another PDF file if you like.

With everything in place, we will start preparing the code for setting up the RAG system with query enhancement. We will import all the packages we use and set up the logger to log all our processes.

import PyPDF2
from langchain.text_splitter import RecursiveCharacterTextSplitter
import google.generativeai as genai
import chromadb
import logging

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)

 

Then, we will prepare all the functions used in our RAG system. For starters, we prepare a function to extract all the text from our PDF file:

def extract_text_from_pdf(pdf_path):
    logger.info(f"Extracting text from PDF: {pdf_path}")
    with open(pdf_path, "rb") as file:
        reader = PyPDF2.PdfReader(file)
        text = ""
        for page in reader.pages:
            text += page.extract_text()
    logger.info("Text extraction complete.")
    return text

 

Passing the whole raw PDF file text into the generative AI will diminish the values of using the RAG. Instead, we want the most relevant result to pass into the LLM, which is located in the documents. For that reason, we will split our raw text data into chunks using the following function:

def chunk_text(text):
    logger.info("Splitting text into chunks...")
    text_splitter = RecursiveCharacterTextSplitter(
        chunk_size=500,  
        chunk_overlap=50,  
        separators=["\n\n", "\n", " ", ""] 
    )
    chunks = text_splitter.split_text(text)
    logger.info(f"Text split into {len(chunks)} chunks.")
    return chunks

 

We have set it as 500 tokens per document with 50 tokens overlap, but you can change it with experimentation. There are no exact parameters for splitting the documents, so you will only know which parameters are the best by experimentation.

With the documents ready, we will process them into embeddings using Gemini:

genai.configure(api_key="YOUR-API-KEY") 

def generate_embeddings(texts):
    logger.info("Generating embeddings for text chunks...")
    embeddings = []
    for i, text in enumerate(texts):
        logger.info(f"Generating embedding for chunk {i + 1}/{len(texts)}...")
        result = genai.embed_content(
            model="models/text-embedding-004",
            content=text
        )
        embeddings.append(result['embedding'])
    logger.info("Embeddings generated.")
    return embeddings

 

All the chunk embeddings need to be stored somewhere. We will use ChromaDB as our vector database. If we are using ChromaDB, the data will be stored locally within our directory by default.

To set this up, we will set the function to store both the chunk documents and the embeddings.

def store_embeddings_in_chromadb(chunks, chunk_embeddings):
    logger.info("Storing embeddings in ChromaDB...")
    client = chromadb.Client()

    # Change the collection name to your preferred name
    collection = client.get_or_create_collection(name="insurance_chunks")

    ids = [f"chunk_{i}" for i in range(len(chunks))]
    metadatas = [{"source": "pdf"}] * len(chunks)  # Add metadata if needed
    collection.add(
        documents=chunks, 
        embeddings=chunk_embeddings, 
        metadatas=metadatas, 
        ids=ids #Unique ID for each documents
    )
    logger.info("Embeddings stored in ChromaDB.")
    return collection

 

We will prepare the RAG system using the documents stored in the vector database, starting with the query rewriting function.

def rewrite_query(original_query):
    logger.info("Rewriting query...")
    
    query_rewrite_template = """You are an AI assistant tasked with reformulating user queries to improve retrieval in a RAG system.
    Given the original query, rewrite it to be more specific, detailed, and likely to retrieve relevant information.
    Original query: {original_query}
    Rewritten query:"""

    # Use Gemini to rewrite the query
    model = genai.GenerativeModel("gemini-1.5-flash")

    # Generate and return our response
    response = model.generate_content(query_rewrite_template.format(original_query=original_query))
    logger.info("Query rewritten.")
    return response.text

 

In the code above, we prepare a prompt template in which the model acts as an AI assistant that reformulates user queries.

Next, we will prepare the HyDE class that is able to generate the hypothetical documents and retrieve similar documents from our vector database.

class HyDERetriever:
    def __init__(self, collection, chunk_size=500):
        self.collection = collection
        self.chunk_size = chunk_size

    def generate_hypothetical_document(self, query):
        logger.info("Generating hypothetical document...")

        hyde_prompt = """Given the question '{query}', generate a hypothetical document that directly answers this question. The document should be detailed and in-depth.
        The document size should be approximately {chunk_size} characters."""

        model = genai.GenerativeModel("gemini-1.5-flash")
        response = model.generate_content(hyde_prompt.format(query=query, chunk_size=self.chunk_size))
        logger.info("Hypothetical document generated.")
        return response.text

    def retrieve(self, query, k=3):
        logger.info("Retrieving relevant documents using HyDE...")
        hypothetical_doc = self.generate_hypothetical_document(query)
        hypothetical_embedding = generate_embeddings([hypothetical_doc])[0]
        results = self.collection.query(
            query_embeddings=[hypothetical_embedding],
            n_results=k
        )
        similar_docs = results["documents"][0] 
        logger.info(f"Retrieved {len(similar_docs)} relevant documents.")
        return similar_docs, hypothetical_doc

 

Using both query rewriting and HyDE, we should be able to improve our RAG results. It’s easy to setup, but you need to ensure the query result is still able to follow the original query intention.

Lastly, we will set the generation functions from our query:

def generate_response(query, context):
    logger.info("Generating response...")
    prompt = f"Context: {context}\n\nQuestion: {query}\n\nAnswer:"
    model = genai.GenerativeModel("gemini-1.5-flash")
    response = model.generate_content(prompt)
    logger.info("Response generated.")
    return response.text

 

Taking It Out of the Oven

 
With everything in place, we set up the RAG system to run with the following code:

if __name__ == "__main__":
    try:
        # Step 1: Extract and chunk text
        pdf_path = "Insurance_Handbook_20103.pdf"
        logger.info(f"Starting process for PDF: {pdf_path}")
        text = extract_text_from_pdf(pdf_path)
        chunks = chunk_text(text)

        # Step 2: Generate embeddings
        chunk_embeddings = generate_embeddings(chunks)

        # Step 3: Store embeddings in ChromaDB
        collection = store_embeddings_in_chromadb(chunks, chunk_embeddings)

        # Step 4: Rewrite the query
        original_query = "What is residual markets in insurance?"
        rewritten_query = rewrite_query(original_query)
        logger.info(f"Rewritten Query: {rewritten_query}")

        # Step 5: Retrieve relevant documents using HyDE
        hyde_retriever = HyDERetriever(collection)
        similar_docs, hypothetical_doc = hyde_retriever.retrieve(rewritten_query)
        logger.info(f"Hypothetical Document: {hypothetical_doc}")
        logger.info(f"Similar Documents: {similar_docs}")

        # Step 6: Generate a response
        context = " ".join(similar_docs)
        response = generate_response(original_query, context)
        logger.info(f"Generated Response: {response}")

    except Exception as e:
        logger.error(f"An error occurred: {e}", exc_info=True)

 

Replace the PDF path and the original query with what you intend to use in our example. Run it by using the following command:

 

The logging process will inform you of all the processes in the RAG system. For example, this is how the rewritten query result is from the simple query “What is residual markets in insurance?”

Rewritten Query: Explain the concept of residual markets in the insurance
industry, including the types of risks typically covered, how they operate, 
and the regulatory frameworks governing their function in the United States 
and/or [Specify a relevant country/region, if known].  Provide examples of 
specific residual market mechanisms, such as state-sponsored insurance pools 
or assigned risk plans.

 

From the rewritten query, it can evolve into hypothetical documents like the one below:

Hypothetical Document: Residual markets in insurance address risks deemed
too hazardous or unprofitable for the private sector.  These markets, often 
government-backed or mandated, provide coverage of last resort.  In the US, 
they include state-sponsored pools (e.g., for high-risk auto insurance) and 
assigned risk plans, where insurers share responsibility for covering 
high-risk individuals. Coverage typically encompasses auto insurance, 
workers' compensation, and occasionally property insurance in high-risk 
areas. Operation involves assessing risk, setting premiums (often higher 
than private market rates), and distributing costs among participating 
insurers. State regulations govern participation, rate setting, and solvency.
Strict oversight aims to prevent market distortions while ensuring access to 
essential insurance.  The system balances the need for widespread coverage 
with the avoidance of excessive burdens on insurers and taxpayers

 

Using the hypothetical document above, our system will find the most related documents from our vector database and pass them into our LLM. The result that was generated to answer our questions is shown below.

Generated Response: In insurance, residual markets refer to the business that
insurers do not voluntarily assume.  This is because the risks involved are 
considered high, and insurers would typically avoid them in a competitive market.
These markets are also sometimes called "shared" markets because profits and 
losses are shared among all insurers in a state offering that type of insurance, 
or "involuntary" markets because participation isn't a choice for insurers.
Residual market programs often require some form of government intervention 
or support because they are rarely self-sufficient.

 

That’s all for this Gemini RAG recipe, from which you can easily adapt and develop your own system with additional query enhancements to improve the results.

 

Wrapping Up

 
RAG is a technique for improving LLM model generated output by integrating external knowledge into the LLM’s existing knowledge. RAG is handy in use cases requiring specific domain knowledge and data privacy.

This article taught us how to cook up a RAG implementation recipe using the Gemini language model, ChromaDB vector database, and query enhancement techniques.

I hope this has helped!
 
 

Cornellius Yudha Wijaya is a data science assistant manager and data writer. While working full-time at Allianz Indonesia, he loves to share Python and data tips via social media and writing media. Cornellius writes on a variety of AI and machine learning topics.

Source Link



Shark AI Ultra Voice Control Robot Vacuum

Transform your cleaning routine with the Shark AI Ultra Voice Control Robot Vacuum! This high-tech marvel boasts over 32,487 ratings, an impressive 4.2 out of 5 stars, and has been purchased over 900 times in the past month. Perfect for keeping your home spotless with minimal effort, this vacuum is now available for the unbeatable price of $349.99!

Don’t miss out on this limited-time offer. Order now and let Shark AI do the work for you!


Start your free Amazon Prime trial
today and unlock unlimited streaming and more!

Help Power Techcratic’s Future – Scan To Support

If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.

As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!

BITCOIN

Bitcoin Logo

Bitcoin QR Code

bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge

Scan the QR code with your crypto wallet app

DOGECOIN

Dogecoin Logo

Dogecoin QR Code

D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA

Scan the QR code with your crypto wallet app

ETHEREUM

Ethereum Logo

Ethereum QR Code

0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a

Scan the QR code with your crypto wallet app

Please read the Privacy and Security Disclaimer on how Techcratic handles your support.

Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.

Tags: AI NEWS
Share162Share28ShareShare4ShareTweet102
Previous Post

3D Butterfly Painting with Texture Paste & Crystals on MDF | Sparkling Textured Art

Next Post

Humanoid robots like Digit and Apollo are expanding beyond Amazon warehouses

AI

AI

Explore the dynamic realm of AI, where breakthroughs and trends are shaping the future. Stay informed and see how AI is making an impact. Don’t miss the crucial updates—read the latest articles here at Techcratic.

Related Posts

Artificial Intelligence
AI

EgoDex: Learning Dexterous Manipulation from Large-Scale Egocentric Video

July 1, 2025
1.3k
Artificial Intelligence
AI

Instruction-Following Pruning for Large Language Models

June 30, 2025
1.3k
Artificial Intelligence
AI

How to Combine Streamlit, Pandas, and Plotly for Interactive Data Apps

June 27, 2025
1.3k
Artificial Intelligence
AI

Tailor responsible AI with new safeguard tiers in Amazon Bedrock Guardrails

June 26, 2025
1.3k
Artificial Intelligence
AI

Automate Data Quality Reports with n8n: From CSV to Professional Analysis

June 26, 2025
1.3k
Artificial Intelligence
AI

NewDay builds A Generative AI based Customer service Agent Assist with over 90% accuracy

June 24, 2025
1.3k
Artificial Intelligence
AI

5 Things You Need to Know About Agentic AI

June 23, 2025
1.3k
Artificial Intelligence
AI

Normalizing Flows are Capable Generative Models

June 20, 2025
1.3k
Load More
Next Post
Humanoid robots like Digit and Apollo are expanding beyond Amazon warehouses

Humanoid robots like Digit and Apollo are expanding beyond Amazon warehouses

Leave a Reply Cancel reply

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

Your Tech Resources

  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Forbes
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo
  • Google News
  • Hacker News
  • Harvard Tech
  • I Like Cats ™
  • I Like Dogs ™
  • LifeHacker
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • PC World
  • Photofocus
  • Physics
  • Random Tech
  • Retro Rewind ™
  • Robot Report
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Art
  • Tech Careers
  • Tech Deals
  • Techcratic ™
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Tech News

  • 30 Second Tech ™
  • AI
  • Apple Insider
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo

Tech News

  • Harvard Tech
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • Physics
  • PC World
  • Random Tech
  • Retro Rewind ™
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Careers

Tech News​

  • Tech Art
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Site Links

  • About Techcratic
  • Affiliate Disclaimer
  • Affiliate Link Policy
  • Contact Techcratic
  • Dealors Discount Store
  • Privacy and Security Disclaimer
  • Privacy Policy
  • RSS Feed
  • Site Map
  • Support Techcratic
  • Techcratic
  • Tech Deals
  • TOS
  • 𝕏
Click For A Secret Deal

Techcratic – Your All In One Tech Hub © 2020 – 2025
All Rights Reserved
∞

No Result
View All Result
  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Gaming
  • I Like Cats ™
  • I Like Dogs ™
  • MacRumors
  • Macworld
  • Tech Deals
  • Techcratic ™
  • Techs Got To Eat ™
  • Tesla
  • UFO
  • Wired