prehistoric-printer-73777
08/27/2025, 9:01 AMtall-airline-16756
08/27/2025, 9:02 AMtall-airline-16756
08/27/2025, 9:03 AMclass RAGEnrichedAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a helpful assistant.")
self._index_path = "path_to_index"
self._data_path = "path_to_data"
self._embeddings_model = "text-embedding-3-small"
self._annoy_index = AnnoyIndex.load(self._index_path)
with open(self._data_path, "rb") as f:
self._paragraphs_by_uuid = pickle.load(f)
async def search(self, query):
query_embedding = await openai.create_embeddings(input=[query], model=self._embeddings_model)
results = self._annoy_index.query(query_embedding[0].embedding, n=5)
context = [self._paragraphs_by_uuid.get(r.userdata, "") for r in results]
return "\n".join(context)
What this does is pull in relevant info from a pre-built knowledge base using embeddings and vector search, then feeds that context into the LLM prompt to help generate a great response.
About Latency:
• The main factors that add to latency are embedding generation, vector search, and adding context into the LLM prompt.
• To help with perceived wait times, you can try things like friendly status updates (think: "Let me look that up..."), dynamic feedback, and streamlining your pipeline.
• Also, using unified models like GRIT can cut down on extra steps, speeding things up by over 60% in some cases.
If you want me to dive deeper or help out with anything else, just let me know—I’m here for you!
Sources: rag/main.py | examples/voice_agents/llamaindex-rag/README.md | External data and RAG | LiveKit Docs | README.md | External data and RAG | LiveKit Docsprehistoric-printer-73777
08/27/2025, 9:04 AMtall-airline-16756
08/27/2025, 9:06 AMprehistoric-printer-73777
08/27/2025, 9:08 AMtall-airline-16756
08/27/2025, 9:08 AMRoomInputOptions when you start an AgentSession. Here’s a quick example:
from livekit.plugins import noise_cancellation
await session.start(
room=ctx.room,
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(), # or NC(), BVCTelephony()
)
)
Compatibility:
• Works with Python and Node.js for inbound audio processing.
• Not available for outbound audio on Web, Swift, or Android platforms.
Just a couple of things to keep in mind:
• Avoid enabling noise cancellation on both the agent (inbound) and frontend (outbound) at the same time, since that can actually hurt performance.
• LiveKit’s AI-based models do a better job than the usual WebRTC noise suppression, especially when things get noisy or there are multiple speakers.
If you have any questions or want me to walk you through anything, just let me know—I’m happy to help!
Sources: Audio and video | LiveKit Docs | Noise & echo cancellation | LiveKit Docs | Enhanced noise cancellation | LiveKit Docs | AI noise cancellation | LiveKit Docsprehistoric-printer-73777
08/27/2025, 9:15 AMtall-airline-16756
08/27/2025, 9:15 AMBVCTelephony as an inbound noise cancellation filter, here’s a simple example to get you started:
await session.start(
agent=MyAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVCTelephony(),
),
)
Dynamic Model Selection:
In environments where you have different participant types, you can pick the right model on the fly like this:
participant = await ctx.wait_for_participant()
filter = noise_cancellation.BVC()
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
filter = noise_cancellation.BVCTelephony()
This way, you’ll get the best audio quality and transcription accuracy whether folks are joining via telephony or WebRTC.
If you have any questions or want me to walk you through anything else, just let me know — I’m here to help!
Sources: Voice AI quickstart | LiveKit Docs | AI noise cancellation | LiveKit Docs | Using Noise Cancellation for SIP and WebRTC Participants | Enhanced noise cancellation | LiveKit Docs