Adding Knowledge (RAG)
Give you agent access to product documents, KBs, and more.
LLMs have tremendous knowledge about the world, but they don’t have all the up-to-date specifics about your organization, your products, or other relevant information you might want to provide to your AI voice agents.
RAG is a common technique for grounding agents in the relevant information for your use case.
Examples of Knowledge Sources
Let’s consider some of the content that might be useful to serve some popular use cases:
Adding RAG to Ultravox
As we saw in the Using Tools guide, tools provide power-ups for your agents. To use RAG with an Ultravox agent, it’s as simple as creating a tool and instructing the agent on how to use the tool.
The Easy Way
Ultravox provides the corpus service for RAG.
Create a Corpus
Use the Create Corpus endpoint. Give your new corpus a name and (optional) description. This returns a corpusId
.
Create a Source
Add a website to crawl using Create Corpus Source. Each source is given a unique sourceId
. We will crawl the URL(s) and ingest all the content.
Query the Corpus
After everything is loaded, try some queries using the Query Corpus endpoint.
Use the queryCorpus Tool
Give the built-in queryCorpus tool. to your agents and provide the corpusId
. For example, if we wanted to create a voice agent to answer questions about Seattle, we could provide the tool like this:
The Other Way
Let’s assume we have already stored our product documentation in a vector database and can search that content at https://foo.bar/lookupProductInfo
.
Here’s how we might create a tool for our Ultravox agent to use:
Add Static Files as Corpus Sources
You can use files as sources for any of your corpora. The process requires using the Create Corpus File Upload API to generate an upload URL.
Follow these steps:
Step 1: Request Upload URL
- Use the Create Corpus File Upload API
- Include the MIME type string in the request body
- This returns the URL to use for upload and the unique ID for the document
- URLs expire after 5 minutes. Request a new one if it expires before using it
Step 2: Upload File
- Use the
presignedUrl
from Step 1 to upload the document - Ensure the MIME type in the upload matches what was specified in Step 1
For example, if we requested an upload URL for a text file (MIME type text/plain
):
Step 3: Create New Source with Uploaded Document
- Use the Create Corpus Source API
- Use
upload
to provide thedocumentId
from Step 1
Supported File Types
Here’s the information in a markdown table format:
File Extension | Type of File | MIME Type |
---|---|---|
doc | Microsoft Word Document | application/msword |
docx | Microsoft Word Open XML Document | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
txt | Plain Text Document | text/plain |
md | Markdown Document | text/markdown |
ppt | Microsoft PowerPoint Presentation | application/vnd.ms-powerpoint |
pptx | Microsoft PowerPoint Open XML Presentation | application/vnd.openxmlformats-officedocument.presentationml.presentation |
Portable Document Format | application/pdf |