Knowledge Base Guide (RAG)
Availability: Live
A knowledge base is a collection of documents in your workspace that an agent answers from. You do not attach it to the agent: you name it in a workflow node, so one knowledge base can serve many nodes and workflows. This page walks through the task; every operation and type is in the Knowledge API reference.
All calls below use a dashboard login (Authorization: Bearer <jwt>) plus x-huat-platform: customer. To manage vectors and search yourself instead, see Embeddings.
1. Create a knowledge base
Section titled “1. Create a knowledge base”mutation CreateKnowledgeBase($input: CreateKnowledgeBaseInput!) { createKnowledgeBase(input: $input) { id name }}{ "input": { "name": "Company Policies", "description": "Employee handbook and guidelines" }}The number of knowledge bases is limited by your plan.
2. Load documents
Section titled “2. Load documents”Three ways in, by source:
| Source | Operation | When the text is searchable |
|---|---|---|
| Pasted text, up to 500 KB | ingestDocument | When the call returns |
| One public web page | ingestDocumentFromUrl | When the call returns |
| A file, up to 20 MB | requestKnowledgeDocumentUpload, then confirmKnowledgeDocumentUpload | After background parsing (READY) |
Text is split into passages of about 512 words that overlap by 64 words, and each passage is embedded. Storage and passage counts count against your plan.
Inline text (synchronous)
Section titled “Inline text (synchronous)”mutation IngestText($input: IngestDocumentInput!) { ingestDocument(input: $input)}{ "input": { "knowledgeBaseId": 123, "fileName": "policies.txt", "text": "All employees must complete onboarding within 30 days." }}ingestDocument returns the number of passages created.
File upload (asynchronous)
Section titled “File upload (asynchronous)”Accepted files: PDF, DOCX, Markdown, CSV and XLSX. PDF and DOCX become plain text, Markdown is kept as written, and every CSV or XLSX row becomes one Header: value | Header: value line (each XLSX sheet starts with === Sheet: <name> ===), so a passage cut mid-table still says which column a value came from.
Ask for an upload URL:
mutation RequestUpload($input: RequestKnowledgeDocumentUploadInput!) { requestKnowledgeDocumentUpload(input: $input) { uploadUrl objectStorageKey }}{ "input": { "knowledgeBaseId": 123, "fileName": "employee_handbook.pdf", "mimeType": "application/pdf", "declaredSizeBytes": 2500000 }}PUT the file to uploadUrl within 15 minutes; the file goes straight to storage, not through the API. Then confirm with the same details and the returned key:
mutation ConfirmUpload($input: ConfirmKnowledgeDocumentUploadInput!) { confirmKnowledgeDocumentUpload(input: $input) { documentId parseStatus }}{ "input": { "knowledgeBaseId": 123, "fileName": "employee_handbook.pdf", "mimeType": "application/pdf", "objectStorageKey": "<objectStorageKey from the previous call>" }}Poll the document until parseStatus is READY or FAILED:
query WatchStatus($knowledgeBaseId: Int!) { knowledgeDocuments(knowledgeBaseId: $knowledgeBaseId) { id fileName parseStatus parseError }}A document goes PENDING, PARSING, READY. A corrupt or unsupported file, a file with no extractable text, or extraction running over 30 seconds ends in FAILED with parseError set, and the storage reserved for it is released.
3. Check what it retrieves
Section titled “3. Check what it retrieves”Before you build a workflow on it, ask the knowledge base the questions your users will ask:
query TestRetrieval($knowledgeBaseId: Int!, $query: String!, $topK: Int) { retrieveChunks( knowledgeBaseId: $knowledgeBaseId query: $query topK: $topK ) { chunkId documentId content score }}{ "knowledgeBaseId": 123, "query": "What is the onboarding process?", "topK": 5}It runs the same search an llm node runs, ordered by similarity (most relevant first); topK defaults to 5 and is capped at 20. If the right passage is not near the top for a paraphrased question, fix the source document before you build on it.
4. Answer from it in a workflow
Section titled “4. Answer from it in a workflow”Two node patterns:
- An
llmnode withknowledgeBaseId. Before the model runs, the user’s latest message is matched against the knowledge base, the five best passages are added to the system prompt, and the model is told to answer only from them and to say so when they do not contain the answer. SetallowGeneralKnowledgeFallbackwhen your own prompt says what to do without a match. - A
knowledge_searchnode, then anllmnode. The search writes the passages to a variable with no model call, so you can branch on “nothing found” (hand over to a person, say), set a minimum score, or search with a query other than the user’s message.
{ "id": "answer", "type": "llm", "label": "Answer from company policies", "config": { "promptTemplate": "You are the HR assistant. Answer the employee's question in two or three sentences.", "knowledgeBaseId": 123, "outputVar": "answer", "streamOutput": false }}A complete agent built this way is the support agent recipe.
Fail-open retrieval behavior
Section titled “Fail-open retrieval behavior”If the search behind an llm node’s knowledgeBaseId fails (a database error, for example), the node does not fail: it answers without passages, so the agent still replies. To tell “searched and found nothing” from “did not search”, read the node’s row in the run’s nodeTrace: retrievedChunkIds lists what was found (empty for nothing), and retrievalError is present only when the search failed. When a failed search must stop the reply, use a knowledge_search node, which fails instead.
See also
Section titled “See also”- Knowledge API reference: every operation, type and status.
knowledge_searchnode andllmnode: the config fields.- Embeddings: vectors for your own search.
- Rate limits: limits on ingestion and search.