Skip to main content

Data Sources and RAG

Data sources let a Custodian Agent answer from the content of your own files. When you attach a file, Custodian Labs extracts its text, splits it into chunks, embeds them, and retrieves the most relevant chunks for each chat message (retrieval-augmented generation).

Supported file types

PDF, DOCX, XLSX, XLS, and plain-text formats (.txt, .md, .csv, .json, .yaml). Text files must be UTF-8. See Reference → Supported file types.

Attach a file

From a path (Node.js)

import { Custodian } from "@custodianlabs/sdk";

const custodian = new Custodian({
model: "gpt-4o",
systemPrompt: "Answer using the provided documents.",
}).addDataSourceFile("./docs/product_manual.pdf");

const app = await custodian.deploy();

With the builder:

const app = await new CustodianBuilder()
.withModel("gpt-4o")
.withPrompt("Answer using the provided documents.")
.withDataSourceFile("./docs/product_manual.pdf")
.deploy();

Call the method more than once to attach multiple files.

From in-memory bytes (browser, edge, serverless)

Runtimes without a filesystem pass the bytes directly instead of a path:

custodian.addDataSourceFile({
data: fileBytes, // Uint8Array | ArrayBuffer | Blob
filename: "manual.pdf",
contentType: "application/pdf", // optional
});

This is the FileInput type, shared by every file method in the SDK (including the Guardian Layer client).

Files upload at deploy time

addDataSourceFile() stages the file locally. The upload happens inside .deploy(), after the assistant is created. See Custodian Agent Class.

Inspect retrieved context

Each ChatResponse includes retrievedContexts — the chunks used for that answer:

const reply = await app.chat("How do I configure webhooks?");
console.log(reply?.response);
console.log(reply?.retrievedContexts);

Use it to check whether the agent is grounding its answer in the expected source material.

Good source-file practices

  • Prefer files with extractable text over scanned images.
  • Use clear section headings.
  • Remove unrelated content before uploading.
  • Split large knowledge bases into focused files.

Next steps