vector_db 中。
用法
我们将在此示例中使用本地 PgVector 数据库。请确保它正在运行:确保其正在运行
knowledge_base.py
knowledge_base 与 Agent 一起使用:
agent.py
WebsiteKnowledgeBase 还支持异步加载。
async_knowledge_base.py
参数
WebsiteKnowledgeBase 是 AgentKnowledge 类的子类,可以访问相同的参数。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
了解如何在知识库中使用网站。
vector_db 中。
pip install bs4
from agno.knowledge.website import WebsiteKnowledgeBase
from agno.vectordb.pgvector import PgVector
knowledge_base = WebsiteKnowledgeBase(
urls=["https://docs.agno.com/introduction"],
# 从种子 URL 开始跟踪的链接数量
max_links=10,
# 表名:ai.website_documents
vector_db=PgVector(
table_name="website_documents",
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
),
)
knowledge_base 与 Agent 一起使用:
from agno.agent import Agent
from knowledge_base import knowledge_base
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
)
agent.knowledge.load(recreate=False)
agent.print_response("Ask me about something from the knowledge base")
pip install qdrant-client
import asyncio
import asyncio
from agno.agent import Agent
from agno.knowledge.website import WebsiteKnowledgeBase
from agno.vectordb.qdrant import Qdrant
COLLECTION_NAME = "website-content"
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
# 使用种子 URL 创建知识库
knowledge_base = WebsiteKnowledgeBase(
urls=["https://docs.agno.com/introduction"],
# 从种子 URL 开始跟踪的链接数量
max_links=5,
# 表名:ai.website_documents
vector_db=vector_db,
)
# 使用知识库创建代理
agent = Agent(knowledge=knowledge_base, search_knowledge=True, debug_mode=True)
if __name__ == "__main__":
# 首次运行时注释掉此行
asyncio.run(knowledge_base.aload(recreate=False))
# 创建并使用代理
asyncio.run(agent.aprint_response("How does agno work?", markdown=True))
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
urls | List[str] | [] | 要读取的 URL |
reader | Optional[WebsiteReader] | None | 用于读取 URL 并将其转换为介质的 WebsiteReader Documents 供向量数据库使用。 |
max_depth | int | 3 | 要抓取的最大深度。 |
max_links | int | 10 | 要抓取的链接数。 |
WebsiteKnowledgeBase 是 AgentKnowledge 类的子类,可以访问相同的参数。