Data Sources and RAG
Data sources let an assistant answer questions using content from your own files.
When you add a file to an assistant, Custodian Labs set up the RAG for you. This includes processing the data file, extract the text, splits it into chunks, creates embeddings, and retrieves the most relevant chunks when a user sends a chat message.
When to Use Data Sources
Use data sources when your assistant needs to answer from:
- Product documentation.
- Internal policies.
- Support handbooks.
- FAQs.
- Structured reference files.
Data sources are useful when the answer should be grounded in your own content rather than only in the model's general knowledge.
Supported File Types
Supported formats include:
| Type | Extensions |
|---|---|
| Text files | .txt, .md, .csv, .json, .yaml, .yml, .log |
.pdf | |
| Word | .docx .odt |
| Excel | .xls, .xlsx, .xlsm, .xltx, .xltm |
Images coming soon!
Text files must be UTF-8 encoded.
Add a Data Source
With the Custodian class:
from custodian_labs import Custodian
custodian = Custodian(
model="gpt-4o",
system_prompt="You are a helpful support assistant.",
)
custodian.add_data_source_file("./support-handbook.pdf")
app = custodian.deploy()
With AssistantBuilder:
from custodian_labs import AssistantBuilder
app = (
AssistantBuilder()
.with_model("gpt-4o")
.with_prompt("You are a helpful support assistant.")
.with_data_source_file("./support-handbook.pdf")
.deploy()
)
You can add multiple files by calling the file method more than once.
How Retrieval Works
At upload time, Custodian Labs:
- Extracts text from the file.
- Splits the text into searchable chunks.
- Creates embeddings for those chunks.
- Stores the chunks with the assistant.
At chat time, Custodian Labs:
- Embeds the user's message.
- Finds the most relevant chunks for that message.
- Adds the retrieved context to the assistant request.
- Returns the assistant response with the retrieved context.
View Retrieved Context
Chat responses include retrieved_contexts, which shows the chunks used for the response:
response = app.chat("What is the refund policy?")
print(response.response)
print(response.retrieved_contexts)
Use this field when you want to inspect whether the assistant is grounding its answer in the expected source material.
Good Source File Practices
- Use clear section headings.
- Remove unrelated content before uploading.
- Prefer files with extractable text rather than scanned images.
- Split very large knowledge bases into focused files.
- Keep source files updated when policies or product details change.
Next Steps
- Chat Sessions: understand how context is retained across messages.
- Custodian Class: configure assistants programmatically.
- Builder API: add data sources with a chained configuration style.