How to integrate rag with livekit agents
# ask-ai
b
How to integrate rag with livekit agents
t
Thanks for reaching out, Pranav. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you're looking to integrate Retrieval-Augmented Generation (RAG) with LiveKit agents, there are a few ways to go about it depending on what fits your setup best: • Using the
on_user_turn_completed
Node:
This one’s great for STT-LLM-TTS pipelines since it adds RAG context right before the LLM crafts a response. • Pre-Built RAG Handler: You can use the
RAGHandler
class to plug RAG in through a function tool, which makes automatic lookups a breeze when needed. • Manual Context Injection: If you want more control, you can manually add the retrieved context into the LLM prompt using tools like LlamaIndex. Also, here are some real-world examples to give you an idea: • LiveKit Documentation Assistant: A voice agent powered by RAG that answers questions using the scraped LiveKit docs. • Handling RAG Delays: Tips on keeping users engaged during lookups, like using dynamic messages or audio cues. If you'd like, I’m happy to walk you through detailed steps or chat about specific use cases. Just let me know! Sources: rag/rag_db_builder.py | delay-handling/README.mdoc | External data and RAG | LiveKit Docs | examples/voice_agents/llamaindex-rag/chat_engine.py
b
Im trying to use an agent with Openai realtime
how can we do then?
t
Hey there! If you’re looking to integrate LiveKit agents with OpenAI’s real-time features, here’s a friendly step-by-step guide to get you started: • Install the OpenAI Plugin: Just run
pip install "livekit-agents[openai]~=1.2"
to grab the plugin you need. • Authenticate: Make sure to set your OpenAI API key in the
OPENAI_API_KEY
environment variable or pass it along when you initialize. • Initialize the Realtime Model: Use the
RealtimeModel
class to set things up like which model to use, the voice, and how turns are detected. Here’s a quick example:
Copy code
from livekit.plugins import openai

session = AgentSession(
    llm=openai.realtime.RealtimeModel(
        model="gpt-4o-realtime-preview",
        voice="alloy",
        temperature=0.8,
        turn_detection=openai.realtime.TurnDetection(type="server_vad"),
        input_audio_transcription=openai.realtime.InputAudioTranscription(model="gpt-4o-mini-transcribe"),
    ),
)
• Configure Turn Detection: You can choose between server-side VAD or semantic VAD to make conversations flow naturally. • Optional: Feel free to use separate TTS plugins or load conversation history if you want multi-turn chats. If you want a full example, check out the
MultimodalAgent
class—it’s great for handling multimodal interactions. And hey, if you have any questions or want help with specific setups, just let me know. I’m here to help! Sources: OpenAI Realtime API integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py | OpenAI Realtime API and LiveKit | LiveKit Docs | plugins/openai/src/realtime/realtime_model.ts | OpenAI integration guide | LiveKit Docs
b
OpenAIrealtime + chromadb along with livekit agents
t
Great news! Integrating OpenAI Realtime with LiveKit agents works really well and supports smooth, low-latency, multimodal interactions. You can easily set this up using the OpenAI plugin for LiveKit Agents. Here’s a quick example:
Copy code
from livekit.plugins import openai
session = AgentSession(
    llm=openai.realtime.RealtimeModel(),
)
That said, the available info doesn’t dive into the specifics of combining ChromaDB with OpenAI Realtime and LiveKit agents. If you’re thinking about using ChromaDB for storing or retrieving data alongside these tools, could you share a bit more about what you have in mind? For instance, are you aiming to use ChromaDB for RAG (Retrieval-Augmented Generation) workflows or something else? Knowing this will help me give you advice that’s spot-on for your needs. Sources: OpenAI Realtime API integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/__init__.py | OpenAI and LiveKit | LiveKit Docs
b
I have a code where it uses chromadb retrieval with a method search , and I have a business database. I want to integrate this rag into my agent where I can send the prompt basing on the user message.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!