Flo-AI RAGs
A composable RAG
FloAI has introduced a composable Retrieval-Augmented Generation (RAG) system, designed to easily integrate with agentic workflows or be used independently. The RAG system allows agents to intelligently retrieve relevant information from a vector store and use that information to generate responses or perform tasks.
Plugging RAG in Agentic Flows
RAG in FloAI can be part of larger agentic workflows, enabling seamless retrieval and generation capabilities within complex systems. By embedding RAG into agent-driven architectures, you can create Agentic RAGs, allowing for more dynamic and knowledge-driven workflows.
from flo import FloSession, FloRagBuilder, FloCompressionPipeline
from langchain.chat_models import ChatOpenAI
# Initialize the session with an LLM
llm = ChatOpenAI(temperature=0, model_name='gpt-4')
session = FloSession(llm)
# Set up the RAG Builder and store in the vector store (can be any like Chroma, Pinecone, etc.)
rag_builder = FloRagBuilder(session, store.as_retriever())
# Create a compression pipeline for better results (reduces redundancy, enhances relevance)
compression_pipeline = FloCompressionPipeline(OpenAIEmbeddings(model="<embeddings model>"))
compression_pipeline.add_embedding_redundant_filter()
compression_pipeline.add_embedding_relevant_filter()
# Build the RAG
rag = rag_builder \
.with_prompt(custom_prompt) \
.with_multi_query() \
.with_compression(compression_pipeline) \
.build_rag()
# Invoke the RAG
response = rag.invoke({ "question": "What are the documents applying for housing loan" })
print(response)
# You can also pass chat history
response_with_history = rag.invoke({ "question": "What are the documents applying for housing loan", "chat_history": [] })
print(response_with_history)
In this example:
FloRagBuilder helps build the RAG system.
FloCompressionPipeline allows the integration of components like re-rankers and duplicate removers for higher-quality results.
The RAG is built with a custom prompt and multi-query to retrieve semantically similar documents.
Agentic RAG Tools
FloAI allows you to convert the RAG system into a reusable tool. You can easily create a RAG Tool, which can then be used in agentic flows.
rag_tool = rag_builder \
.with_multi_query() \
.build_rag_tool(name="RAGTool", description="RAG to answer questions by looking at the database")
Once the RAG tool is built, it can be registered in a session and used within any agent workflow.
Using RAG in Agentic Flow
After creating and registering the RAG tool, you can use it in a YAML configuration for an agentic workflow. Here’s an example where a team of agents handles various tasks like sending emails, fetching transactions, and answering questions about housing loans using a RAG Tool.
apiVersion: flo/alpha-v1
kind: FloRoutedTeam
name: support-email-handler
team:
name: SupportTicketHandler
router:
name: SupportSupervisor
kind: supervisor
agents:
- name: EmailSender
role: Email Sender
job: You are capable of sending the reply email but constructing an apt response
tools:
- name: SendEmailTool
- name: TransactionFetcher
role: Transaction Fetcher
job: You are capable of fetching any kind of transactions from the database given transaction reference id
tools:
- name: FetchTransactionTool
- name: HousingLoanTeamLead
role: Housing Loan Specialist
job: Fetch the housing loan information from the db and answer the question
tools:
- name: HousingLoanTool
In this example:
Agents are responsible for different tasks, such as sending emails, fetching transactions, or answering housing loan-related queries.
The HousingLoanTool is registered in the session as an RAG-based tool, fetching relevant documents for answering housing loan questions.
By building a composable RAG system and making it easy to plug into agentic flows, FloAI enables the creation of powerful, knowledge-driven workflows. Whether used independently or as part of a broader agentic system, RAG helps retrieve, filter, and generate responses from relevant data sources, enhancing both accuracy and efficiency.
Last updated
Was this helpful?