Agentic 分块是一种智能方法,通过使用模型来确定文本中的自然断点来将文档拆分成更小的块。它不是在固定的字符数处分割文本,而是分析内容以查找语义上有意义的边界,例如段落中断和主题转换。
from agno.agent import Agent
from agno.document.chunking.agentic import AgenticChunking
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_agentic_chunking", db_url=db_url),
chunking_strategy=AgenticChunking(),
)
knowledge_base.load(recreate=False) # 首次运行后注释掉此行
agent = Agent(
knowledge_base=knowledge_base,
search_knowledge=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
Agentic 分块参数
参数 | 类型 | 默认值 | 描述 |
---|
model | Model | OpenAIChat | 用于分块的模型。 |
max_chunk_size | int | 5000 | 每个块的最大尺寸。 |
Responses are generated using AI and may contain mistakes.