| title | Knowledge Base |
|---|---|
| description | Add documents to your agents' knowledge base for RAG-powered responses on elizaOS Cloud. |
import { Callout, Steps, Tabs, Cards } from "nextra/components";
Enhance your agents with document-based knowledge using Retrieval-Augmented Generation (RAG).
The Knowledge Base allows you to:
- Upload documents (PDF, TXT, MD, etc.)
- Automatically chunk and embed content
- Query semantically for relevant context
- Connect to agents for enhanced responses
Navigate to Dashboard → Knowledge for the visual interface.
<Tabs items={['cURL', 'JavaScript', 'Python']}> <Tabs.Tab>
# Upload a document
curl -X POST "https://cloud.milady.ai/api/v1/knowledge/upload-file" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@document.pdf" \
-F "agentId=agent_abc123"</Tabs.Tab> <Tabs.Tab>
const formData = new FormData();
formData.append('file', file);
formData.append('agentId', 'agent_abc123');
const response = await fetch('https://cloud.milady.ai/api/v1/knowledge/upload-file', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
},
body: formData,
});
const result = await response.json();
console.log('Document uploaded:', result.id);</Tabs.Tab> <Tabs.Tab>
import requests
with open('document.pdf', 'rb') as f:
response = requests.post(
'https://cloud.milady.ai/api/v1/knowledge/upload-file',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
files={'file': f},
data={'agentId': 'agent_abc123'},
)
result = response.json()
print(f'Document uploaded: {result["id"]}')</Tabs.Tab>
| Format | Extension | Max Size |
|---|---|---|
.pdf |
5MB | |
| Text | .txt |
5MB |
| Markdown | .md |
5MB |
| Word | .docx |
5MB |
| JSON | .json |
5MB |
| XML | .xml |
5MB |
| YAML | .yaml |
5MB |
| CSV | .csv |
5MB |
Note: Maximum 5MB per file and 5MB total per batch upload.
### Prepare Your Documents Ensure documents are in a supported format and within size limits.Use the Knowledge dashboard or the upload API endpoint.
Documents are automatically chunked and embedded.
Link the knowledge base to your agent for RAG.
{
"id": "doc_abc123",
"filename": "product-manual.pdf",
"status": "processing",
"chunks": null,
"createdAt": "2024-01-15T10:30:00Z"
}curl -X GET "https://cloud.milady.ai/api/v1/knowledge/check?documentId=doc_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"{
"id": "doc_abc123",
"status": "completed",
"chunks": 42,
"tokensUsed": 15234
}Search your knowledge base semantically:
curl -X POST "https://cloud.milady.ai/api/v1/knowledge/query" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How do I reset my password?",
"agentId": "agent_abc123",
"limit": 5
}'{
"results": [
{
"content": "To reset your password, navigate to Settings > Security > Reset Password...",
"score": 0.92,
"documentId": "doc_abc123",
"metadata": {
"page": 15,
"section": "Account Settings"
}
},
{
"content": "Password requirements include at least 8 characters...",
"score": 0.85,
"documentId": "doc_abc123",
"metadata": {
"page": 16,
"section": "Security"
}
}
]
}curl -X GET "https://cloud.milady.ai/api/v1/knowledge?agentId=agent_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"curl -X GET "https://cloud.milady.ai/api/v1/knowledge/doc_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"curl -X DELETE "https://cloud.milady.ai/api/v1/knowledge/doc_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"Configure how documents are split:
| Setting | Default | Description |
|---|---|---|
chunkSize |
1000 | Characters per chunk |
chunkOverlap |
200 | Overlap between chunks |
minChunkSize |
100 | Minimum chunk size |
Configure query behavior:
| Setting | Default | Description |
|---|---|---|
limit |
5 | Number of results |
minScore |
0.7 | Minimum relevance score |
rerank |
true | Re-rank results for relevance |
When knowledge is connected to an agent, relevant context is automatically retrieved:
// Agent with knowledge base
const response = await fetch("https://cloud.milady.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "agent_abc123", // Agent with connected knowledge
messages: [{ role: "user", content: "How do I reset my password?" }],
}),
});The agent automatically queries the knowledge base and includes relevant context in its response.
Query knowledge and inject context manually:
// 1. Query knowledge
const knowledge = await fetch("https://cloud.milady.ai/api/v1/knowledge/query", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
query: "password reset",
limit: 3,
}),
}).then((r) => r.json());
// 2. Include in chat
const context = knowledge.results.map((r) => r.content).join("\n\n");
const response = await fetch("https://cloud.milady.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-4o",
messages: [
{ role: "system", content: `Use this context:\n\n${context}` },
{ role: "user", content: "How do I reset my password?" },
],
}),
});See Billing & Credits for current pricing on document uploads, embeddings, queries, and storage.
- Quality Content — Use well-structured, accurate documents
- Organize — Group related documents for better retrieval
- Update Regularly — Keep knowledge current by refreshing documents
- Test Queries — Verify retrieval quality before production