Skip to main content

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:

TypeExtensions
Text files.txt, .md, .csv, .json, .yaml, .yml, .log
PDF.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:

  1. Extracts text from the file.
  2. Splits the text into searchable chunks.
  3. Creates embeddings for those chunks.
  4. Stores the chunks with the assistant.

At chat time, Custodian Labs:

  1. Embeds the user's message.
  2. Finds the most relevant chunks for that message.
  3. Adds the retrieved context to the assistant request.
  4. 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