用法
我们在此示例中使用本地 LanceDB 数据库。请确保它正在运行
knowledge_base.py
参数
PDFBytesKnowledgeBase 是 AgentKnowledge 类的子类,拥有相同的参数访问权限。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
了解如何在您的知识库中使用内存中的 PDF 字节。
pip install pypdf
from agno.agent import Agent
from agno.knowledge.pdf import PDFBytesKnowledgeBase
from agno.vectordb.lancedb import LanceDb
vector_db = LanceDb(
table_name="recipes_async",
uri="tmp/lancedb",
)
with open("data/pdfs/ThaiRecipes.pdf", "rb") as f:
pdf_bytes = f.read()
knowledge_base = PDFBytesKnowledgeBase(
pdfs=[pdf_bytes],
vector_db=vector_db,
)
knowledge_base.load(recreate=False) # 首次运行后注释掉此行
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
)
agent.print_response("How to make Tom Kha Gai?", markdown=True)
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| pdfs | Union[List[bytes], List[IO]] | - | PDF 内容列表(以字节或 IO 流形式)。 |
| exclude_files | List[str] | [] | 要排除的文件模式列表(从基类继承)。 |
| reader | Union[PDFReader, PDFImageReader] | PDFReader() | 将 PDF 转换为向量数据库的 Document 的 PDFReader 或 PDFImageReader。 |
PDFBytesKnowledgeBase 是 AgentKnowledge 类的子类,拥有相同的参数访问权限。