Knowledge
Upload documents and get grounded answers with citations.
A knowledge base ingests documents (PDF, DOCX, TXT, Markdown, HTML, URLs, or raw text), chunks and embeds them, and answers questions with citations.
Create and upload
import { createKnowledgeClient } from "@libra-memory/sdk";
const knowledge = createKnowledgeClient({ apiKey: process.env.LIBRA_API_KEY });
const kb = knowledge.knowledge("support-docs");
await knowledge.createKnowledge({ name: "support-docs", instructions: "Cite sources." });
await kb.uploadFile("./returns-policy.pdf");
await kb.uploadText({ title: "shipping", text: "We ship worldwide in 3–5 days." });
await kb.waitUntilReady();Ingestion is asynchronous — poll a document's status until ready (the SDK's
waitUntilReady() does this for you).
Chat with citations
const res = await kb.chat([{ role: "user", content: "How long is the return window?" }]);
console.log(res.message.content); // grounded answer
console.log(res.citations); // source chunksUse context() instead of chat() to retrieve the matching chunks without
generating an answer.