Essential cookies

Cookies that are required to enable basic website functionality.

Marketing cookies

Cookies used to deliver advertising that is more relevant to you.

Personalization cookies

Cookies that allow the website to remember choice you make (e.g. user name, location) and provide more enhanced, personalized features.

Analytics cookies

Cookies to help us understand how the website performs, how visitors interact with the site, and any technical issues.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Sep 13
#
Education

TheorIQ: An Introduction to Retrieval Augmented Generation (RAG) for AI Agents

AI is powerful when you know how to harness it! Join our “TheorIQ” series as we simplify complex AI ideas into ‘natural language’. We’ll break down key concepts and share practical examples to help you understand and apply AI effectively.

In 2020, Patrick Lewis introduced the term Retrieval Augmented Generation (RAG) in a groundbreaking paper, positioning it as a key method for improving the accuracy and reliability of generative AI models. The method has gained widespread acceptance, and more recently, he has apologized for the unappealing acronym.

As AI Agents continue to evolve and integrate multiple generative models, understanding concepts like RAG is crucial for AI enthusiasts and our community. This knowledge will serve as the foundation for creating dynamic AI Agents and Agent Collectives on the Theoriq protocol.

What is RAG?

RAG, or Retrieval Augmented Generation, is a technique that enhances AI’s ability to provide accurate, up-to-date responses. Imagine if every time you asked AI a question, it could quickly access the latest information from the Internet or a large database. That’s what RAG does. It helps Large Language Models (LLMs) to use up-to-date facts instead of solely relying on their pre-training data.

What is Pre-Training Data?

Before we dive deeper into RAG, it’s important to understand pre-training data and how LLMs work. LLMs are trained on vast amounts of text data to perform basic language tasks and follow instructions, building an understanding of language and general knowledge up to a certain point in time. This pre-training allows LLMs to generate human-like text.

However, pre-trained, out of the box LLMs have limitations:

  • Static Information: Their information is frozen, only knowing data at the time of the LLMs training.
  • Biased and Inaccurate: The model may reproduce biases or errors present in their training, which doesn’t reflect real world use cases or historical facts.
  • No Real-Time Information: They can’t access current events or newly published data.

This is why current AI chatbots, like ChatGPT, are not search engines. While they can generate creative responses, under the hood they essentially predict the next word and may struggle with real-time facts and real-world scenarios.

How RAG Enhances AI Agents

Imagine asking an AI Agent, "What should I wear today?" Without RAG, it might give a generic answer like, “how about something comfortable, like jeans and a t-shirt?”. But with RAG, the same AI interaction can be programmed to have the persona of a ‘Stylist’ that can check the latest weather report, consider the occasion you’re dressing for, and analyze the latest styling trends – it would then suggest something that is tailored to your needs.

Once we add programming to our interactions with AI, like adding a Stylist persona, we call these tools ‘Agents’. At Theoriq, we define AI Agents as follows:

AI agents are autonomous software systems that leverage modern generative AI models to plan, access data, use tools, make decisions, and interact with the real world to perform specific functions.” Theoriq Team. (2024). Theoriq: The AI Agent Base Layer.

The typical workflow for RAG involves chunking documents into smaller pieces, computing embeddings for each chunk, and storing them in a vector database. When a question is asked,  the system retrieves the most relevant chunks using a similarity metric, which helps the LLM generate a more accurate and contextually relevant response (that's where Retrieval Augmented Generation comes from - you retrieverelevant info and generate a response with the augmented context). This process might also include intermediate steps like re-ranking or filtering the retrieved information.

New Words Alert 🚨

  • Chunking: Breaking down large documents into smaller, manageable pieces of text.
  • Embeddings: Numerical representation of text that captures semantic meaning.
  • Vector Database: A specialized database optimized for storing and retrieving embeddings.

A RAG Workflow Involves Several Key Steps:

  • Large documents are split into smaller, manageable text chunks.
  • Each chunk is converted into an embedding–a numerical representation that captures its meaning, allowing for quick comparisons between texts.
  • These embeddings are stored in a special database that's optimized for finding similar information.
  • When a question is asked, the system compares it to stored embeddings and retrieves the most relevant chunks.
  • The AI Agent uses the retrieved information along with the question to generate an informed response.

A key aspect of building robust RAG applications is setting up the right data sources. These sources can range from Internet searches, documents from private databases, or publicly available domain-specific data. It's essential to review the retrieved content to ensure relevance–after all, "garbage in, garbage out"!

Why Use RAG?

  • Better Answers, Fewer Mistakes: RAG helps AI Agents provide more accurate, grounded, and up-to-date responses, reducing hallucinations by ensuring the information provided is relevant to the question.
  • Leveraging Private or Domain Specific Data: For example, a Web3 News Agent without access to fresh data could provide inaccurate answers. RAG pulls the latest information to avoid this.
  • Cost and Time Efficiency: Feeding all possible context as an LLM input is either impossible or costly (for example, filling up Gemini 1.5 Pro context window of 1 million tokens will cost you at least $7 per request!). RAG retrieves only the most relevant information, improving both accuracy and performance, as well as reducing costs and latency.
  • Enhanced User Experience: Users get richer, more precise answers that directly address their queries and intent.

Like Humans, AI Agents Need Context

RAG is about offering the most relevant context to help AI Agents answer questions accurately. RAG is also a way to record Agent interactions and experiences into context for future conversations. By saving and organizing these experiences into a "personal diary," which the Agent continually updates, RAG provides the most relevant experiences for the current situation, enabling long-term memory. This way, the Agent can learn from past mistakes and avoid repeating them.

RAG is used to include a specific context for an Agent, rather than relying on general knowledge.
RAG is used to include a specific context for an Agent, rather than relying on general knowledge.

At Theoriq, we’re advancing AI Agents by investigating the use of RAG into our decentralized Agent Collectives, where multiple agents collaborate on complex tasks. RAG could enable these agents to access shared experiences, making collective decision-making more efficient and intelligent. By pooling knowledge and context across multiple agents, Theoriq's ecosystem not only improves individual agent performance but also promotes a dynamic collaboration between agents. This approach accelerates the development of powerful, decentralized AI solutions that leverage the collective power of multiple agents, driving progress in both AI and Web3 applications.

RAG (Retrieval Augmented Generation) significantly enhances AI agents by providing up-to-date, accurate, and contextually relevant information. By breaking down documents into smaller chunks, creating embeddings, and utilizing vector databases, RAG enables AI to generate well-informed and precise responses. This technique not only reduces errors, but also lowers costs, and improves the user experience by leveraging specific and current data sources. RAG is the open-book test that AI always aces.

The team at Theoriq is constantly exploring the latest advancements in AI and Web3, striving to integrate them into the protocol. Through this approach, we are building an innovative, open, decentralized ecosystem where the benefits are shared equally by all.

About Theoriq

Theoriq is committed to building a responsible, inclusive, and consensus-driven AI landscape in Web3. At the forefront of integrating AI with blockchain technology, Theoriq empowers the community to leverage cutting-edge AI Agent collectives to improve decision-making, automation, and user experiences across Web3.

Theoriq is a decentralized protocol for governing multi-agent systems built by integrating AI with blockchain technology. The platform supports a flexible and modular base layer that powers an ecosystem of dynamic AI Agent collectives that are interoperable, composable and decentralized.

By harnessing the decentralized nature of web3, Theoriq is unlocking the potential of collective AI by empowering communities, developers, researchers, and AI enthusiasts to actively shape the future of decentralized AI.

Theoriq has raised over $10.4M and is backed by Hack VC, Foresight Ventures, Inception Capital, HTX Ventures and more, and have joined start-up programs with Google Cloud and NVIDIA.