固定大小分块是一种将文档分割成指定大小的小块的方法,块之间可以设置可选的重叠。当你希望将大型文档处理成更小、更易于管理的部分时,此方法会非常有用。
from agno.agent import Agent
from agno.document.chunking.fixed import FixedSizeChunking
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(table_name="recipes_fixed_size_chunking", db_url=db_url),
chunking_strategy=FixedSizeChunking(),
)
knowledge_base.load(recreate=False) # 首次运行后注释掉此行
agent = Agent(
knowledge_base=knowledge_base,
search_knowledge=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
固定大小分块参数
参数 | 类型 | 默认值 | 描述 |
---|
chunk_size | int | 5000 | 每个块的最大大小。 |
overlap | int | 0 | 块之间要重叠的字符数。 |
Responses are generated using AI and may contain mistakes.