RAG System Design

RAG System Design
unsplash.com

Key Components of RAG System Design

Data Sources

Users often make spelling mistakes or grammatical errors. To improve retrieval accuracy:

Example System Prompt for Query Rewriting

You are a helpful assistant that rewrites user queries to improve retrieval accuracy.
Correct any spelling mistakes, enhance clarity, and add relevant context where necessary.

Examples:
- User Query: "What is the capitel of Frnace?"
  Rewritten Query: "What is the capital of France?"

- User Query: "Tell me abot the histroy of AI."
  Rewritten Query: "Can you provide information about the history of Artificial Intelligence?"

RAG Pipeline Flow

User_Query  Rewriting_Function  Embedding_Model(take chunks) 
Judge_Model(for best chunk)  Rewrite_Query  Retrieval_Model 
RAG_Model  Final Answer

Sub-Query Generation

Sub-queries can be generated from the main query to target specific aspects of the information needed:

Note: Sometimes generating sub-queries may not be necessary, especially if the main query is already clear and specific. Instead, you can focus on enhancing the main query through techniques like query expansion or rephrasing to improve retrieval effectiveness.

HyDe (Hypothetical Document Embeddings)

HyDe is a technique where you generate hypothetical answers to the user's query and then create embeddings for these hypothetical answers:

Benefits:

Want to learn about Generative AI ? Visit Generative AI Resource Hub