AI and Deep Learning Community Question

TITLE: How do I reduce hallucinations in LLMs using Retrieval-Augmented Generation (RAG)?

Posted on 2024-05-14 • In AI and Deep Learning • By David Miller

We are deploying a GPT-based chatbot for our internal documentation, but it keeps generating "hallucinations"—confidently stating facts that don't exist in our manuals. I’ve heard that Retrieval-Augmented Generation (RAG) is the industry standard for fixing this. Can someone explain how to properly set up a vector database and an embedding pipeline to ensure the model only uses our private data?

3 Answers 15,451 Views

All answers to this question 3 Answers

Emily Richardson Answered on 2024-05-16
Answered

To implement RAG effectively, you need to move away from relying solely on the model's weights. First, convert your PDF and markdown files into "chunks" using a library like LangChain. These chunks are then converted into numerical vectors using an embedding model (like OpenAI’s text-embedding-3) and stored in a vector database such as Pinecone or Milvus. When a user asks a question, your system performs a semantic search to find the most relevant chunks and passes them to the LLM as "context." This forces the model to stay "grounded" in your specific documents, which significantly drops the hallucination rate.

Michael Stevens Answered on 2024-05-17
Answered

What strategy are you using for your "chunk size"? If your chunks are too small, the model loses context; if they are too large, you might exceed the token limit or introduce irrelevant noise into the prompt.

David Miller Commented on 2024-05-19
Commented

Michael, I'm currently using a fixed 500-character chunk with a 50-character overlap. After testing, I found that "semantic chunking"—where you break text based on sentence meaning rather than character count—works much better for technical manuals. I’ve also implemented a "re-ranking" step using Cohere to make sure the top 3 results are truly the most relevant before the LLM sees them. This combination has lowered our error rate from roughly 20% down to under 2%.

Sarah Jenkins Answered on 2024-05-20
Answered

You should also check your "temperature" setting. Keeping it near 0.0 or 0.1 for factual tasks ensures the model stays more deterministic and less "creative" with your private data.

Emily Richardson Commented on 2024-05-21
Commented

Sarah is spot on. Lowering the temperature is the quickest win for RAG systems. I usually set mine to 0.0 for any internal knowledge base to ensure the answers remain as literal as possible.

Write a Comment

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

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.