Retrieval-Augmented Generation (RAG) is a prompting technique that enhances large language model (LLM) responses by dynamically retrieving relevant information from external knowledge sources before generating a response. Rather than relying solely on the model’s internal knowledge, RAG incorporates up-to-date, specific, and contextually relevant information from external databases, documents, or knowledge bases.
Here’s a simple RAG implementation using Latitude:
RAG Basic Example
Copy
Ask AI
---provider: OpenAImodel: gpt-4otemperature: 0.7tools: - search_knowledge_base: description: Retrieve information from the knowledge base parameters: type: object additionalProperties: false required: ['query'] properties: query: type: string description: The search query to retrieve relevant information---# Knowledge-Enhanced ResponseAnswer the user's question about {{ topic }} by first retrieving relevant information.## User Question:{{ user_question }}## Information Retrieval:I'll search for the most relevant information to answer this question.## Comprehensive Answer:Based on the retrieved information, I'll now provide a complete and accurate answer to the question.
This example shows a more sophisticated RAG implementation that retrieves information from multiple sources and evaluates their relevance:
Copy
Ask AI
---provider: OpenAImodel: gpt-4otemperature: 0.3tools: - search_knowledge_base: description: Retrieve information from the primary knowledge base parameters: type: object additionalProperties: false required: ['query'] properties: query: type: string description: The search query to retrieve relevant information - search_recent_documents: description: Retrieve information from recent documents for time-sensitive information parameters: type: object additionalProperties: false required: ['query'] properties: query: type: string description: The search query to retrieve recent information---<step># Initial Information Gathering## User Question:{{ user_question }}## Primary Knowledge Search:Let me search our main knowledge base for relevant information.## Recent Documents Search:I'll also check recent documents for any updates or new information.</step><step># Information Synthesis## Retrieved Information:Let me analyze and synthesize the information from both sources:1. **Main Knowledge Base Findings:** - Key facts and concepts retrieved - Relevant background information2. **Recent Documents Findings:** - Updates or new information - Changes to previously established information## Information Evaluation:- Relevance score of each retrieved piece- Consistency between sources- Recency and reliability assessment</step><step># Final Response GenerationBased on the synthesized information, I'll now provide a comprehensive answer:## Answer:[Comprehensive answer to the user's question]## Sources:[List of sources used with citations]## Confidence Level:[Assessment of confidence based on quality and consistency of retrieved information]</step>
This example shows how to implement RAG for a specific domain (medical information):
Copy
Ask AI
---provider: OpenAImodel: gpt-4otemperature: 0.2tools: - search_medical_database: description: Retrieve information from verified medical databases parameters: type: object additionalProperties: false required: ['query', 'search_depth'] properties: query: type: string description: The medical search query search_depth: type: string enum: ['basic', 'detailed', 'comprehensive'] description: The depth of search to perform---# Medical Information AssistantI'll answer your medical question by retrieving information from verified medical databases.## Medical Question:{{ medical_question }}## Information Retrieval:Searching medical databases for clinically validated information...## Medical Answer:Based on information from verified medical sources:[Detailed answer with medical references]## Important Notice:This information is for educational purposes only and not a substitute for professional medical advice. Always consult a healthcare provider for medical concerns.
Implement multi-hop retrieval for complex questions:
Recursive RAG
Copy
Ask AI
---provider: OpenAImodel: gpt-4otemperature: 0.5tools: - search_knowledge_base: description: Retrieve information from the knowledge base parameters: type: object additionalProperties: false required: ['query'] properties: query: type: string description: The search query---<step># Question Decomposition## Original Question:{{ complex_question }}## Sub-questions:Let me break this down into smaller, answerable sub-questions:1. [First sub-question]2. [Second sub-question]3. [Third sub-question]</step><step># Progressive RetrievalI'll search for information to answer each sub-question:## First Sub-question Search:[Search and retrieve information]## Second Sub-question Search:[Search and retrieve information]## Third Sub-question Search:[Search and retrieve information]</step><step># Integrated ResponseBased on all the information retrieved for each sub-question:## Comprehensive Answer:[Integrated answer that addresses the original complex question]</step>