Quản lý tài liệu trong kho kiến thức ElevenAgents
Mua gói Thành viên QuanTriMang Pro để trải nghiệm website không quảng cáo và sử dụng các tiện ích AI trên QuanTriMang.
Tìm hiểu cách quản lý cơ sở kiến thức của bạn từ dashboard Knowledge Base, CLI hoặc API. Để hiểu rõ cơ sở kiến thức là gì và cách các agent sử dụng nó, hãy xem phần Thiết lập cơ sở kiến thức cho ElevenAgents.
Thêm tài liệu
Tài liệu có thể được tạo từ file, trang web hoặc plain text. Sau khi tạo, hãy gắn chúng vào một agent để nội dung tài liệu có thể được sử dụng trong các cuộc hội thoại.
Dashboard
Từ dashboard Knowledge Base hoặc trực tiếp từ phần cấu hình của agent, hãy nhấp vào Add document và chọn nguồn dữ liệu.
1. File
Upload lên tài liệu ở định dạng PDF, TXT, DOCX, HTML, EPUB hoặc Markdown, với dung lượng tối đa 20MB mỗi file.
2. URL
Nhập trang web bằng cách dán URL của trang đó. Để nạp dữ liệu từ toàn bộ trang web, hãy sử dụng tùy chọn thu thập dữ liệu (crawl) - bạn có thể thu thập toàn bộ trang web bằng cách đi theo các liên kết từ URL bắt đầu, hoặc nhập các trang từ sơ đồ trang web (sitemap). Nếu việc nhập trang thất bại, hãy đảm bảo rằng trang web của bạn cho phép user agent của trình thu thập dữ liệu hoạt động.
Đảm bảo bạn có quyền sử dụng nội dung từ các URL mà mình cung cấp.
3. Text
Nhập văn bản thủ công và đặt tên cho nó.
CLI
CLI không hỗ trợ upload trực tiếp các tài liệu cơ sở kiến thức (knowledge base). Hãy tạo chúng thông qua dashboard hoặc API, sau đó đính kèm các ID tài liệu thu được vào cấu hình agent của bạn.
1. Tải cấu hình agent về
elevenlabs agents pull --agent "<agent-name>"
2. Chỉnh sửa file agent_configs/<agent-name>.json
Thiết lập trường conversation_config.agent.prompt.knowledge_base:
{
"conversation_config": {
"agent": {
"prompt": {
"knowledge_base": [
{
"type": "file",
"name": "Unladen Swallow Facts",
"id": "i2YYI6huwBmcgYydAXARmQJc3pmX",
"usage_mode": "auto"
}
]
}
}
}
}
3. Đẩy các thay đổi của bạn lên hệ thống
elevenlabs agents push --agent "<agent-name>"
API
Tạo từng tài liệu, sau đó gắn các ID được trả về vào cấu hình của agent.
Python
import os
from dotenv import load_dotenv
from elevenlabs import ElevenLabs
load_dotenv()
elevenlabs = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
# Create a document from text
text_doc = elevenlabs.conversational_ai.knowledge_base.documents.create_from_text(
text="The airspeed velocity of an unladen swallow (European) is 24 miles per hour, or roughly 11 meters per second.",
name="Unladen Swallow facts",
)
# Create a document from a URL
url_doc = elevenlabs.conversational_ai.knowledge_base.documents.create_from_url(
url="https://en.wikipedia.org/wiki/Unladen_swallow",
name="Unladen Swallow Wikipedia page",
)
# Create a document from a file
file_doc = elevenlabs.conversational_ai.knowledge_base.documents.create_from_file(
file=open("/path/to/unladen-swallow-facts.txt", "rb"),
name="Unladen Swallow Facts",
)
# Attach the documents to an agent
elevenlabs.conversational_ai.agents.update(
agent_id="agent_7101k5zvyjhmfg983brhmhkd98n6",
conversation_config={
"agent": {
"prompt": {
"knowledge_base": [
{"type": "text", "name": text_doc.name, "id": text_doc.id},
{"type": "url", "name": url_doc.name, "id": url_doc.id},
{"type": "file", "name": file_doc.name, "id": file_doc.id},
]
}
}
},
)
TypeScript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import fs from "node:fs";
import "dotenv/config";
const elevenlabs = new ElevenLabsClient();
// Create a document from text
const textDoc = await elevenlabs.conversationalAi.knowledgeBase.documents.createFromText({
name: "Unladen Swallow Facts",
text: "The airspeed velocity of an unladen swallow (European) is 24 miles per hour, or roughly 11 meters per second.",
});
// Create a document from a URL
const urlDoc = await elevenlabs.conversationalAi.knowledgeBase.documents.createFromUrl({
name: "Unladen Swallow Wikipedia page",
url: "https://en.wikipedia.org/wiki/Unladen_swallow",
});
// Create a document from a file
const fileBuffer = fs.readFileSync("/path/to/unladen-swallow-facts.txt");
const file = new File([fileBuffer], "unladen-swallow-facts.txt", { type: "text/plain" });
const fileDoc = await elevenlabs.conversationalAi.knowledgeBase.documents.createFromFile({
name: "Unladen Swallow Facts",
file,
});
// Attach the documents to an agent
await elevenlabs.conversationalAi.agents.update("agent_7101k5zvyjhmfg983brhmhkd98n6", {
conversationConfig: {
agent: {
prompt: {
knowledgeBase: [
{ type: "text", name: textDoc.name, id: textDoc.id },
{ type: "url", name: urlDoc.name, id: urlDoc.id },
{ type: "file", name: fileDoc.name, id: fileDoc.id },
],
},
},
},
});
Để thu thập toàn bộ dữ liệu từ một trang web vào một thư mục tài liệu thay vì chỉ thêm một trang duy nhất, hãy bắt đầu một tác vụ thu thập dữ liệu. Quá trình thu thập dữ liệu diễn ra bất đồng bộ - hãy sử dụng ID tác vụ được trả về để kiểm tra trạng thái hoặc hủy bỏ nó.
Python
crawl = elevenlabs.conversational_ai.knowledge_base.crawl_jobs.create(
url="https://elevenlabs.io/docs",
max_depth=3,
max_pages=1000,
)
TypeScript
const crawl = await elevenlabs.conversationalAi.knowledgeBase.crawlJobs.create({
url: "https://elevenlabs.io/docs",
maxDepth: 3,
maxPages: 1000,
});
Crawler user agent
Các tác vụ nhập URL và thu thập dữ liệu sẽ truy xuất các trang bằng user agent là ElevenlabsBot/1.0.
Nếu trang web của bạn nằm sau CDN, WAF hoặc quy tắc bảo vệ chống bot, hãy cho phép user agent này để trình thu thập dữ liệu có thể đọc được các trang của bạn. Khi một yêu cầu bị chặn, tài liệu vẫn được tạo nhưng không thể trích xuất nội dung từ đó.
Trình thu thập dữ liệu cũng tuân thủ file robots.txt. Các trang bị cấm đối với ElevenlabsBot hoặc tất cả các user agent sẽ bị bỏ qua; vì vậy, hãy kiểm tra các quy tắc của bạn nếu một trang mà bạn mong đợi được lập chỉ mục lại bị thiếu. Để cho phép trình thu thập dữ liệu một cách cụ thể:
robots.txt
User-agent: ElevenlabsBot
Allow: /
Thêm tài liệu hiện có vào agent
Tài liệu có thể được tái sử dụng cho nhiều agent, do đó kiến thức dùng chung chỉ cần được duy trì một lần duy nhất.
- Đi tới phần cấu hình của agent.
- Tìm mục Knowledge Base và nhấp vào Add document.
- Chọn một tài liệu có sẵn từ cơ sở kiến thức hoặc upload lên tài liệu mới.
Việc tái sử dụng tài liệu giữa các agent giúp đảm bảo tính nhất quán của kiến thức và tránh việc tải lên trùng lặp.
Chỉnh sửa tài liệu
Bạn có thể chỉnh sửa trực tiếp nội dung tài liệu thay vì xóa và upload lại. Việc chỉnh sửa tài liệu sẽ tự động tạo lại các đoạn nội dung để tìm kiếm và những vector nhúng RAG, đảm bảo tính đồng bộ giữa chức năng tìm kiếm và khả năng truy xuất của agent.
- Tài liệu dạng văn bản và file: Chỉnh sửa nội dung trực tiếp (inline) và lưu lại.
- Tài liệu dạng file: Ngoài ra, bạn có thể thay thế file hiện tại bằng một phiên bản mới.
- Tài liệu dạng URL: Chỉnh sửa nội dung khi tính năng tự động đồng bộ (auto-sync) đang tắt. Khi tính năng này đang bật, chu kỳ đồng bộ sẽ quản lý tài liệu và các thao tác chỉnh sửa thủ công sẽ bị chặn.
Python
# Update a document's name or content
elevenlabs.conversational_ai.knowledge_base.documents.update(
documentation_id="i2YYI6huwBmcgYydAXARmQJc3pmX",
name="Unladen Swallow Facts",
content="The airspeed velocity of an unladen swallow (European) is 24 miles per hour.",
)
# Replace the underlying file of a file document
elevenlabs.conversational_ai.knowledge_base.document.update_file(
documentation_id="i2YYI6huwBmcgYydAXARmQJc3pmX",
file=open("/path/to/unladen-swallow-facts-v2.txt", "rb"),
)
TypeScript
// Update a document's name or content
await elevenlabs.conversationalAi.knowledgeBase.documents.update("i2YYI6huwBmcgYydAXARmQJc3pmX", {
name: "Unladen Swallow Facts",
content: "The airspeed velocity of an unladen swallow (European) is 24 miles per hour.",
});
// Replace the underlying file of a file document
const fileBuffer = fs.readFileSync("/path/to/unladen-swallow-facts-v2.txt");
const updatedFile = new File([fileBuffer], "unladen-swallow-facts-v2.txt", { type: "text/plain" });
await elevenlabs.conversationalAi.knowledgeBase.document.updateFile("i2YYI6huwBmcgYydAXARmQJc3pmX", {
file: updatedFile,
});
Luôn cập nhật nội dung từ URL
Các tài liệu được tạo từ URL có thể được làm mới để lấy lại nội dung mới nhất từ nguồn gốc. Việc làm mới sẽ lập lại chỉ mục cho tài liệu, nhờ đó các agent hỗ trợ RAG sẽ sử dụng nội dung đã được cập nhật.
Python
elevenlabs.conversational_ai.knowledge_base.document.refresh(
documentation_id="i2YYI6huwBmcgYydAXARmQJc3pmX",
)
TypeScript
await elevenlabs.conversationalAi.knowledgeBase.document.refresh("i2YYI6huwBmcgYydAXARmQJc3pmX");
Trong dashboard, bạn cũng có thể bật tính năng tự động đồng bộ để tự động làm mới các tài liệu URL theo lịch trình, đảm bảo nội dung luôn được cập nhật mà không cần cập nhật thủ công.
Sắp xếp bằng thư mục
Thư mục nhóm các tài liệu liên quan lại với nhau để dễ quản lý và đính kèm hàng loạt. Tạo một thư mục, sau đó di chuyển tài liệu vào đó từ dashboard hoặc API.
Một thư mục được đính kèm với một agent sẽ giúp tất cả tài liệu của agent đó có sẵn thông qua RAG, vì vậy agent đó phải bật RAG để sử dụng thư mục.
Python
# Create a folder
folder = elevenlabs.conversational_ai.knowledge_base.documents.create_folder(
name="Product documentation",
)
# Move a document into the folder
elevenlabs.conversational_ai.knowledge_base.documents.move(
document_id="i2YYI6huwBmcgYydAXARmQJc3pmX",
move_to=folder.id,
)
TypeScript
// Create a folder
const folder = await elevenlabs.conversationalAi.knowledgeBase.documents.createFolder({
name: "Product documentation",
});
// Move a document into the folder
await elevenlabs.conversationalAi.knowledgeBase.documents.move("i2YYI6huwBmcgYydAXARmQJc3pmX", {
moveTo: folder.id,
});
Các dependency và việc xóa
Mỗi tài liệu đều có tab Dependent agents, liệt kê những agent hiện đang phụ thuộc vào tài liệu đó.
Không thể xóa tài liệu khi vẫn có agent phụ thuộc vào nó. Hãy loại bỏ tài liệu khỏi các agent đó trước, hoặc sử dụng tính năng Force deletion (buộc xóa) để ngắt kết nối tài liệu khỏi tất cả các dependency cùng lúc.
Bạn nên đọc
-
Kiểm soát cách ElevenAgents hoạt động trong môi trường thực tế
-
Cách chọn mô hình AI phù hợp trong ElevenAgents
-
Cách cấu hình agent để giao tiếp bằng nhiều ngôn ngữ trong ElevenAgents
-
Cách thiết kế giọng nói sống động, lôi cuốn cho ElevenLabs Agents
-
Cấu hình hành vi kênh (channel) cho ElevenAgents
-
Cách thiết kế các luồng hội thoại phức tạp trong ElevenAgents
-
Thiết kế và cấu hình AI agent đàm thoại trong ElevenLabs
-
Các nguyên tắc thiết kế hệ thống AI đàm thoại trong ElevenLabs
-
Tạo quy trình có cấu trúc cho ElevenAgents
Theo Nghị định 147/2024/ND-CP, bạn cần xác thực tài khoản trước khi sử dụng tính năng này. Chúng tôi sẽ gửi mã xác thực qua SMS hoặc Zalo tới số điện thoại mà bạn nhập dưới đây:
Hướng dẫn AI
AI Tools
Học IT
Hàm Excel