is it possible to implement RAG through real-time ...
# ask-ai
r
is it possible to implement RAG through real-time pipeline?
t
Thanks for reaching out, Chandan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether Retrieval-Augmented Generation (RAG) can be implemented in a real-time pipeline — yes, it can. You can perform RAG in the agent pipeline by running a retrieval step after the user's turn completes and injecting the retrieved context into the chat context before the LLM generates a response. Use the
on_user_turn_completed
lifecycle node to fetch relevant documents (search/vector DB lookup) from the final transcript, then add that content to
turn_ctx
so the model sees it for generation. Example pattern: 1. Detect end of user turn with
on_user_turn_completed
. 2. Call your retrieval function (vector search, DB query) using
new_message.text_content()
. 3. Add retrieved text to the turn context:
Copy code
turn_ctx.add_message(
  role="assistant",
  content=f"Retrieved context: {rag_content}"
)
1. Let the pipeline continue to the LLM generation step. Notes: • This supports low-latency real-time RAG when turn detection happens in the agent (not inside the model). • It works with STT → LLM → TTS pipelines by acting on the final transcript before generation. Would you like a concrete example integrating a specific vector store or guidance on turn-detection settings? Sources: Pipeline nodes and hooks | LiveKit docs | External data and RAG | LiveKit Docs