> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Pdf-Url 进行 Agentic 过滤

> 了解如何使用带有用户特定元数据的 Pdf-Url 文档进行 agentic 知识过滤。

## 代码

```python theme={null}
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.lancedb import LanceDb

# 初始化 LanceDB
# 默认情况下，它将数据存储在 /tmp/lancedb
vector_db = LanceDb(
    table_name="recipes",
    uri="tmp/lancedb",  # 您可以将此路径更改为存储数据的位置
)

# 步骤 1：使用文档和元数据初始化知识库
# ------------------------------------------------------------------------------
# 在初始化知识库时，我们可以附加将用于过滤的元数据
# 此元数据可以包括用户 ID、文档类型、日期或任何其他属性

knowledge_base = PDFUrlKnowledgeBase(
    urls=[
        {
            "url": "https://agno-public.s3.amazonaws.com/recipes/thai_recipes_short.pdf",
            "metadata": {
                "cuisine": "Thai",
                "source": "Thai Cookbook",
                "region": "Southeast Asia",
            },
        },
        {
            "url": "https://agno-public.s3.amazonaws.com/recipes/cape_recipes_short_2.pdf",
            "metadata": {
                "cuisine": "Cape",
                "source": "Cape Cookbook",
                "region": "South Africa",
            },
        },
    ],
    vector_db=vector_db,
)

# 将所有文档加载到向量数据库中
knowledge_base.load(recreate=True)

# 步骤 2：使用 Agent 查询知识库，通过查询中的过滤器自动进行过滤
# -----------------------------------------------------------------------------------

# 启用 agentic 过滤
agent = Agent(
    knowledge=knowledge_base,
    search_knowledge=True,
    enable_agentic_knowledge_filters=True,
)

# 查询 Jordan Mitchell 的经验和技能，并在查询中包含过滤器，以便 Agent 可以自动提取它们
agent.print_response(
    "如何制作泰式炒河粉，参考文档中 cuisine 为 Thai 且 source 为 Thai Cookbook 的内容",
    markdown=True,
)
```

## 用法

<Steps>
  <Step title="安装库">
    ```bash theme={null}
    pip install -U agno openai lancedb
    ```
  </Step>

  <Step title="运行示例">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/knowledge/filters/pdf_url/agentic_filtering.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/knowledge/filters/pdf_url/agentic_filtering.py
      ```
    </CodeGroup>
  </Step>
</Steps>
