Workflows Like Never Before V0.28.0

The latest version of our platform is out now, it’s packed with new features and enhancements designed to boost your Workflows and integrate even more sophisticated AI capabilities into your applications. Here's a look into what's new, how it works, and why it matters for your projects.

RAG Related Features

Revolutionary RAG Components for Flexible Data Handling

Our newest additions, the RagEngine and RagContext, are designed to significantly upgrade how data flows through AI-driven systems. The RagEngine orchestrates the retrieval, processing, and generation stages of data, acting much like the conductor of an orchestra, ensuring each section comes in at the right time for perfect harmony. The RagContext, on the other hand, serves as the container that passes essential data throughout these stages, ensuring nothing gets lost along the way.

Stages of RAG:

  • QueryRagStage: Think of this as the brainstorming phase, where the system expands and interprets user queries to understand and anticipate needs more effectively.
  • RetrievalRagStage: This is the research phase, where the system searches the data to gather the most relevant information.
  • ResponseRagStage: In the final stage, like a presentation, the system polishes and delivers the information in a coherent and contextually appropriate manner.

To explain further about the graphic above, the RAG process begins by querying for specific information, expanding and interpreting user queries to accurately anticipate and understand their needs. It then retrieves the most relevant information from a comprehensive dataset, and finally, modifies and tailors this data to produce a coherent and contextually appropriate response.

Targeted RAG Modules for Precision and Efficiency

To make these stages even more effective, Griptape has introduced specific RAG modules for different tasks:

  • Retrieval Modules like VectorStoreRetrieval and TextLoaderRetrieval handle fetching data from structured databases and real-time feeds, respectively, ensuring that the system always has the latest and most relevant data at its disposal.
  • Response Modules such as PromptResponseRagModule and TextChunksResponseRagModule work on crafting precise and engaging responses based on the data retrieved, ensuring that the output is not only informative but also accurate.

Below is an example of how you can use the new RagEngine with your own data stores. In this code snippet, we are setting up a system to manage and respond to queries using RAG. First we load and store text data from a website into a local vector store using Griptape tools. This allows us to efficiently retrieve information based on user queries. An agent will then be created with tools meant to handle the retrieval of this data and generate responses.

from griptape.tools import RagClient
from griptape.structures import Agent
from griptape.drivers import (
    OpenAiChatPromptDriver,
    LocalVectorStoreDriver,
    OpenAiEmbeddingDriver,
)
from griptape.engines.rag import RagEngine
from griptape.engines.rag.modules import (
    VectorStoreRetrievalRagModule,
    PromptResponseRagModule,
)
from griptape.engines.rag.stages import RetrievalRagStage, ResponseRagStage
from griptape.loaders import WebLoader

from dotenv import load_dotenv

load_dotenv()

namespace = "griptape-rag"
vector_store_driver = LocalVectorStoreDriver(embedding_driver=OpenAiEmbeddingDriver())
artifacts = WebLoader().load(
    "https://www.griptape.ai/blog/understanding-retrieval-augmented-generation"
)
vector_store_driver.upsert_text_artifacts({namespace: artifacts})

agent = Agent(
    tools=[
        RagClient(
            description="Contains information about Griptape's RAG approach. "
            "Use it to answer any physics-related questions.",
            rag_engine=RagEngine(
                retrieval_stage=RetrievalRagStage(
                    retrieval_modules=[
                        VectorStoreRetrievalRagModule(
                            vector_store_driver=vector_store_driver,
                            query_params={"namespace": namespace, "top_n": 20},
                        )
                    ]
                ),
                response_stage=ResponseRagStage(
                    response_module=PromptResponseRagModule(
                        prompt_driver=OpenAiChatPromptDriver(model="gpt-4o")
                    )
                ),
            ),
        )
    ],
)

agent.run("How does Griptape implement RAG?")

Moreover, the LocalVectorStoreDriver.persist_file makes data management easier by allowing you to store and retrieve large datasets efficiently. This feature allows the LocalVectorStoreDriver to persist the vector store to a file, which helps prevent memory overload when working with large datasets, ensuring more efficient data management.

We can modify our RAG code above by passing the path/to/file we want to persist into the LocalVectorStoreDriver.

vector_store_driver = 
LocalVectorStoreDriver(embedding_driver=OpenAiEmbeddingDriver(),
persist_file="test_file.txt")

Enhanced Search and Reranking Capabilities

The new CohereRerankDriver refines how search results are ordered, pushing the most relevant information to the forefront. Imagine searching through a bookshelf where the most useful books always end up at eye level, ready for you to pick up. This is what our reranking driver does for digital content.

Reranking is needed when you have more than one data source and you’d like the AI to intelligently rank the responses it gets during the Retrieval stage of the RagEngine. Let’s update our initial code to show how this can work.

import os
from griptape.tools import RagClient
from griptape.structures import Agent
from griptape.drivers import (
    OpenAiChatPromptDriver,
    LocalVectorStoreDriver,
    OpenAiEmbeddingDriver,
    CohereRerankDriver,
)
from griptape.engines.rag import RagEngine
from griptape.engines.rag.modules import (
    VectorStoreRetrievalRagModule,
    PromptResponseRagModule,
    TextChunksRerankRagModule,
)
from griptape.engines.rag.stages import RetrievalRagStage, ResponseRagStage
from griptape.loaders import WebLoader

from dotenv import load_dotenv

load_dotenv()

vector_store_driver = LocalVectorStoreDriver(
    embedding_driver=OpenAiEmbeddingDriver()
)
griptape_blog_artifacts = WebLoader().load(
    "https://www.griptape.ai/blog/understanding-retrieval-augmented-generation"
)
aws_blog_artifacts = WebLoader().load(
    "https://aws.amazon.com/what-is/retrieval-augmented-generation/"
)
vector_store_driver.upsert_text_artifacts({"griptape-rag": griptape_blog_artifacts})
vector_store_driver.upsert_text_artifacts({"aws-rag": aws_blog_artifacts})

agent = Agent(
    tools=[
        RagClient(
            description="Contains information about Griptape's RAG approach. "
            "Use it to answer any physics-related questions.",
            rag_engine=RagEngine(
                retrieval_stage=RetrievalRagStage(
                    retrieval_modules=[
                        VectorStoreRetrievalRagModule(
                            name="Griptape RAG Blog",
                            vector_store_driver=vector_store_driver,
                            query_params={"namespace": "griptape-rag", "top_n": 5},
                        ),
                        VectorStoreRetrievalRagModule(
                            name="AWS RAG Blog",
                            vector_store_driver=vector_store_driver,
                            query_params={"namespace": "aws-rag", "top_n": 5},
                        ),
                    ],
                    rerank_module=TextChunksRerankRagModule(
                        rerank_driver=CohereRerankDriver(
                            api_key=os.environ["COHERE_API_KEY"], top_n=10
                        )
                    ),
                ),
                response_stage=ResponseRagStage(
                    response_module=PromptResponseRagModule(
                        prompt_driver=OpenAiChatPromptDriver(model="gpt-4o")
                    )
                ),
            ),
        )
    ],
)

agent.run("What is RAG? Tell me which data source you got your answer from.")

Streamlining Operations with Utilities and Web Drivers

With additions like GoogleWebSearchDriver and DuckDuckGoWebSearchDriver, your applications can now leverage the unique capabilities of these search giants directly. Whether it's Google's vast index or DuckDuckGo's privacy-focused results, you can choose the tool that best fits your needs. 

Future-Proofing with API Changes and Enhancements

We've made several API changes, removing outdated features and streamlining existing ones to reduce complexity and escalate performance. For instance, the transition from TextQueryTask to RagTask allows for a smoother integration of retrieval and response functionalities, in turn, making your development process more intuitive.

See the full change list here!

Conclusion

The enhancements and new features introduced are designed to empower developers by simplifying complex processes and providing powerful tools that enable the creation of more responsive and intelligent systems. Explore the capabilities of Griptape’s newest release and discover how they can transform your projects, making them more efficient and impactful. We are excited to see what you build.