mirror of
https://github.com/agno-agi/agno.git
synced 2026-10-11 22:09:58 +00:00
feat: V2.0.0 (#4226)
Changelog TBD --------- Co-authored-by: Willem Carel de Jongh <[email protected]> Co-authored-by: Nancy Chauhan <[email protected]> Co-authored-by: manu <[email protected]> Co-authored-by: Mustafa Esoofally <[email protected]> Co-authored-by: Kaustubh <[email protected]> Co-authored-by: ysolanky <[email protected]> Co-authored-by: Harshith VH <[email protected]> Co-authored-by: Ayush <[email protected]> Co-authored-by: Monalisha Mishra <[email protected]> Co-authored-by: Yash Pratap Solanky <[email protected]> Co-authored-by: Ashpreet <[email protected]> Co-authored-by: yarin-tradezbird <[email protected]> Co-authored-by: yarinbass <[email protected]> Co-authored-by: Anurag <[email protected]> Co-authored-by: Adi Berkowitz <[email protected]> Co-authored-by: Adi Berkowitz <[email protected]>
This commit is contained in:
co-authored by
Willem Carel de Jongh
Nancy Chauhan
manu
Mustafa Esoofally
Kaustubh
ysolanky
Harshith VH
Ayush
Monalisha Mishra
Yash Pratap Solanky
Ashpreet
yarin-tradezbird
yarinbass
Anurag
Adi Berkowitz
Adi Berkowitz
parent
d9a133f59d
commit
9342086712
@@ -11,9 +11,10 @@ on:
|
||||
- reopened
|
||||
branches:
|
||||
- "main"
|
||||
- "v2.0"
|
||||
|
||||
jobs:
|
||||
style-check:
|
||||
style-check-agno:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -46,8 +47,77 @@ jobs:
|
||||
run: |
|
||||
mypy .
|
||||
|
||||
style-check-cookbook:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.9"]
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: cookbook
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade \
|
||||
pip setuptools wheel \
|
||||
ruff mypy pytest
|
||||
pip install --no-deps -r ../libs/agno/requirements.txt
|
||||
- name: Ruff format
|
||||
run: |
|
||||
ruff format .
|
||||
- name: Ruff check
|
||||
run: |
|
||||
ruff check .
|
||||
# - name: Mypy
|
||||
# run: |
|
||||
# mypy .
|
||||
|
||||
|
||||
style-check-agno-infra:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.9"]
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: libs/agno_infra
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade \
|
||||
pip setuptools wheel \
|
||||
ruff mypy pytest
|
||||
pip install -r requirements.txt
|
||||
- name: Ruff format
|
||||
run: |
|
||||
ruff format .
|
||||
- name: Ruff check
|
||||
run: |
|
||||
ruff check .
|
||||
- name: Mypy
|
||||
run: |
|
||||
mypy .
|
||||
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
# Skip push events if there's an open PR from the same branch
|
||||
if: github.event_name != 'push' || !github.event.pull_request
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.12"]
|
||||
|
||||
@@ -5,6 +5,13 @@ on:
|
||||
branches:
|
||||
- "*release*" # Run on release-* format
|
||||
- "release/*" # Run on release/1.2.3 branch format
|
||||
- "v2.0"
|
||||
workflow_dispatch: # Allows manual triggering
|
||||
inputs:
|
||||
branch:
|
||||
description: 'Branch to run checks on'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
style-check:
|
||||
@@ -708,7 +715,7 @@ jobs:
|
||||
working-directory: .
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
python -m pytest ./libs/agno/tests/integration/workflows ./libs/agno/tests/integration/workflows_2
|
||||
python -m pytest ./libs/agno/tests/integration/workflows
|
||||
|
||||
test-embedder:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -766,15 +773,12 @@ jobs:
|
||||
working-directory: .
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
python -m pytest ./libs/agno/tests/integration/knowledge/test_csv_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_csv_url_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_docx_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_json_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_md_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_pdf_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_pdf_url_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_pdf_bytes_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_text_knowledge_base.py
|
||||
python -m pytest ./libs/agno/tests/integration/knowledge/test_csv_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_docx_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_json_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_md_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_pdf_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_text_knowledge.py
|
||||
|
||||
test-knowledge-2:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -803,11 +807,10 @@ jobs:
|
||||
working-directory: .
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
python -m pytest ./libs/agno/tests/integration/knowledge/test_arxiv_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_firecrawl_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_url_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_website_knowledge_base.py \
|
||||
./libs/agno/tests/integration/knowledge/test_youtube_knowledge_base.py
|
||||
python -m pytest ./libs/agno/tests/integration/knowledge/test_arxiv_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_firecrawl_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_website_knowledge.py \
|
||||
./libs/agno/tests/integration/knowledge/test_youtube_knowledge.py
|
||||
|
||||
# Run remaining integration tests
|
||||
test-remaining:
|
||||
@@ -837,4 +840,4 @@ jobs:
|
||||
working-directory: .
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
python -m pytest --ignore=./libs/agno/tests/integration/models --ignore=./libs/agno/tests/integration/agent --ignore=./libs/agno/tests/integration/knowledge --ignore=./libs/agno/tests/integration/teams --ignore=./libs/agno/tests/integration/embedder --ignore=./libs/agno/tests/integration/workflows --ignore=./libs/agno/tests/integration/workflows_2 ./libs/agno/tests/integration
|
||||
python -m pytest --ignore=./libs/agno/tests/integration/db --ignore=./libs/agno/tests/integration/models --ignore=./libs/agno/tests/integration/agent --ignore=./libs/agno/tests/integration/knowledge --ignore=./libs/agno/tests/integration/teams --ignore=./libs/agno/tests/integration/embedder --ignore=./libs/agno/tests/integration/workflows --ignore=./libs/agno/tests/integration/workflows_2 ./libs/agno/tests/integration
|
||||
|
||||
+8
-1
@@ -43,6 +43,7 @@ venv*
|
||||
agnoenv*
|
||||
aienv*
|
||||
phienv*
|
||||
set-env.ps1
|
||||
|
||||
# ignore tmp dirs
|
||||
scratch
|
||||
@@ -65,6 +66,12 @@ token.json
|
||||
coverage_report
|
||||
.coverage
|
||||
|
||||
# JSON files used as testing DB
|
||||
agno_json_data/
|
||||
|
||||
# AI
|
||||
.claude/
|
||||
.cursor/
|
||||
.cursor/
|
||||
|
||||
# ignore pyrightconfig.json
|
||||
pyrightconfig.json
|
||||
|
||||
+11
-11
@@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
- Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
@@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
|
||||
+2
-2
@@ -78,8 +78,8 @@ Make sure all tests pass before submitting your pull request. If you add new fea
|
||||
- The `VectorDb` interface is defined in `libs/agno/agno/vectordb/base
|
||||
- Import your `VectorDb` Class in `libs/agno/agno/vectordb/<your_db>/__init__.py`.
|
||||
- Checkout the [`libs/agno/agno/vectordb/pgvector/pgvector`](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/vectordb/pgvector/pgvector.py) file for an example.
|
||||
4. Add a recipe for using your `VectorDb` under `cookbook/agent_concepts/knowledge/vector_dbs/<your_db>`.
|
||||
- Checkout [`cookbook/agent_concepts/knowledge/vector_dbs/pgvector_db/pg_vector`](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/pgvector_db/pg_vector.py) for an example.
|
||||
4. Add a recipe for using your `VectorDb` under `cookbook/knowledge/vector_dbs/<your_db>`.
|
||||
- Checkout [`cookbook/knowledge/vector_dbs/pgvector_db/pg_vector`](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/pgvector_db/pg_vector.py) for an example.
|
||||
5. Important: Format and validate your code by running `./scripts/format.sh` and `./scripts/validate.sh`.
|
||||
6. Submit a pull request.
|
||||
|
||||
|
||||
@@ -15,169 +15,68 @@
|
||||
|
||||
## What is Agno?
|
||||
|
||||
[Agno](https://docs.agno.com) is a full-stack framework for building Multi-Agent Systems with memory, knowledge and reasoning.
|
||||
[Agno](https://docs.agno.com) is a high-performance runtime for multi-agent systems. Use it to build, run and manage secure multi-agent systems in your cloud.
|
||||
|
||||
Use Agno to build the 5 levels of Agentic Systems:
|
||||
- Level 1: Agents with tools and instructions.
|
||||
- Level 2: Agents with knowledge and storage.
|
||||
- Level 3: Agents with memory and reasoning.
|
||||
- Level 4: Agent Teams that can reason and collaborate.
|
||||
- Level 5: Agentic Workflows with state and determinism.
|
||||
Agno gives you the fastest framework for building agents with session management, memory, knowledge, human in the loop and MCP support. You can put agents together as an autonomous multi-agent team, or build step-based agentic workflows for full control over complex multi-step processes.
|
||||
|
||||
Example: Level 1 Reasoning Agent that uses the YFinance API to answer questions:
|
||||
In 10 lines of code, we can build an Agent that will fetch the top stories from HackerNews and summarize them.
|
||||
|
||||
```python reasoning_finance_agent.py
|
||||
```python hackernews_agent.py
|
||||
from agno.agent import Agent
|
||||
from agno.models.anthropic import Claude
|
||||
from agno.tools.reasoning import ReasoningTools
|
||||
from agno.tools.yfinance import YFinanceTools
|
||||
|
||||
reasoning_agent = Agent(
|
||||
model=Claude(id="claude-sonnet-4-20250514"),
|
||||
tools=[
|
||||
ReasoningTools(add_instructions=True),
|
||||
YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),
|
||||
],
|
||||
instructions="Use tables to display data.",
|
||||
markdown=True,
|
||||
)
|
||||
```
|
||||
|
||||
https://github.com/user-attachments/assets/4ef27ba6-a781-4fb0-b49c-bfd838123c83
|
||||
|
||||
## Get Started
|
||||
|
||||
If you're new to Agno, read the documentation to build your [first Agent](https://docs.agno.com/introduction/agents), chat with it on the [playground](https://docs.agno.com/introduction/playground) and monitor it on [agno.com](https://docs.agno.com/introduction/monitoring).
|
||||
|
||||
After that, checkout the [Examples Gallery](https://docs.agno.com/examples) and build real-world applications with Agno.
|
||||
|
||||
## Why Agno?
|
||||
|
||||
Agno will help you build best-in-class, highly-performant agentic systems, saving you hours of research and boilerplate. Here are some key features that set Agno apart:
|
||||
|
||||
- **Model Agnostic**: Agno provides a unified interface to 23+ model providers, no lock-in.
|
||||
- **Highly performant**: Agents instantiate in **~3μs** and use **~6.5Kib** memory on average.
|
||||
- **Reasoning is a first class citizen**: Reasoning improves reliability and is a must-have for complex autonomous agents. Agno supports 3 approaches to reasoning: Reasoning Models, `ReasoningTools` or our custom `chain-of-thought` approach.
|
||||
- **Natively Multi-Modal**: Agno Agents are natively multi-modal, they accept text, image, audio and video as input and generate text, image, audio and video as output.
|
||||
- **Advanced Multi-Agent Architecture**: Agno provides an industry leading multi-agent architecture (**Agent Teams**) with reasoning, memory, and shared context.
|
||||
- **Built-in Agentic Search**: Agents can search for information at runtime using 20+ vector databases. Agno provides state-of-the-art Agentic RAG, **fully async and highly performant.**
|
||||
- **Built-in Memory & Session Storage**: Agents come with built-in `Storage` & `Memory` drivers that give your Agents long-term memory and session storage.
|
||||
- **Structured Outputs**: Agno Agents can return fully-typed responses using model provided structured outputs or `json_mode`.
|
||||
- **Pre-built FastAPI Routes**: After building your Agents, serve them using pre-built FastAPI routes. 0 to production in minutes.
|
||||
- **Monitoring**: Monitor agent sessions and performance in real-time on [agno.com](https://app.agno.com).
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
pip install -U agno
|
||||
```
|
||||
|
||||
## Example - Reasoning Agent
|
||||
|
||||
Let's build a Reasoning Agent to get a sense of Agno's capabilities.
|
||||
|
||||
Save this code to a file: `reasoning_agent.py`.
|
||||
|
||||
```python
|
||||
from agno.agent import Agent
|
||||
from agno.models.anthropic import Claude
|
||||
from agno.tools.reasoning import ReasoningTools
|
||||
from agno.tools.yfinance import YFinanceTools
|
||||
from agno.tools.hackernews import HackerNewsTools
|
||||
|
||||
agent = Agent(
|
||||
model=Claude(id="claude-sonnet-4-20250514"),
|
||||
tools=[
|
||||
ReasoningTools(add_instructions=True),
|
||||
YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),
|
||||
],
|
||||
instructions=[
|
||||
"Use tables to display data",
|
||||
"Only output the report, no other text",
|
||||
],
|
||||
model=Claude(id="claude-sonnet-4-0"),
|
||||
tools=[HackerNewsTools()],
|
||||
markdown=True,
|
||||
)
|
||||
agent.print_response(
|
||||
"Write a report on NVDA",
|
||||
stream=True,
|
||||
show_full_reasoning=True,
|
||||
stream_intermediate_steps=True,
|
||||
)
|
||||
agent.print_response("Summarize the top 5 stories on hackernews", stream=True)
|
||||
```
|
||||
|
||||
Then create a virtual environment, install dependencies, export your `ANTHROPIC_API_KEY` and run the agent.
|
||||
But the real advantage of Agno is its [AgentOS](https://docs.agno.com/agent-os/introduction) runtime:
|
||||
|
||||
```shell
|
||||
uv venv --python 3.12
|
||||
source .venv/bin/activate
|
||||
1. You get a pre-built FastAPI app for running your agentic system, meaning you start building your product on day one. This is a remarkable advantage over other solutions or rolling your own.
|
||||
2. You also get a control plane which connects directly to your AgentOS for testing, monitoring and managing your system. This gives you unmatched visibility and control over your system.
|
||||
3. Your AgentOS runs in your cloud and you get complete data privacy because no data ever leaves your system. This is incredible for security conscious enterprises that can't send traces to external services.
|
||||
|
||||
uv pip install agno anthropic yfinance
|
||||
For organizations building agents, Agno provides the complete solution. You get the fastest framework for building agents (speed of development and execution), a pre-built FastAPI app that lets you build your product on day one, and a control plane for managing your system.
|
||||
|
||||
export ANTHROPIC_API_KEY=sk-ant-api03-xxxx
|
||||
We bring a novel architecture that no other framework provides, your AgentOS runs securely in your cloud, and the control plane connects directly to it from your browser. You don't need to send data to external services or pay retention costs, you get complete privacy and control.
|
||||
|
||||
python reasoning_agent.py
|
||||
```
|
||||
## Getting started
|
||||
|
||||
We can see the Agent is reasoning through the task, using the `ReasoningTools` and `YFinanceTools` to gather information. This is how the output looks like:
|
||||
If you're new to Agno, follow our [quickstart](https://docs.agno.com/introduction/quickstart) to build your first Agent and run it using the AgentOS.
|
||||
|
||||
https://github.com/user-attachments/assets/bbb99955-9848-49a9-9732-3e19d77b2ff8
|
||||
After that, checkout the [examples gallery](https://docs.agno.com/examples/introduction) and build real-world applications with Agno.
|
||||
|
||||
## Example - Multi Agent Teams
|
||||
## Documentation, Community & More examples
|
||||
|
||||
Agents are the atomic unit of work, and work best when they have a narrow scope and a small number of tools. When the number of tools grows beyond what the model can handle or you need to handle multiple concepts, use a team of agents to spread the load.
|
||||
- Docs: <a href="https://docs.agno.com" target="_blank" rel="noopener noreferrer">docs.agno.com</a>
|
||||
- Cookbook: <a href="https://github.com/agno-agi/agno/tree/main/cookbook" target="_blank" rel="noopener noreferrer">Cookbook</a>
|
||||
- Community forum: <a href="https://community.agno.com/" target="_blank" rel="noopener noreferrer">community.agno.com</a>
|
||||
- Discord: <a href="https://discord.gg/4MtYHHrgA8" target="_blank" rel="noopener noreferrer">discord</a>
|
||||
|
||||
```python
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
from agno.tools.duckduckgo import DuckDuckGoTools
|
||||
from agno.tools.yfinance import YFinanceTools
|
||||
from agno.team import Team
|
||||
## Setup your coding agent to use Agno
|
||||
|
||||
web_agent = Agent(
|
||||
name="Web Agent",
|
||||
role="Search the web for information",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[DuckDuckGoTools()],
|
||||
instructions="Always include sources",
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
For LLMs and AI assistants to understand and navigate Agno's documentation, we provide an [llms.txt](https://docs.agno.com/llms.txt) or [llms-full.txt](https://docs.agno.com/llms-full.txt) file.
|
||||
|
||||
finance_agent = Agent(
|
||||
name="Finance Agent",
|
||||
role="Get financial data",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
|
||||
instructions="Use tables to display data",
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
This file is built for AI systems to efficiently parse and reference our documentation.
|
||||
|
||||
agent_team = Team(
|
||||
mode="coordinate",
|
||||
members=[web_agent, finance_agent],
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
success_criteria="A comprehensive financial news report with clear sections and data-driven insights.",
|
||||
instructions=["Always include sources", "Use tables to display data"],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
### IDE Integration
|
||||
|
||||
agent_team.print_response("What's the market outlook and financial performance of AI semiconductor companies?", stream=True)
|
||||
```
|
||||
When building Agno agents, using Agno documentation as a source in your IDE is a great way to speed up your development. Here's how to integrate with Cursor:
|
||||
|
||||
Install dependencies and run the Agent team:
|
||||
1. In Cursor, go to the "Cursor Settings" menu.
|
||||
2. Find the "Indexing & Docs" section.
|
||||
3. Add `https://docs.agno.com/llms-full.txt` to the list of documentation URLs.
|
||||
4. Save the changes.
|
||||
|
||||
```shell
|
||||
pip install ddgs yfinance
|
||||
|
||||
python agent_team.py
|
||||
```
|
||||
|
||||
[View this example in the cookbook](./cookbook/getting_started/05_agent_team.py)
|
||||
Now, Cursor will have access to the Agno documentation. You can do the same with other IDEs like VSCode, Windsurf etc.
|
||||
|
||||
## Performance
|
||||
|
||||
At Agno, we're obsessed with performance. Why? because even simple AI workflows can spawn thousands of Agents. Scale that to a modest number of users and performance becomes a bottleneck. Agno is designed for building high performance agentic systems:
|
||||
At Agno, we're obsessed with performance. Why? because even simple AI workflows can spawn thousands of Agents. Scale that to a modest number of users and performance becomes a bottleneck. Agno is designed for building highly performant agentic systems:
|
||||
|
||||
- Agent instantiation: ~3μs on average
|
||||
- Memory footprint: ~6.5Kib on average
|
||||
@@ -226,33 +125,9 @@ Agno agents are designed for performance and while we do share some benchmarks a
|
||||
|
||||
Given that each framework is different and we won't be able to tune their performance like we do with Agno, for future benchmarks we'll only be comparing against ourselves.
|
||||
|
||||
## Complete Documentation Index
|
||||
|
||||
For LLMs and AI assistants to understand and navigate Agno's complete documentation, we provide an [LLMs.txt](https://docs.agno.com/llms.txt) or [LLMs-Full.txt](https://docs.agno.com/llms-full.txt) file.
|
||||
|
||||
This file is specifically formatted for AI systems to efficiently parse and reference our documentation.
|
||||
|
||||
### Cursor Setup
|
||||
|
||||
When building Agno agents, using Agno documentation as a source in Cursor is a great way to speed up your development.
|
||||
|
||||
1. In Cursor, go to the "Cursor Settings" menu.
|
||||
2. Find the "Indexing & Docs" section.
|
||||
3. Add `https://docs.agno.com/llms-full.txt` to the list of documentation URLs.
|
||||
4. Save the changes.
|
||||
|
||||
Now, Cursor will have access to the Agno documentation.
|
||||
|
||||
## Documentation, Community & More examples
|
||||
|
||||
- Docs: <a href="https://docs.agno.com" target="_blank" rel="noopener noreferrer">docs.agno.com</a>
|
||||
- Cookbook: <a href="https://github.com/agno-agi/agno/tree/main/cookbook" target="_blank" rel="noopener noreferrer">Cookbook</a>
|
||||
- Community forum: <a href="https://community.agno.com/" target="_blank" rel="noopener noreferrer">community.agno.com</a>
|
||||
- Discord: <a href="https://discord.gg/4MtYHHrgA8" target="_blank" rel="noopener noreferrer">discord</a>
|
||||
|
||||
## Contributions
|
||||
|
||||
We welcome contributions, read our [contributing guide](https://github.com/agno-agi/agno/blob/main/CONTRIBUTING.md) to get started.
|
||||
We welcome contributions, read our [contributing guide](https://github.com/agno-agi/agno/blob/v2.0/CONTRIBUTING.md) to get started.
|
||||
|
||||
## Telemetry
|
||||
|
||||
|
||||
+180
-20
@@ -1,40 +1,200 @@
|
||||
# Agno Cookbooks
|
||||
|
||||
Welcome to Agno's cookbook collection! Here you will find hundreds of examples on how to use the Agno framework to build what you want.
|
||||
|
||||
## Setup
|
||||
|
||||
### Create and activate a virtual environment
|
||||
|
||||
```shell
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
### Install libraries
|
||||
|
||||
```shell
|
||||
pip install -U openai agno # And all other packages you might need
|
||||
```
|
||||
|
||||
### Export your keys
|
||||
|
||||
```shell
|
||||
export OPENAI_API_KEY=***
|
||||
export GOOGLE_API_KEY=***
|
||||
```
|
||||
|
||||
## Run a cookbook
|
||||
|
||||
```shell
|
||||
python cookbook/.../example.py
|
||||
```
|
||||
|
||||
The full folder is organized in sections focused on a specific concept or features. These are the top level ones:
|
||||
|
||||
## Getting Started
|
||||
|
||||
The getting started guide walks through the basics of building with Agno. Cookbooks build on each other, introducing new concepts and capabilities.
|
||||
|
||||
## Agent Levels
|
||||
|
||||
Here you will find an introduction to Agents and to what they can do. Each level introduces a chore feature or abstractions for your AI system:
|
||||
|
||||
The getting started guide walks through the basics of building Agents with Agno. Recipes build on each other, introducing new concepts and capabilities.
|
||||
1. Agent with tools and instructions
|
||||
2. Agent with knowledge and storage
|
||||
3. Agent with memory and reasoning
|
||||
4. A Team of Agents
|
||||
5. A Workflow
|
||||
|
||||
## Agent Concepts
|
||||
## Agents From Scratch
|
||||
|
||||
The concepts cookbook walks through the core concepts of Agno.
|
||||
Focused examples to showcase some of the main features you can use with Agno Agents:
|
||||
|
||||
- [Async](./agent_concepts/async)
|
||||
- [RAG](./agent_concepts/rag)
|
||||
- [Knowledge](./agent_concepts/knowledge)
|
||||
- [Memory](./agent_concepts/memory)
|
||||
- [Storage](storage)
|
||||
- [Tools](./tools)
|
||||
- [Reasoning](./reasoning)
|
||||
- [Vector DBs](./agent_concepts/knowledge/vector_dbs)
|
||||
- [Multi-modal Agents](./agent_concepts/multimodal)
|
||||
- [Agent Teams](./teams)
|
||||
- [Other](./agent_concepts/other)
|
||||
- Knowledge
|
||||
- Storage
|
||||
- Tools
|
||||
|
||||
## Agents
|
||||
|
||||
A more complete set of cookbooks related to Agno Agents. Here you will find more specific and advanced examples of what Agno Agents can do:
|
||||
|
||||
- Agentic search: using RAG with an Agent
|
||||
- Async: running Agents asynchronously
|
||||
- Db: features related to long term storage
|
||||
- Dependencies: adding logic that runs when the Agent does
|
||||
- Events: handling events when streaming an Agent response
|
||||
- Human in the loop: everything about our HITL flows
|
||||
- Memory: a complete guide on User Memories
|
||||
- Multimodal: handling media with your Agents
|
||||
- Other: more examples of some of our features
|
||||
- RAG: guide on using RAG with your Agents
|
||||
- Session: guide on interacting with the current and previous Sessions
|
||||
- State: examples on handling Session state data
|
||||
- Tool concepts: comprehensive set of examples of Agents using Agno ToolKits and custom Tools
|
||||
|
||||
## Db
|
||||
|
||||
In this section you can see examples on how to use all our Db implementations with your Agents. These are all the supported ones:
|
||||
|
||||
- PostgresDB
|
||||
- SqliteDB
|
||||
- MongoDB
|
||||
- MySQL
|
||||
- Redis
|
||||
- SingleStore
|
||||
- FireStore
|
||||
- JSON files
|
||||
- GCS with JSON files
|
||||
|
||||
## Evals
|
||||
|
||||
Section focused on evaluating your Agno Agents and Teams across three key dimensions:
|
||||
|
||||
- Accuracy: How complete/correct/accurate is the Agent’s response (LLM-as-a-judge)
|
||||
- Performance: How fast does the Agent respond and what’s the memory footprint?
|
||||
- Reliability: Does the Agent make the expected tool calls?
|
||||
|
||||
## Examples
|
||||
|
||||
Collection of real world examples you can build using Agno Agents, Teams and Workflows.
|
||||
|
||||
## Integrations
|
||||
|
||||
Examples for some of the main integrations you can use with your Agno code.
|
||||
|
||||
## Knowledge
|
||||
|
||||
Knowledge is the way to provide your Agents with information they can search at runtime to make better decisions and generate better answers.
|
||||
|
||||
The examples cookbook contains real world examples of building agents with Agno.
|
||||
In this section you will find a comprehensive list of examples on how to manage your Knowledge setup, what sources are available, what databases can be used, etc.
|
||||
|
||||
## Playground
|
||||
## Memory
|
||||
|
||||
The playground cookbook contains examples of interacting with agents using the Agno Agent UI.
|
||||
An Agent can store insights and facts about users that it learns through conversations with them. This is great to personalize responses!
|
||||
|
||||
## Workflows
|
||||
Here you will find a guide to learn how Memory is setup and how much your Agent can do with it.
|
||||
|
||||
## Models
|
||||
|
||||
Models are the brain of Agno Agents. In this folder you will find specific examples for each of the Models we support:
|
||||
|
||||
- AI/ML API
|
||||
- Anthropic
|
||||
- AWS Bedrock
|
||||
- Azure AI Foundry
|
||||
- Claude via AWS Bedrock
|
||||
- Cohere
|
||||
- DeepSeek
|
||||
- Fireworks
|
||||
- Google Gemini
|
||||
- Groq
|
||||
- Hugging Face
|
||||
- LiteLLM
|
||||
- Mistral
|
||||
- NVIDIA
|
||||
- Nebius AI Studio
|
||||
- Ollama
|
||||
- OpenAI
|
||||
- OpenAI Like
|
||||
- OpenAI via Azure
|
||||
- OpenRouter
|
||||
- Perplexity
|
||||
- Sambanova
|
||||
- Together
|
||||
- vLLM
|
||||
- xAI
|
||||
- LangDB
|
||||
|
||||
## Reasoning
|
||||
|
||||
Reasoning gives Agents the ability to plan before acting, and to analyze results after having generated them. This can greatly improve an Agent's capacity to solve problems. There are three ways to use reasoning:
|
||||
|
||||
### Reasoning models
|
||||
|
||||
Some models are pre-trained to reasoning. The most popular reasoning models are available for your Agno Agents out of the box.
|
||||
|
||||
See the [examples](./models/).
|
||||
|
||||
### Reasoning tools
|
||||
|
||||
You can give your Agent tools that enable reasoning. This is the simplest way to achieve reasoning.
|
||||
|
||||
See the [examples](./tools/).
|
||||
|
||||
### Reasoning Agents
|
||||
|
||||
Reasoning Agents are a new type of multi-agent system developed by Agno that combines chain of thought reasoning with tool use.
|
||||
|
||||
You can enable reasoning on any Agent by setting reasoning=True.
|
||||
|
||||
When an Agent with reasoning=True is given a task, a separate “Reasoning Agent” first solves the problem using chain-of-thought. At each step, it calls tools to gather information, validate results, and iterate until it reaches a final answer. Once the Reasoning Agent has a final answer, it hands the results back to the original Agent to validate and provide a response.
|
||||
|
||||
See the [examples](./agents/).
|
||||
|
||||
The workflows cookbook contains examples of building workflows with Agno.
|
||||
|
||||
## Scripts
|
||||
|
||||
Some utility scripts to make your work with Agno easier.
|
||||
|
||||
## Teams
|
||||
|
||||
A Team is a collection of Agents (or other sub-teams) that work together to accomplish tasks. They are the main abstraction piece in the Agno framework after Agents.
|
||||
|
||||
You can find a comprehensive set of examples in this folder, divided by the main features you can use with your Teams.
|
||||
|
||||
## Tools
|
||||
|
||||
Tools are utilities that allow Agents to perform tasks. Think searching the web, running SQL, sending emails or calling APIs.
|
||||
|
||||
In this folder you will find examples for some of our ToolKits. An Agno ToolKit is the simplest way to give tools to your Agents and works out of the box.
|
||||
|
||||
You can also find examples to learn how to use custom tools, for any functionality we don't support out of the box yet.
|
||||
|
||||
## Workflows
|
||||
|
||||
Agno Workflows are designed to automate complex processes by defining a series of steps that are executed in sequence. Each step can be executed by an agent, a team, or a custom function.
|
||||
|
||||
Just a place to store setup scripts like `run_pgvector.sh` etc
|
||||
Workflows are our higher-level abstraction, and are useful to build complex AI systems. In this folder you will find a comprehensive guide showcasing what are the building blocks of Workflows and how much can be achieved using them.
|
||||
|
||||
## Setup
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
*.jpg
|
||||
*.png
|
||||
*.mp3
|
||||
*.wav
|
||||
*.mp4
|
||||
*.mp3
|
||||
@@ -1,78 +0,0 @@
|
||||
# Agent Concepts
|
||||
|
||||
Application of several agent concepts using Agno.
|
||||
|
||||
## Overview
|
||||
|
||||
### Async
|
||||
|
||||
Async refers to agents built with `async def` support, allowing them to seamlessly integrate into asynchronous Python applications. While async agents are not inherently parallel, they allow better handling of I/O-bound operations, improving responsiveness in Python apps.
|
||||
|
||||
For examples of using async agents, see /cookbook/agent_concepts/async/.
|
||||
|
||||
### Hybrid Search
|
||||
|
||||
Hybrid Search combines multiple search paradigms—such as vector similarity search and traditional keyword-based search—to retrieve the most relevant results for a given query. This approach ensures that agents can find both semantically similar results and exact keyword matches, improving accuracy and context-awareness in diverse use cases.
|
||||
|
||||
Hybrid search examples can be found under `/cookbook/agent_concepts/hybrid_search/`
|
||||
|
||||
### Knowledge
|
||||
|
||||
Agents use a knowledge base to supplement their training data with domain expertise.
|
||||
Knowledge is stored in a vector database and provides agents with business context at query time, helping them respond in a context-aware manner.
|
||||
|
||||
Examples of Agents with knowledge can be found under `/cookbook/agent_concepts/knowledge/`
|
||||
|
||||
### Memory
|
||||
|
||||
Agno provides 3 types of memory for Agents:
|
||||
|
||||
1. Chat History: The message history of the session. Agno will store the sessions in a database for you, and retrieve them when you resume a session.
|
||||
2. User Memories: Notes and insights about the user, this helps the model personalize the response to the user.
|
||||
3. Summaries: A summary of the conversation, which is added to the prompt when chat history gets too long.
|
||||
|
||||
Examples of Agents using different memory types can be found under `/cookbook/agent_concepts/memory/`
|
||||
|
||||
### Multimodal
|
||||
|
||||
In addition to text, Agno agents support image, audio, and video inputs and can generate image and audio outputs.
|
||||
|
||||
Examples with multimodal input and outputs using Agno can be found under `/cookbook/agent_concepts/storage/`
|
||||
|
||||
### RAG
|
||||
|
||||
RAG (Retrieval-Augmented Generation) integrates external data sources with AI's generation processes to produce context-aware, accurate, and relevant responses. It leverages vector databases for retrieved information and enhances agent memory components like chat history and summaries to provide coherent and informed answers.
|
||||
|
||||
Examples of agentic RAG can be found under `/cookbook/agent_concepts/rag/`
|
||||
|
||||
### Reasoning
|
||||
|
||||
Reasoning is an *experimental feature* that enables an Agent to think through a problem step-by-step before jumping into a response. The Agent works through different ideas, validating and correcting as needed. Once it reaches a final answer, it will validate and provide a response.
|
||||
|
||||
Examples of agentic shwowing their reasoning can be found under `/cookbook/agent_concepts/reasoning/`
|
||||
|
||||
### Storage
|
||||
|
||||
Agents use storage to persist sessions and session state by storing them in a database.
|
||||
|
||||
Agents come with built-in memory, but it only lasts while the session is active. To continue conversations across sessions, we store agent sessions in a database like Sqllite or PostgreSQL.
|
||||
|
||||
Examples of using storage with Agno agents can be found under `/cookbook/agent_concepts/storage/`
|
||||
|
||||
### Teams
|
||||
|
||||
Multiple agents can be combined to form a team and complete complicated tasks as a cohesive unit.
|
||||
|
||||
Examples of using agent teams with Agno can be found under `/cookbook/agent_concepts/teams/`
|
||||
|
||||
### Tools
|
||||
|
||||
Agents use tools to take actions and interact with external systems. A tool is a function that an Agent can use to achieve a task. For example: searching the web, running SQL, sending an email or calling APIs.
|
||||
|
||||
Examples of using tools with Agno agents can be found under `/cookbook/agent_concepts/tools/`
|
||||
|
||||
### Vector DB's
|
||||
|
||||
Vector databases enable us to store information as embeddings and search for “results similar” to our input query using cosine similarity or full text search. These results are then provided to the Agent as context so it can respond in a context-aware manner using Retrieval Augmented Generation (RAG).
|
||||
|
||||
Examples of using vector databases with Agno can be found under `/cookbook/agent_concepts/vector_dbs/`
|
||||
@@ -1,46 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.light_rag import LightRagKnowledgeBase, lightrag_retriever
|
||||
from agno.models.anthropic import Claude
|
||||
|
||||
# Create a knowledge base, loaded with documents from a URL
|
||||
knowledge_base = LightRagKnowledgeBase(
|
||||
lightrag_server_url="http://localhost:9621",
|
||||
path="tmp/", # Load documents from a local directory
|
||||
urls=["https://docs.agno.com/introduction/agents.md"], # Load documents from a URL
|
||||
)
|
||||
|
||||
# Load the knowledge base with the documents from the local directory and the URL
|
||||
asyncio.run(knowledge_base.load())
|
||||
|
||||
# Load the knowledge base with the text
|
||||
asyncio.run(
|
||||
knowledge_base.load_text(text="Dogs and cats are not pets, they are friends.")
|
||||
)
|
||||
|
||||
|
||||
# Create an agent with the knowledge base and the retriever
|
||||
agent = Agent(
|
||||
model=Claude(id="claude-3-7-sonnet-latest"),
|
||||
# Agentic RAG is enabled by default when `knowledge` is provided to the Agent.
|
||||
knowledge=knowledge_base,
|
||||
retriever=lightrag_retriever,
|
||||
# search_knowledge=True gives the Agent the ability to search on demand
|
||||
# search_knowledge is True by default
|
||||
search_knowledge=True,
|
||||
instructions=[
|
||||
"Include sources in your response.",
|
||||
"Always search your knowledge before answering the question.",
|
||||
"Use the async_search method to search the knowledge base.",
|
||||
],
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Which candidates are available for the role of a Senior Software Engineer?"
|
||||
)
|
||||
)
|
||||
asyncio.run(agent.aprint_response("What are Agno Agents?"))
|
||||
@@ -1,13 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
|
||||
agent = Agent(
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
description="You help people with their health and fitness goals.",
|
||||
instructions=["Recipes should be under 5 ingredients"],
|
||||
markdown=True,
|
||||
)
|
||||
# -*- Print a response to the cli
|
||||
asyncio.run(agent.aprint_response("Share a breakfast recipe."))
|
||||
@@ -1,13 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
|
||||
agent = Agent(
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
description="You help people with their health and fitness goals.",
|
||||
instructions=["Recipes should be under 5 ingredients"],
|
||||
markdown=True,
|
||||
)
|
||||
# -*- Print a response to the cli
|
||||
asyncio.run(agent.aprint_response("Share a breakfast recipe.", stream=True))
|
||||
@@ -1,57 +0,0 @@
|
||||
import json
|
||||
from textwrap import dedent
|
||||
|
||||
import httpx
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
|
||||
|
||||
def get_top_hackernews_stories(num_stories: int = 5) -> str:
|
||||
"""Fetch and return the top stories from HackerNews.
|
||||
|
||||
Args:
|
||||
num_stories: Number of top stories to retrieve (default: 5)
|
||||
Returns:
|
||||
JSON string containing story details (title, url, score, etc.)
|
||||
"""
|
||||
# Get top stories
|
||||
stories = [
|
||||
{
|
||||
k: v
|
||||
for k, v in httpx.get(
|
||||
f"https://hacker-news.firebaseio.com/v0/item/{id}.json"
|
||||
)
|
||||
.json()
|
||||
.items()
|
||||
if k != "kids" # Exclude discussion threads
|
||||
}
|
||||
for id in httpx.get(
|
||||
"https://hacker-news.firebaseio.com/v0/topstories.json"
|
||||
).json()[:num_stories]
|
||||
]
|
||||
return json.dumps(stories, indent=4)
|
||||
|
||||
|
||||
# Create a Context-Aware Agent that can access real-time HackerNews data
|
||||
agent = Agent(
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
# Each function in the context is evaluated at runtime
|
||||
context={"top_hackernews_stories": get_top_hackernews_stories},
|
||||
# Alternatively, you can manually add the context to the instructions
|
||||
instructions=dedent("""\
|
||||
You are an insightful tech trend observer! 📰
|
||||
|
||||
Here are the top stories on HackerNews:
|
||||
{top_hackernews_stories}\
|
||||
"""),
|
||||
# add_state_in_messages will make the `top_hackernews_stories` variable
|
||||
# available in the instructions
|
||||
add_state_in_messages=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Example usage
|
||||
agent.print_response(
|
||||
"Summarize the top stories on HackerNews and identify any interesting trends.",
|
||||
stream=True,
|
||||
)
|
||||
@@ -1,36 +0,0 @@
|
||||
import json
|
||||
from textwrap import dedent
|
||||
|
||||
import httpx
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
|
||||
|
||||
def get_upcoming_spacex_launches(num_launches: int = 5) -> str:
|
||||
url = "https://api.spacexdata.com/v5/launches/upcoming"
|
||||
launches = httpx.get(url).json()
|
||||
launches = sorted(launches, key=lambda x: x["date_unix"])[:num_launches]
|
||||
return json.dumps(launches, indent=4)
|
||||
|
||||
|
||||
# Create an Agent that has access to real-time SpaceX data
|
||||
agent = Agent(
|
||||
model=OpenAIChat(id="gpt-4.1"),
|
||||
# Each function in the context is evaluated at runtime
|
||||
context={"upcoming_spacex_launches": get_upcoming_spacex_launches},
|
||||
description=dedent("""\
|
||||
You are a cosmic analyst and spaceflight enthusiast. 🚀
|
||||
|
||||
Here are the next SpaceX launches:
|
||||
{upcoming_spacex_launches}\
|
||||
"""),
|
||||
# add_state_in_messages will make the `upcoming_spacex_launches` variable
|
||||
# available in the description and instructions
|
||||
add_state_in_messages=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Tell me about the upcoming SpaceX missions.",
|
||||
stream=True,
|
||||
)
|
||||
@@ -1,49 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import RunEvent
|
||||
from agno.agent.agent import Agent
|
||||
from agno.models.openai.chat import OpenAIChat
|
||||
from agno.tools.yfinance import YFinanceTools
|
||||
|
||||
finance_agent = Agent(
|
||||
agent_id="finance-agent",
|
||||
name="Finance Agent",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[YFinanceTools()],
|
||||
)
|
||||
|
||||
|
||||
async def run_agent_with_events(prompt: str):
|
||||
content_started = False
|
||||
async for run_response_event in await finance_agent.arun(
|
||||
prompt,
|
||||
stream=True,
|
||||
stream_intermediate_steps=True,
|
||||
):
|
||||
if run_response_event.event in [RunEvent.run_started, RunEvent.run_completed]:
|
||||
print(f"\nEVENT: {run_response_event.event}")
|
||||
|
||||
if run_response_event.event in [RunEvent.tool_call_started]:
|
||||
print(f"\nEVENT: {run_response_event.event}")
|
||||
print(f"TOOL CALL: {run_response_event.tool.tool_name}")
|
||||
print(f"TOOL CALL ARGS: {run_response_event.tool.tool_args}")
|
||||
|
||||
if run_response_event.event in [RunEvent.tool_call_completed]:
|
||||
print(f"\nEVENT: {run_response_event.event}")
|
||||
print(f"TOOL CALL: {run_response_event.tool.tool_name}")
|
||||
print(f"TOOL CALL RESULT: {run_response_event.tool.result}")
|
||||
|
||||
if run_response_event.event in [RunEvent.run_response_content]:
|
||||
if not content_started:
|
||||
print("\nCONTENT:")
|
||||
content_started = True
|
||||
else:
|
||||
print(run_response_event.content, end="")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(
|
||||
run_agent_with_events(
|
||||
"What is the price of Apple stock?",
|
||||
)
|
||||
)
|
||||
@@ -1,58 +0,0 @@
|
||||
# Agent Knowledge
|
||||
|
||||
**Knowledge Base:** is information that the Agent can search to improve its responses. This directory contains a series of cookbooks that demonstrate how to build a knowledge base for the Agent.
|
||||
|
||||
> Note: Fork and clone this repository if needed
|
||||
|
||||
### 1. Create a virtual environment
|
||||
|
||||
```shell
|
||||
python3 -m venv ~/.venvs/aienv
|
||||
source ~/.venvs/aienv/bin/activate
|
||||
```
|
||||
|
||||
### 2. Install libraries
|
||||
|
||||
```shell
|
||||
pip install -U pgvector "psycopg[binary]" sqlalchemy openai agno
|
||||
```
|
||||
|
||||
### 3. Run PgVector
|
||||
|
||||
> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first.
|
||||
|
||||
- Run using a helper script
|
||||
|
||||
```shell
|
||||
./cookbook/scripts/run_pgvector.sh
|
||||
```
|
||||
|
||||
- OR run using the docker run command
|
||||
|
||||
```shell
|
||||
docker run -d \
|
||||
-e POSTGRES_DB=ai \
|
||||
-e POSTGRES_USER=ai \
|
||||
-e POSTGRES_PASSWORD=ai \
|
||||
-e PGDATA=/var/lib/postgresql/data/pgdata \
|
||||
-v pgvolume:/var/lib/postgresql/data \
|
||||
-p 5532:5432 \
|
||||
--name pgvector \
|
||||
agnohq/pgvector:16
|
||||
```
|
||||
|
||||
### 4. Test Knowledge Cookbooks
|
||||
|
||||
Eg: PDF URL Knowledge Base
|
||||
|
||||
- Install libraries
|
||||
|
||||
```shell
|
||||
pip install -U pypdf bs4
|
||||
```
|
||||
|
||||
- Run the PDF URL script
|
||||
|
||||
```shell
|
||||
python cookbook/agent_concepts/knowledge/pdf_url.py
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.arxiv import ArxivKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the ArXiv documents
|
||||
knowledge_base = ArxivKnowledgeBase(
|
||||
queries=["Generative AI", "Machine Learning"],
|
||||
# Table name: ai.arxiv_documents
|
||||
vector_db=PgVector(
|
||||
table_name="arxiv_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
agent.print_response(
|
||||
"Ask me about generative ai from the knowledge base", markdown=True
|
||||
)
|
||||
@@ -1,31 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.arxiv import ArxivKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "arxive-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Create a knowledge base with the ArXiv documents
|
||||
knowledge_base = ArxivKnowledgeBase(
|
||||
queries=["Generative AI", "Machine Learning"], vector_db=vector_db
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Ask me about generative ai from the knowledge base", markdown=True
|
||||
)
|
||||
)
|
||||
@@ -1,20 +0,0 @@
|
||||
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) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,30 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.document.chunking.row import RowChunking
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
urls=[
|
||||
"https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
|
||||
],
|
||||
vector_db=PgVector(
|
||||
table_name="imdb_movies_row_chunking",
|
||||
db_url=db_url,
|
||||
),
|
||||
chunking_strategy=RowChunking(),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Use the agent
|
||||
agent.print_response("Tell me about the movie Guardians of the Galaxy", markdown=True)
|
||||
@@ -1,18 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
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", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,20 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document.chunking.document import DocumentChunking
|
||||
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_document_chunking", db_url=db_url),
|
||||
chunking_strategy=DocumentChunking(),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,20 +0,0 @@
|
||||
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) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,20 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document.chunking.recursive import RecursiveChunking
|
||||
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_recursive_chunking", db_url=db_url),
|
||||
chunking_strategy=RecursiveChunking(),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,20 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document.chunking.semantic import SemanticChunking
|
||||
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_semantic_chunking", db_url=db_url),
|
||||
chunking_strategy=SemanticChunking(similarity_threshold=0.5),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,73 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.combined import CombinedKnowledgeBase
|
||||
from agno.knowledge.csv import CSVKnowledgeBase
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.knowledge.website import WebsiteKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create CSV knowledge base
|
||||
csv_kb = CSVKnowledgeBase(
|
||||
path=Path("data/csvs"),
|
||||
vector_db=PgVector(
|
||||
table_name="csv_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create PDF URL knowledge base
|
||||
pdf_url_kb = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create Website knowledge base
|
||||
website_kb = WebsiteKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
max_links=10,
|
||||
vector_db=PgVector(
|
||||
table_name="website_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create Local PDF knowledge base
|
||||
local_pdf_kb = PDFKnowledgeBase(
|
||||
path="data/pdfs",
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Combine knowledge bases
|
||||
knowledge_base = CombinedKnowledgeBase(
|
||||
sources=[
|
||||
csv_kb,
|
||||
pdf_url_kb,
|
||||
website_kb,
|
||||
local_pdf_kb,
|
||||
],
|
||||
vector_db=PgVector(
|
||||
table_name="combined_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Initialize the Agent with the combined knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Use the agent
|
||||
agent.print_response("Ask me about something from the knowledge base", markdown=True)
|
||||
@@ -1,80 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.combined import CombinedKnowledgeBase
|
||||
from agno.knowledge.csv import CSVKnowledgeBase
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.knowledge.website import WebsiteKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create CSV knowledge base
|
||||
csv_kb = CSVKnowledgeBase(
|
||||
path=Path("data/csvs"),
|
||||
vector_db=PgVector(
|
||||
table_name="csv_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create PDF URL knowledge base
|
||||
pdf_url_kb = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create Website knowledge base
|
||||
website_kb = WebsiteKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
max_links=10,
|
||||
vector_db=PgVector(
|
||||
table_name="website_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Create Local PDF knowledge base
|
||||
local_pdf_kb = PDFKnowledgeBase(
|
||||
path="data/pdfs",
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Combine knowledge bases
|
||||
knowledge_base = CombinedKnowledgeBase(
|
||||
sources=[
|
||||
csv_kb,
|
||||
pdf_url_kb,
|
||||
website_kb,
|
||||
local_pdf_kb,
|
||||
],
|
||||
vector_db=PgVector(
|
||||
table_name="combined_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
# Initialize the Agent with the combined knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Ask me about something from the knowledge base", markdown=True
|
||||
)
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv import CSVKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = CSVKnowledgeBase(
|
||||
path=Path("data/csvs"),
|
||||
vector_db=PgVector(
|
||||
table_name="csv_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Use the agent
|
||||
agent.print_response("Ask me about something from the knowledge base", markdown=True)
|
||||
@@ -1,30 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv import CSVKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "csv-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
|
||||
knowledge_base = CSVKnowledgeBase(
|
||||
path=Path("data/csv"),
|
||||
vector_db=vector_db,
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("What is the csv file about", markdown=True))
|
||||
@@ -1,21 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/csvs/employees.csv"],
|
||||
vector_db=PgVector(table_name="csv_documents", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"What is the average salary of employees in the Marketing department?",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,31 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "csv-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv"],
|
||||
vector_db=vector_db,
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(
|
||||
agent.aprint_response("What genre of movies are present here?", markdown=True)
|
||||
)
|
||||
@@ -1,54 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.document.base import Document
|
||||
from agno.knowledge.document import DocumentKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
fun_facts = """
|
||||
- Earth is the third planet from the Sun and the only known astronomical object to support life.
|
||||
- Approximately 71% of Earth's surface is covered by water, with the Pacific Ocean being the largest.
|
||||
- The Earth's atmosphere is composed mainly of nitrogen (78%) and oxygen (21%), with traces of other gases.
|
||||
- Earth rotates on its axis once every 24 hours, leading to the cycle of day and night.
|
||||
- The planet has one natural satellite, the Moon, which influences tides and stabilizes Earth's axial tilt.
|
||||
- Earth's tectonic plates are constantly shifting, leading to geological activities like earthquakes and volcanic eruptions.
|
||||
- The highest point on Earth is Mount Everest, standing at 8,848 meters (29,029 feet) above sea level.
|
||||
- The deepest part of the ocean is the Mariana Trench, reaching depths of over 11,000 meters (36,000 feet).
|
||||
- Earth has a diverse range of ecosystems, from rainforests and deserts to coral reefs and tundras.
|
||||
- The planet's magnetic field protects life by deflecting harmful solar radiation and cosmic rays.
|
||||
"""
|
||||
|
||||
|
||||
# Load documents from the data/docs directory
|
||||
documents = [Document(content=fun_facts)]
|
||||
|
||||
# Database connection URL
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the loaded documents
|
||||
knowledge_base = DocumentKnowledgeBase(
|
||||
documents=documents,
|
||||
vector_db=PgVector(
|
||||
table_name="documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
# Load the knowledge base
|
||||
await knowledge_base.aload(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
await agent.aprint_response(
|
||||
"Ask me about something from the knowledge base about earth", markdown=True
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,27 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.docx import DocxKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the DOCX files from the data/docs directory
|
||||
knowledge_base = DocxKnowledgeBase(
|
||||
path=Path("tmp/docs"),
|
||||
vector_db=PgVector(
|
||||
table_name="docx_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
agent.print_response("What docs do you have in your knowledge base?", markdown=True)
|
||||
@@ -1,31 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.docx import DocxKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb, SearchType
|
||||
|
||||
# Create a knowledge base with the DOCX files from the data/docs directory
|
||||
knowledge_base = DocxKnowledgeBase(
|
||||
path=Path("tmp/docs"),
|
||||
vector_db=LanceDb(
|
||||
uri="tmp/lancedb",
|
||||
table_name="docx_reader",
|
||||
search_type=SearchType.hybrid,
|
||||
),
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"What docs do you have in your knowledge base?", markdown=True
|
||||
)
|
||||
)
|
||||
@@ -1,57 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with URLs and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include cuisine type, source, region, or any other attributes
|
||||
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
urls=[
|
||||
{
|
||||
"url": "https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_1.csv",
|
||||
"metadata": {
|
||||
"data_type": "sales",
|
||||
"quarter": "Q1",
|
||||
"year": 2024,
|
||||
"region": "north_america",
|
||||
"currency": "USD",
|
||||
},
|
||||
},
|
||||
{
|
||||
"url": "https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_2.csv",
|
||||
"metadata": {
|
||||
"data_type": "sales",
|
||||
"year": 2024,
|
||||
"region": "europe",
|
||||
"currency": "EUR",
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Tell me about revenue performance and top selling products for region 'north_america' and data_type 'sales'",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,59 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with URLs and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include cuisine type, source, region, or any other attributes
|
||||
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
urls=[
|
||||
{
|
||||
"url": "https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_1.csv",
|
||||
"metadata": {
|
||||
"data_type": "sales",
|
||||
"quarter": "Q1",
|
||||
"year": 2024,
|
||||
"region": "north_america",
|
||||
"currency": "USD",
|
||||
},
|
||||
},
|
||||
{
|
||||
"url": "https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_2.csv",
|
||||
"metadata": {
|
||||
"data_type": "sales",
|
||||
"year": 2024,
|
||||
"region": "europe",
|
||||
"currency": "EUR",
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"region": "north_america", "data_type": "sales"},
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Revenue performance and top selling products",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,53 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize knowledge base
|
||||
knowledge_base = CSVUrlKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
url="https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_1.csv",
|
||||
metadata={
|
||||
"data_type": "sales",
|
||||
"quarter": "Q1",
|
||||
"year": 2024,
|
||||
"region": "north_america",
|
||||
"currency": "USD",
|
||||
},
|
||||
recreate=False, # only use at the first run, True/False
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
url="https://agno-public.s3.us-east-1.amazonaws.com/demo_data/filters/filters_2.csv",
|
||||
metadata={
|
||||
"data_type": "sales",
|
||||
"year": 2024,
|
||||
"region": "europe",
|
||||
"currency": "EUR",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"region": "north_america", "data_type": "sales"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Revenue performance and top selling products",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,110 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document import Document
|
||||
from agno.knowledge.document import DocumentKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="documents",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Create sample documents with different metadata
|
||||
sample_documents = [
|
||||
Document(
|
||||
name="user_profile_jordan",
|
||||
id="doc_1",
|
||||
content="Jordan Mitchell is a Senior Software Engineer with 8 years of experience in full-stack development. Expertise in Python, JavaScript, React, and Node.js. Led multiple projects and mentored junior developers.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_taylor",
|
||||
id="doc_2",
|
||||
content="Taylor Brooks is a Product Manager with 5 years of experience in agile development and product strategy. Skilled in user research, roadmap planning, and cross-functional team leadership.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_morgan",
|
||||
id="doc_3",
|
||||
content="Morgan Lee is a UX Designer with 6 years of experience in user interface design and user experience research. Proficient in Figma, Adobe Creative Suite, and user testing methodologies.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_remote",
|
||||
id="doc_4",
|
||||
content="Remote Work Policy: Employees are allowed to work from home up to 3 days per week. All remote work must be approved by direct supervisor and requires secure VPN connection.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_vacation",
|
||||
id="doc_5",
|
||||
content="Vacation Policy: Full-time employees accrue 2.5 days of vacation per month. Maximum accrual is 30 days. Vacation requests must be submitted at least 2 weeks in advance.",
|
||||
),
|
||||
]
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach additional metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = DocumentKnowledgeBase(
|
||||
documents=[
|
||||
{
|
||||
"document": sample_documents[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[3],
|
||||
"metadata": {
|
||||
"created_by": "hr_department",
|
||||
"year": 2025,
|
||||
"status": "current",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[4],
|
||||
"metadata": {
|
||||
"created_by": "hr_department",
|
||||
"year": 2025,
|
||||
"status": "current",
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills with user_id jordan_mitchell",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,110 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document import Document
|
||||
from agno.knowledge.document import DocumentKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="documents",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Create sample documents with different metadata
|
||||
sample_documents = [
|
||||
Document(
|
||||
name="user_profile_jordan",
|
||||
id="doc_1",
|
||||
content="Jordan Mitchell is a Senior Software Engineer with 8 years of experience in full-stack development. Expertise in Python, JavaScript, React, and Node.js. Led multiple projects and mentored junior developers.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_taylor",
|
||||
id="doc_2",
|
||||
content="Taylor Brooks is a Product Manager with 5 years of experience in agile development and product strategy. Skilled in user research, roadmap planning, and cross-functional team leadership.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_morgan",
|
||||
id="doc_3",
|
||||
content="Morgan Lee is a UX Designer with 6 years of experience in user interface design and user experience research. Proficient in Figma, Adobe Creative Suite, and user testing methodologies.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_remote",
|
||||
id="doc_4",
|
||||
content="Remote Work Policy: Employees are allowed to work from home up to 3 days per week. All remote work must be approved by direct supervisor and requires secure VPN connection.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_vacation",
|
||||
id="doc_5",
|
||||
content="Vacation Policy: Full-time employees accrue 2.5 days of vacation per month. Maximum accrual is 30 days. Vacation requests must be submitted at least 2 weeks in advance.",
|
||||
),
|
||||
]
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach additional metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = DocumentKnowledgeBase(
|
||||
documents=[
|
||||
{
|
||||
"document": sample_documents[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"year": 2025,
|
||||
"status": "active",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[3],
|
||||
"metadata": {
|
||||
"created_by": "hr_department",
|
||||
"year": 2025,
|
||||
"status": "current",
|
||||
},
|
||||
},
|
||||
{
|
||||
"document": sample_documents[4],
|
||||
"metadata": {
|
||||
"created_by": "hr_department",
|
||||
"year": 2025,
|
||||
"status": "current",
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,96 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.document import Document
|
||||
from agno.knowledge.document import DocumentKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="documents",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Create sample documents with different metadata
|
||||
sample_documents = [
|
||||
Document(
|
||||
name="user_profile_jordan",
|
||||
id="doc_1",
|
||||
content="Jordan Mitchell is a Senior Software Engineer with 8 years of experience in full-stack development. Expertise in Python, JavaScript, React, and Node.js. Led multiple projects and mentored junior developers.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_taylor",
|
||||
id="doc_2",
|
||||
content="Taylor Brooks is a Product Manager with 5 years of experience in agile development and product strategy. Skilled in user research, roadmap planning, and cross-functional team leadership.",
|
||||
),
|
||||
Document(
|
||||
name="user_profile_morgan",
|
||||
id="doc_3",
|
||||
content="Morgan Lee is a UX Designer with 6 years of experience in user interface design and user experience research. Proficient in Figma, Adobe Creative Suite, and user testing methodologies.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_remote",
|
||||
id="doc_4",
|
||||
content="Remote Work Policy: Employees are allowed to work from home up to 3 days per week. All remote work must be approved by direct supervisor and requires secure VPN connection.",
|
||||
),
|
||||
Document(
|
||||
name="company_policy_vacation",
|
||||
id="doc_5",
|
||||
content="Vacation Policy: Full-time employees accrue 2.5 days of vacation per month. Maximum accrual is 30 days. Vacation requests must be submitted at least 2 weeks in advance.",
|
||||
),
|
||||
]
|
||||
|
||||
# Step 1: Initialize knowledge base and load documents with metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize the DocumentKnowledgeBase
|
||||
knowledge_base = DocumentKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
# Load first document with Jordan Mitchell metadata
|
||||
knowledge_base.load_document(
|
||||
document=sample_documents[0],
|
||||
metadata={"user_id": "jordan_mitchell", "year": 2025, "status": "active"},
|
||||
recreate=True, # Set to True only for the first run, then set to False
|
||||
)
|
||||
|
||||
# Load second document with Taylor Brooks metadata
|
||||
knowledge_base.load_document(
|
||||
document=sample_documents[1],
|
||||
metadata={"user_id": "taylor_brooks", "year": 2025, "status": "active"},
|
||||
)
|
||||
|
||||
# Load third document with Morgan Lee metadata
|
||||
knowledge_base.load_document(
|
||||
document=sample_documents[2],
|
||||
metadata={"user_id": "morgan_lee", "year": 2025, "status": "active"},
|
||||
)
|
||||
|
||||
# Load fourth document with HR department metadata
|
||||
knowledge_base.load_document(
|
||||
document=sample_documents[3],
|
||||
metadata={"created_by": "hr_department", "year": 2025, "status": "current"},
|
||||
)
|
||||
|
||||
# Load fifth document with HR department metadata
|
||||
knowledge_base.load_document(
|
||||
document=sample_documents[4],
|
||||
metadata={"created_by": "hr_department", "year": 2025, "status": "current"},
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,91 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.docx import DocxKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.DOCX
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = DocxKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with Agent using filters from query automatically
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
# Enable agentic filtering
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills with filters in query so that Agent can automatically pick them up
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills with jordan_mitchell as user id and document type cv",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,116 +0,0 @@
|
||||
"""
|
||||
User-Level Knowledge Filtering Example
|
||||
|
||||
This cookbook demonstrates how to use knowledge filters to restrict knowledge base searches to specific users, document types, or any other metadata attributes.
|
||||
|
||||
Key concepts demonstrated:
|
||||
1. Loading documents with user-specific metadata
|
||||
2. Filtering knowledge base searches by user ID
|
||||
3. Combining multiple filter criteria
|
||||
4. Comparing results across different filter combinations
|
||||
|
||||
You can pass filters in the following ways:
|
||||
1. If you pass on Agent only, we use that for all runs
|
||||
2. If you pass on run/print_response only, we use that for that run
|
||||
3. If you pass on both, we override with the filters passed on run/print_response for that run
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.docx import DocxKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.DOCX
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb",
|
||||
)
|
||||
|
||||
# Now use the downloaded paths in knowledge base initialization
|
||||
knowledge_base = DocxKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
|
||||
# # Query for Taylor Brooks as a candidate
|
||||
# agent.print_response(
|
||||
# "Tell me about Taylor Brooks as a candidate",
|
||||
# knowledge_filters={"user_id": "taylor_brooks"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,86 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.docx import DocxKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.DOCX
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize the DocxKnowledgeBase
|
||||
knowledge_base = DocxKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[0],
|
||||
metadata={"user_id": "jordan_mitchell", "document_type": "cv", "year": 2025},
|
||||
recreate=True, # Set to True only for the first run, then set to False
|
||||
)
|
||||
|
||||
# Load second document with user_2 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[1],
|
||||
metadata={"user_id": "taylor_brooks", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_3 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[2],
|
||||
metadata={"user_id": "morgan_lee", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_4 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[3],
|
||||
metadata={"user_id": "casey_jordan", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_5 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[4],
|
||||
metadata={"user_id": "alex_rivera", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uncomment the example you want to run
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
# agent.print_response(
|
||||
# "Tell me about Jordan Mitchell's experience and skills",
|
||||
# knowledge_filters = {"user_id": "jordan_mitchell"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,122 +0,0 @@
|
||||
"""
|
||||
User-Level Knowledge Filtering Example
|
||||
|
||||
This cookbook demonstrates how to use knowledge filters to restrict knowledge base searches to specific users, document types, or any other metadata attributes.
|
||||
|
||||
Key concepts demonstrated:
|
||||
1. Loading documents with user-specific metadata
|
||||
2. Filtering knowledge base searches by user ID
|
||||
3. Combining multiple filter criteria
|
||||
4. Comparing results across different filter combinations
|
||||
|
||||
You can pass filters in the following ways:
|
||||
1. If you pass on Agent only, we use that for all runs
|
||||
2. If you pass on run/print_response only, we use that for that run
|
||||
3. If you pass on both, we override with the filters passed on run/print_response for that run
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.TXT
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=False,
|
||||
add_references=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# add_references=True,
|
||||
# search_knowledge=False,
|
||||
# )
|
||||
|
||||
# # Query for Taylor Brooks as a candidate
|
||||
# agent.print_response(
|
||||
# "Tell me about Taylor Brooks as a candidate",
|
||||
# knowledge_filters={"user_id": "taylor_brooks"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,91 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.JSON
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with Agent using filters from query automatically
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
# Enable agentic filtering
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills with filters in query so that Agent can automatically pick them up
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills with jordan_mitchell as user id and document type cv",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,95 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.JSON
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Load all documents into the vector database
|
||||
asyncio.run(knowledge_base.aload(recreate=True))
|
||||
|
||||
# Query for Alex Rivera's experience and skills
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
@@ -1,120 +0,0 @@
|
||||
"""
|
||||
User-Level Knowledge Filtering Example
|
||||
|
||||
This cookbook demonstrates how to use knowledge filters to restrict knowledge base searches to specific users, document types, or any other metadata attributes.
|
||||
|
||||
Key concepts demonstrated:
|
||||
1. Loading documents with user-specific metadata
|
||||
2. Filtering knowledge base searches by user ID
|
||||
3. Combining multiple filter criteria
|
||||
4. Comparing results across different filter combinations
|
||||
|
||||
You can pass filters in the following ways:
|
||||
1. If you pass on Agent only, we use that for all runs
|
||||
2. If you pass on run/print_response only, we use that for that run
|
||||
3. If you pass on both, we override with the filters passed on run/print_response for that run
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.JSON
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell' experience and skills
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
|
||||
# # Query for Taylor Brooks as a candidate
|
||||
# agent.print_response(
|
||||
# "Tell me about Taylor Brooks as a candidate",
|
||||
# knowledge_filters={"user_id": "taylor_brooks"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,86 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.JSON
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize the JSONKnowledgeBase
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[0],
|
||||
metadata={"user_id": "jordan_mitchell", "document_type": "cv", "year": 2025},
|
||||
recreate=True, # Set to True only for the first run, then set to False
|
||||
)
|
||||
|
||||
# Load second document with user_2 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[1],
|
||||
metadata={"user_id": "taylor_brooks", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_3 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[2],
|
||||
metadata={"user_id": "morgan_lee", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_4 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[3],
|
||||
metadata={"user_id": "casey_jordan", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_5 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[4],
|
||||
metadata={"user_id": "alex_rivera", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uncomment the example you want to run
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
# agent.print_response(
|
||||
# "Tell me about Jordan Mitchell's experience and skills",
|
||||
# knowledge_filters = {"user_id": "jordan_mitchell"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,91 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.PDF
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with Agent using filters from query automatically
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
# Enable agentic filtering
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills with filters in query so that Agent can automatically pick them up
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills with jordan_mitchell as user id and document type cv",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,95 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.PDF
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Load all documents into the vector database
|
||||
asyncio.run(knowledge_base.aload(recreate=True))
|
||||
|
||||
# Query for Alex Rivera's experience and skills
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
@@ -1,89 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.PDF
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,86 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.PDF
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize the PDFKnowledgeBase
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[0],
|
||||
metadata={"user_id": "jordan_mitchell", "document_type": "cv", "year": 2025},
|
||||
recreate=True, # Set to True only for the first run, then set to False
|
||||
)
|
||||
|
||||
# Load second document with user_2 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[1],
|
||||
metadata={"user_id": "taylor_brooks", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_3 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[2],
|
||||
metadata={"user_id": "morgan_lee", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_4 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[3],
|
||||
metadata={"user_id": "casey_jordan", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_5 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[4],
|
||||
metadata={"user_id": "alex_rivera", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uncomment the example you want to run
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
# agent.print_response(
|
||||
# "Tell me about Jordan Mitchell's experience and skills",
|
||||
# knowledge_filters = {"user_id": "jordan_mitchell"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,56 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with Agent using filters from query automatically
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
# Enable agentic filtering
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills with filters in query so that Agent can automatically pick them up
|
||||
agent.print_response(
|
||||
"How to make Pad Thai, refer from document with cuisine Thai and source Thai Cookbook",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,62 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Load all documents into the vector database
|
||||
asyncio.run(knowledge_base.aload(recreate=True))
|
||||
|
||||
# Query for Alex Rivera's experience and skills
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Tell me how to make Pad Thai",
|
||||
knowledge_filters={"cuisine": "Thai"},
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
@@ -1,89 +0,0 @@
|
||||
"""
|
||||
User-Level Knowledge Filtering Example with PDF URLs
|
||||
|
||||
This cookbook demonstrates how to use knowledge filters with PDF documents accessed via URLs,
|
||||
showing how to restrict knowledge base searches to specific cuisines, sources, or any other metadata attributes.
|
||||
|
||||
Key concepts demonstrated:
|
||||
1. Loading PDF documents from URLs with specific metadata
|
||||
2. Filtering knowledge base searches by cuisine type
|
||||
3. Combining multiple filter criteria
|
||||
4. Comparing results across different filter combinations
|
||||
|
||||
You can pass filters in the following ways:
|
||||
1. If you pass on Agent only, we use that for all runs
|
||||
2. If you pass on run/print_response only, we use that for that run
|
||||
3. If you pass on both, we override with the filters passed on run/print_response for that run
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with URLs and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include cuisine type, source, region, or any other attributes
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
# This will only return information from documents with Thai cuisine
|
||||
knowledge_filters={"cuisine": "Thai"},
|
||||
)
|
||||
|
||||
# Query for Thai recipes
|
||||
agent.print_response(
|
||||
"Tell me how to make Pad Thai",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
|
||||
# # Query for Cape Malay recipes
|
||||
# agent.print_response(
|
||||
# "Tell me how to make Cape Malay Curry",
|
||||
# knowledge_filters={"cuisine": "Cape"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,57 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize knowledge base
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
url="https://agno-public.s3.amazonaws.com/recipes/thai_recipes_short.pdf",
|
||||
metadata={"cuisine": "Thai", "source": "Thai Cookbook"},
|
||||
recreate=False, # only use at the first run, True/False
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
url="https://agno-public.s3.amazonaws.com/recipes/cape_recipes_short_2.pdf",
|
||||
metadata={"cuisine": "Cape", "source": "Cape Cookbook"},
|
||||
)
|
||||
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={
|
||||
"cuisine": "Thai"
|
||||
}, # This will only return information from documents associated with Thai cuisine
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me how to make Pad Thai",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
# agent.print_response(
|
||||
# "Tell me how to make Cape Malay Curry",
|
||||
# knowledge_filters={"cuisine": "Cape"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,91 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.TXT
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with Agent using filters from query automatically
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
# Enable agentic filtering
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
enable_agentic_knowledge_filters=True,
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills with filters in query so that Agent can automatically pick them up
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills with jordan_mitchell as user id and document type cv",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,95 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.TXT
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Load all documents into the vector database
|
||||
asyncio.run(knowledge_base.aload(recreate=True))
|
||||
|
||||
# Query for Alex Rivera's experience and skills
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
@@ -1,120 +0,0 @@
|
||||
"""
|
||||
User-Level Knowledge Filtering Example
|
||||
|
||||
This cookbook demonstrates how to use knowledge filters to restrict knowledge base searches to specific users, document types, or any other metadata attributes.
|
||||
|
||||
Key concepts demonstrated:
|
||||
1. Loading documents with user-specific metadata
|
||||
2. Filtering knowledge base searches by user ID
|
||||
3. Combining multiple filter criteria
|
||||
4. Comparing results across different filter combinations
|
||||
|
||||
You can pass filters in the following ways:
|
||||
1. If you pass on Agent only, we use that for all runs
|
||||
2. If you pass on run/print_response only, we use that for that run
|
||||
3. If you pass on both, we override with the filters passed on run/print_response for that run
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.TXT
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When initializing the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=[
|
||||
{
|
||||
"path": downloaded_cv_paths[0],
|
||||
"metadata": {
|
||||
"user_id": "jordan_mitchell",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[1],
|
||||
"metadata": {
|
||||
"user_id": "taylor_brooks",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[2],
|
||||
"metadata": {
|
||||
"user_id": "morgan_lee",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[3],
|
||||
"metadata": {
|
||||
"user_id": "casey_jordan",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": downloaded_cv_paths[4],
|
||||
"metadata": {
|
||||
"user_id": "alex_rivera",
|
||||
"document_type": "cv",
|
||||
"year": 2025,
|
||||
},
|
||||
},
|
||||
],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load all documents into the vector database
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base and filters
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
|
||||
# Query for Jordan Mitchell's experience and skills
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# # Option 2: Filters on the run/print_response
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
|
||||
# # Query for Taylor Brooks as a candidate
|
||||
# agent.print_response(
|
||||
# "Tell me about Taylor Brooks as a candidate",
|
||||
# knowledge_filters={"user_id": "taylor_brooks"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,86 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.utils.media import (
|
||||
SampleDataFileExtension,
|
||||
download_knowledge_filters_sample_data,
|
||||
)
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Download all sample CVs and get their paths
|
||||
downloaded_cv_paths = download_knowledge_filters_sample_data(
|
||||
num_files=5, file_extension=SampleDataFileExtension.TXT
|
||||
)
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Step 1: Initialize knowledge base with documents and metadata
|
||||
# ------------------------------------------------------------------------------
|
||||
# When loading the knowledge base, we can attach metadata that will be used for filtering
|
||||
# This metadata can include user IDs, document types, dates, or any other attributes
|
||||
|
||||
# Initialize the TextKnowledgeBase
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[0],
|
||||
metadata={"user_id": "jordan_mitchell", "document_type": "cv", "year": 2025},
|
||||
recreate=True, # Set to True only for the first run, then set to False
|
||||
)
|
||||
|
||||
# Load second document with user_2 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[1],
|
||||
metadata={"user_id": "taylor_brooks", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_3 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[2],
|
||||
metadata={"user_id": "morgan_lee", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_4 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[3],
|
||||
metadata={"user_id": "casey_jordan", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Load second document with user_5 metadata
|
||||
knowledge_base.load_document(
|
||||
path=downloaded_cv_paths[4],
|
||||
metadata={"user_id": "alex_rivera", "document_type": "cv", "year": 2025},
|
||||
)
|
||||
|
||||
# Step 2: Query the knowledge base with different filter combinations
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uncomment the example you want to run
|
||||
|
||||
# Option 1: Filters on the Agent
|
||||
# Initialize the Agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
knowledge_filters={"user_id": "jordan_mitchell"},
|
||||
)
|
||||
agent.print_response(
|
||||
"Tell me about Jordan Mitchell's experience and skills",
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# agent = Agent(
|
||||
# knowledge=knowledge_base,
|
||||
# search_knowledge=True,
|
||||
# )
|
||||
# agent.print_response(
|
||||
# "Tell me about Jordan Mitchell's experience and skills",
|
||||
# knowledge_filters = {"user_id": "jordan_mitchell"},
|
||||
# markdown=True,
|
||||
# )
|
||||
@@ -1,22 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.firecrawl import FireCrawlKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "website-content"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Create a knowledge base with the seed URLs
|
||||
knowledge_base = FireCrawlKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True, debug_mode=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
agent.print_response("How does agno work?", markdown=True)
|
||||
@@ -1,24 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.firecrawl import FireCrawlKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "website-content"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Create a knowledge base with the seed URLs
|
||||
knowledge_base = FireCrawlKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True, debug_mode=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
asyncio.run(agent.aprint_response("How does agno work?", markdown=True))
|
||||
@@ -1,29 +0,0 @@
|
||||
"""
|
||||
This agent answers questions using knowledge from a PDF stored in a Google Cloud Storage (GCS) bucket.
|
||||
|
||||
Setup Steps:
|
||||
1. Install required libraries: agno, google-cloud-storage, psycopg-binary (for PostgreSQL vector DB).
|
||||
2. Set up your GCS bucket and upload your PDF file.
|
||||
3. For public GCS buckets: No authentication needed, just set the bucket and PDF path.
|
||||
4. For private GCS buckets:
|
||||
- Grant the service account Storage Object Viewer access to the bucket via Google Cloud Console
|
||||
- Export GOOGLE_APPLICATION_CREDENTIALS with the path to your service account JSON before running the script
|
||||
5. Update 'bucket_name' and 'blob_name' in the script to your PDF's location.
|
||||
6. Run the script to load the knowledge base and ask questions.
|
||||
"""
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.gcs.pdf import GCSPDFKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = GCSPDFKnowledgeBase(
|
||||
bucket_name="your-gcs-bucket",
|
||||
blob_name="path/to/your.pdf",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,33 +0,0 @@
|
||||
"""
|
||||
This agent answers questions using knowledge from a PDF stored in a Google Cloud Storage (GCS) bucket.
|
||||
|
||||
Setup Steps:
|
||||
1. Install required libraries: agno, google-cloud-storage, psycopg-binary (for PostgreSQL vector DB).
|
||||
2. Set up your GCS bucket and upload your PDF file.
|
||||
3. For public GCS buckets: No authentication needed, just set the bucket and PDF path.
|
||||
4. For private GCS buckets:
|
||||
- Grant the service account Storage Object Viewer access to the bucket via Google Cloud Console
|
||||
- Export GOOGLE_APPLICATION_CREDENTIALS with the path to your service account JSON before running the script
|
||||
5. Update 'bucket_name' and 'blob_name' in the script to your PDF's location.
|
||||
6. Run the script to load the knowledge base and ask questions.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.gcs.pdf import GCSPDFKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = GCSPDFKnowledgeBase(
|
||||
bucket_name="your-gcs-bucket",
|
||||
blob_name="path/to/your.pdf",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(knowledge_base.aload(recreate=False)) # Comment out after first run
|
||||
|
||||
asyncio.run(agent.aprint_response("How to make Thai curry?", markdown=True))
|
||||
@@ -1,27 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
path=Path("tmp/docs"),
|
||||
vector_db=PgVector(
|
||||
table_name="json_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Use the agent
|
||||
agent.print_response("Ask me about something from the knowledge base", markdown=True)
|
||||
@@ -1,33 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.json import JSONKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "json-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
knowledge_base = JSONKnowledgeBase(
|
||||
path=Path("tmp/docs"),
|
||||
vector_db=vector_db,
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
|
||||
# Initialize the Agent with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"Ask anything from the json knowledge base", markdown=True
|
||||
)
|
||||
)
|
||||
@@ -1,32 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.markdown import MarkdownKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
|
||||
knowledge_base = MarkdownKnowledgeBase(
|
||||
path=Path("README.md"), # Path to your markdown file(s)
|
||||
vector_db=PgVector(
|
||||
table_name="markdown_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Initialize the Assistant with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the documents in the knowledge base
|
||||
agent.print_response(
|
||||
"What is a good way to get started with Agno?",
|
||||
markdown=True,
|
||||
)
|
||||
@@ -1,36 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.markdown import MarkdownKnowledgeBase
|
||||
from agno.vectordb.pgvector.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
|
||||
knowledge_base = MarkdownKnowledgeBase(
|
||||
path=Path("README.md"), # Path to your markdown file(s)
|
||||
vector_db=PgVector(
|
||||
table_name="markdown_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
|
||||
|
||||
# Initialize the Assistant with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# This is only needed during the first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"What knowledge is available in my knowledge base?",
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
@@ -1,24 +0,0 @@
|
||||
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) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Tom Kha Gai?", markdown=True)
|
||||
@@ -1,30 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Tom Kha Gai?", markdown=True))
|
||||
@@ -1,27 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the PDFs from the data/pdfs directory
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
path="data/pdfs",
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents",
|
||||
# Can inspect database via psql e.g. "psql -h localhost -p 5432 -U ai -d ai"
|
||||
db_url=db_url,
|
||||
),
|
||||
reader=PDFReader(chunk=True),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
agent.print_response("Ask me about something from the knowledge base", markdown=True)
|
||||
@@ -1,29 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "pdf-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Create a knowledge base with the PDFs from the data/pdfs directory
|
||||
knowledge_base = PDFKnowledgeBase(
|
||||
path="data/pdf", # for password-protected PDFs, use path=[{"path": "tmp/ThaiRecipes_protected.pdf", "password": "ThaiRecipes"}],
|
||||
vector_db=vector_db,
|
||||
reader=PDFReader(chunk=True),
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Thai curry?", markdown=True))
|
||||
@@ -1,30 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with simplified password handling
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=[
|
||||
{
|
||||
"url": "https://agno-public.s3.us-east-1.amazonaws.com/recipes/ThaiRecipes_protected.pdf",
|
||||
"password": "ThaiRecipes",
|
||||
}
|
||||
],
|
||||
vector_db=PgVector(
|
||||
table_name="pdf_documents_password",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=True)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
show_tool_calls=True,
|
||||
)
|
||||
|
||||
agent.print_response("Give me the recipe for pad thai")
|
||||
@@ -1,18 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
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", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,29 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase, PDFUrlReader
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "pdf-url-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Create a knowledge base with the PDFs from the data/pdfs directory
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
reader=PDFUrlReader(chunk=True),
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Thai curry?", markdown=True))
|
||||
@@ -1,15 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.s3.pdf import S3PDFKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = S3PDFKnowledgeBase(
|
||||
bucket_name="agno-public",
|
||||
key="recipes/ThaiRecipes.pdf",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,25 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.s3.pdf import S3PDFKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = S3PDFKnowledgeBase(
|
||||
bucket_name="agno-public",
|
||||
key="recipes/ThaiRecipes.pdf",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(agent.knowledge.aload(recreate=True))
|
||||
|
||||
asyncio.run(agent.aprint_response("How to make Thai curry?", markdown=True))
|
||||
@@ -1,15 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.s3.text import S3TextKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = S3TextKnowledgeBase(
|
||||
bucket_name="agno-public",
|
||||
key="recipes/recipes.docx",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
knowledge_base.load(recreate=True) # Comment out after first run
|
||||
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True)
|
||||
agent.print_response("How to make Hummus?", markdown=True)
|
||||
@@ -1,25 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.s3.text import S3TextKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
knowledge_base = S3TextKnowledgeBase(
|
||||
bucket_name="agno-public",
|
||||
key="recipes/recipes.docx",
|
||||
vector_db=PgVector(table_name="recipes", db_url=db_url),
|
||||
)
|
||||
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(agent.knowledge.aload(recreate=True))
|
||||
|
||||
asyncio.run(agent.aprint_response("How to make Hummus?", markdown=True))
|
||||
@@ -1,29 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
|
||||
# Initialize the TextKnowledgeBase
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=Path("data/docs"), # Table name: ai.text_documents
|
||||
vector_db=PgVector(
|
||||
table_name="text_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
num_documents=5, # Number of documents to return on search
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Initialize the Assistant with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Use the agent
|
||||
agent.print_response("Ask me about something from the knowledge base", markdown=True)
|
||||
@@ -1,33 +0,0 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.text import TextKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "essay-txt"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
# Initialize the TextKnowledgeBase
|
||||
knowledge_base = TextKnowledgeBase(
|
||||
path=Path("tmp/docs"),
|
||||
vector_db=vector_db,
|
||||
num_documents=5,
|
||||
)
|
||||
|
||||
# Initialize the Assistant with the knowledge_base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"What knowledge is available in my knowledge base?", markdown=True
|
||||
)
|
||||
)
|
||||
@@ -1,43 +0,0 @@
|
||||
"""Agent with Knowledge - An agent that can search a knowledge base
|
||||
|
||||
Install dependencies: `pip install openai lancedb tantivy agno`
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.url import UrlKnowledge
|
||||
from agno.models.openai import OpenAIChat
|
||||
from agno.vectordb.lancedb import LanceDb, SearchType
|
||||
|
||||
# Setup paths
|
||||
cwd = Path(__file__).parent
|
||||
tmp_dir = cwd.joinpath("tmp")
|
||||
tmp_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Initialize knowledge base
|
||||
agent_knowledge = UrlKnowledge(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
vector_db=LanceDb(
|
||||
uri=str(tmp_dir.joinpath("lancedb")),
|
||||
table_name="agno_assist_knowledge",
|
||||
search_type=SearchType.hybrid,
|
||||
),
|
||||
)
|
||||
|
||||
agent_with_knowledge = Agent(
|
||||
name="Agent with Knowledge",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
knowledge=agent_knowledge,
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
agent_knowledge.load()
|
||||
|
||||
agent_with_knowledge.print_response(
|
||||
"Tell me about teams with context to agno", stream=True
|
||||
)
|
||||
@@ -1,44 +0,0 @@
|
||||
"""Agent with Knowledge - An agent that can search a knowledge base
|
||||
|
||||
Install dependencies: `pip install openai lancedb tantivy agno`
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.url import UrlKnowledge
|
||||
from agno.models.openai import OpenAIChat
|
||||
from agno.vectordb.lancedb import LanceDb, SearchType
|
||||
|
||||
# Setup paths
|
||||
cwd = Path(__file__).parent
|
||||
tmp_dir = cwd.joinpath("tmp")
|
||||
tmp_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Initialize knowledge base
|
||||
agent_knowledge = UrlKnowledge(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
vector_db=LanceDb(
|
||||
uri=str(tmp_dir.joinpath("lancedb")),
|
||||
table_name="agno_assist_knowledge",
|
||||
search_type=SearchType.hybrid,
|
||||
),
|
||||
)
|
||||
|
||||
agent_with_knowledge = Agent(
|
||||
name="Agent with Knowledge",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
knowledge=agent_knowledge,
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(agent_knowledge.aload(recreate=False))
|
||||
|
||||
asyncio.run(
|
||||
agent_with_knowledge.aprint_response(
|
||||
"Tell me about teams with context to agno", stream=True
|
||||
)
|
||||
)
|
||||
@@ -1,177 +0,0 @@
|
||||
## Vector DBs
|
||||
Vector databases enable us to store information as embeddings and search for “results similar” to our input query using cosine similarity or full text search.
|
||||
|
||||
## Setup
|
||||
|
||||
### Create a virtual environment
|
||||
|
||||
```shell
|
||||
python3 -m venv ~/.venvs/aienv
|
||||
source ~/.venvs/aienv/bin/activate
|
||||
```
|
||||
|
||||
### Install libraries
|
||||
|
||||
```shell
|
||||
pip install -U qdrant-client pypdf openai agno
|
||||
```
|
||||
|
||||
## Test your VectorDB
|
||||
|
||||
### Cassandra DB
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/cassandra_db.py
|
||||
```
|
||||
|
||||
|
||||
### ChromaDB
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/chroma_db.py
|
||||
```
|
||||
|
||||
### Clickhouse
|
||||
|
||||
> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first.
|
||||
|
||||
- Run using a helper script
|
||||
|
||||
```shell
|
||||
./cookbook/run_clickhouse.sh
|
||||
```
|
||||
|
||||
- OR run using the docker run command
|
||||
|
||||
```shell
|
||||
docker run -d \
|
||||
-e CLICKHOUSE_DB=ai \
|
||||
-e CLICKHOUSE_USER=ai \
|
||||
-e CLICKHOUSE_PASSWORD=ai \
|
||||
-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
|
||||
-v clickhouse_data:/var/lib/clickhouse/ \
|
||||
-v clickhouse_log:/var/log/clickhouse-server/ \
|
||||
-p 8123:8123 \
|
||||
-p 9000:9000 \
|
||||
--ulimit nofile=262144:262144 \
|
||||
--name clickhouse-server \
|
||||
clickhouse/clickhouse-server
|
||||
```
|
||||
|
||||
#### Run the agent
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/clickhouse.py
|
||||
```
|
||||
|
||||
### LanceDB
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/lance_db.py
|
||||
```
|
||||
|
||||
### PgVector
|
||||
|
||||
> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first.
|
||||
|
||||
- Run using a helper script
|
||||
|
||||
```shell
|
||||
./cookbook/run_pgvector.sh
|
||||
```
|
||||
|
||||
- OR run using the docker run command
|
||||
|
||||
```shell
|
||||
docker run -d \
|
||||
-e POSTGRES_DB=ai \
|
||||
-e POSTGRES_USER=ai \
|
||||
-e POSTGRES_PASSWORD=ai \
|
||||
-e PGDATA=/var/lib/postgresql/data/pgdata \
|
||||
-v pgvolume:/var/lib/postgresql/data \
|
||||
-p 5532:5432 \
|
||||
--name pgvector \
|
||||
agnohq/pgvector:16
|
||||
```
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/pg_vector.py
|
||||
```
|
||||
|
||||
### Mem0
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/mem0.py
|
||||
```
|
||||
|
||||
### Milvus
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/milvus.py
|
||||
```
|
||||
|
||||
### Pinecone DB
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/pinecone_db.py
|
||||
```
|
||||
|
||||
### Singlestore
|
||||
|
||||
> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first.
|
||||
|
||||
#### Run the setup script
|
||||
```shell
|
||||
./cookbook/scripts/run_singlestore.sh
|
||||
```
|
||||
|
||||
#### Create the database
|
||||
|
||||
- Visit http://localhost:8080 and login with username: `root` and password: `admin`
|
||||
- Create the database with your choice of name. Default setup script requires AGNO as database name. `CREATE DATABASE your_database_name;`
|
||||
|
||||
#### Add credentials
|
||||
|
||||
- For SingleStore
|
||||
|
||||
```shell
|
||||
export SINGLESTORE_HOST="localhost"
|
||||
export SINGLESTORE_PORT="3306"
|
||||
export SINGLESTORE_USERNAME="root"
|
||||
export SINGLESTORE_PASSWORD="admin"
|
||||
export SINGLESTORE_DATABASE="your_database_name"
|
||||
export SINGLESTORE_SSL_CA=".certs/singlestore_bundle.pem"
|
||||
```
|
||||
|
||||
- Set your OPENAI_API_KEY
|
||||
|
||||
```shell
|
||||
export OPENAI_API_KEY="sk-..."
|
||||
```
|
||||
|
||||
#### Run Agent
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/singlestore.py
|
||||
```
|
||||
|
||||
|
||||
### Qdrant
|
||||
|
||||
```shell
|
||||
docker run -p 6333:6333 -p 6334:6334 -v $(pwd)/qdrant_storage:/qdrant/storage:z qdrant/qdrant
|
||||
```
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/qdrant_db.py
|
||||
```
|
||||
|
||||
### Weaviate
|
||||
|
||||
```shell
|
||||
./cookbook/scripts/run_weviate.sh
|
||||
```
|
||||
|
||||
```shell
|
||||
python cookbook/vector_dbs/weaviate_db.py
|
||||
```
|
||||
@@ -1,20 +0,0 @@
|
||||
# install chromadb - `pip install chromadb`
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.chroma import ChromaDb
|
||||
|
||||
# Initialize ChromaDB
|
||||
vector_db = ChromaDb(collection="recipes", path="tmp/chromadb", persistent_client=True)
|
||||
|
||||
# Create knowledge base
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
# Create and use the agent
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
agent.print_response("Show me how to make Tom Kha Gai", markdown=True)
|
||||
@@ -1,28 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.storage.agent.sqlite import SqliteAgentStorage
|
||||
from agno.vectordb.clickhouse import Clickhouse
|
||||
|
||||
agent = Agent(
|
||||
storage=SqliteAgentStorage(table_name="recipe_agent"),
|
||||
knowledge=PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=Clickhouse(
|
||||
table_name="recipe_documents",
|
||||
host="localhost",
|
||||
port=8123,
|
||||
username="ai",
|
||||
password="ai",
|
||||
),
|
||||
),
|
||||
# Show tool calls in the response
|
||||
show_tool_calls=True,
|
||||
# Enable the agent to search the knowledge base
|
||||
search_knowledge=True,
|
||||
# Enable the agent to read the chat history
|
||||
read_chat_history=True,
|
||||
)
|
||||
# Comment out after first run
|
||||
agent.knowledge.load(recreate=False) # type: ignore
|
||||
|
||||
agent.print_response("How do I make pad thai?", markdown=True)
|
||||
@@ -1,27 +0,0 @@
|
||||
# install lancedb - `pip install lancedb`
|
||||
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Create knowledge base
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(knowledge_base.aload(recreate=False)) # Comment out after first run
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
|
||||
@@ -1,24 +0,0 @@
|
||||
# install lancedb - `pip install lancedb`
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
|
||||
# Initialize LanceDB
|
||||
# By default, it stores data in /tmp/lancedb
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb", # You can change this path to store data elsewhere
|
||||
)
|
||||
|
||||
# Create knowledge base
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
# Create and use the agent
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
agent.print_response("How to make Tom Kha Gai", markdown=True)
|
||||
@@ -1,39 +0,0 @@
|
||||
import typer
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.lancedb import LanceDb
|
||||
from agno.vectordb.search import SearchType
|
||||
from rich.prompt import Prompt
|
||||
|
||||
vector_db = LanceDb(
|
||||
table_name="recipes",
|
||||
uri="tmp/lancedb",
|
||||
search_type=SearchType.hybrid,
|
||||
)
|
||||
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
|
||||
def lancedb_agent(user: str = "user"):
|
||||
agent = Agent(
|
||||
user_id=user,
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
show_tool_calls=True,
|
||||
)
|
||||
|
||||
while True:
|
||||
message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
|
||||
if message in ("exit", "bye"):
|
||||
break
|
||||
agent.print_response(message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
typer.run(lancedb_agent)
|
||||
@@ -1,23 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
vector_db = PgVector(table_name="recipes", db_url=db_url)
|
||||
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
|
||||
@@ -1,16 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
vector_db = PgVector(table_name="recipes", db_url=db_url)
|
||||
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
agent.print_response("How to make Thai curry?", markdown=True)
|
||||
@@ -1,39 +0,0 @@
|
||||
import asyncio
|
||||
from os import getenv
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.pineconedb import PineconeDb
|
||||
|
||||
api_key = getenv("PINECONE_API_KEY")
|
||||
index_name = "thai-recipe-index"
|
||||
|
||||
vector_db = PineconeDb(
|
||||
name=index_name,
|
||||
dimension=1536,
|
||||
metric="cosine",
|
||||
spec={"serverless": {"cloud": "aws", "region": "us-east-1"}},
|
||||
api_key=api_key,
|
||||
)
|
||||
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
# Show tool calls in the response
|
||||
show_tool_calls=True,
|
||||
# Enable the agent to search the knowledge base
|
||||
search_knowledge=True,
|
||||
# Enable the agent to read the chat history
|
||||
read_chat_history=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False, upsert=True))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
|
||||
@@ -1,18 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "thai-recipes"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
knowledge_base.load(recreate=False) # Comment out after first run
|
||||
|
||||
# Create and use the agent
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
agent.print_response("List down the ingredients to make Massaman Gai", markdown=True)
|
||||
@@ -1,30 +0,0 @@
|
||||
# install upstash-vector - `uv pip install upstash-vector`
|
||||
# Add OPENAI_API_KEY to your environment variables for the agent response
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.vectordb.upstashdb.upstashdb import UpstashVectorDb
|
||||
|
||||
# How to connect to an Upstash Vector index
|
||||
# - Create a new index in Upstash Console with the correct dimension
|
||||
# - Fetch the URL and token from Upstash Console
|
||||
# - Replace the values below or use environment variables
|
||||
|
||||
# Initialize Upstash DB
|
||||
vector_db = UpstashVectorDb(
|
||||
url="UPSTASH_VECTOR_REST_URL",
|
||||
token="UPSTASH_VECTOR_REST_TOKEN",
|
||||
)
|
||||
|
||||
# Create a new PDFUrlKnowledgeBase
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Load the knowledge base - after first run, comment out
|
||||
knowledge_base.load(recreate=False, upsert=True)
|
||||
|
||||
# Create and use the agent
|
||||
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
|
||||
agent.print_response("What are some tips for cooking glass noodles?", markdown=True)
|
||||
@@ -1,82 +0,0 @@
|
||||
"""
|
||||
This example demonstrates using Weaviate as a vector database.
|
||||
|
||||
Installation:
|
||||
pip install weaviate-client
|
||||
|
||||
You can use either Weaviate Cloud or a local instance.
|
||||
|
||||
Weaviate Cloud Setup:
|
||||
1. Create account at https://console.weaviate.cloud/
|
||||
2. Create a cluster and copy the "REST endpoint" and "Admin" API Key. Then set environment variables:
|
||||
export WCD_URL="your-cluster-url"
|
||||
export WCD_API_KEY="your-api-key"
|
||||
|
||||
Local Development Setup:
|
||||
1. Install Docker from https://docs.docker.com/get-docker/
|
||||
2. Run Weaviate locally:
|
||||
docker run -d \
|
||||
-p 8080:8080 \
|
||||
-p 50051:50051 \
|
||||
--name weaviate \
|
||||
cr.weaviate.io/semitechnologies/weaviate:1.28.4
|
||||
or use the script `cookbook/scripts/run_weviate.sh` to start a local instance.
|
||||
3. Remember to set `local=True` on the Weaviate instantiation.
|
||||
"""
|
||||
|
||||
from agno.document import Document
|
||||
from agno.embedder.sentence_transformer import SentenceTransformerEmbedder
|
||||
from agno.knowledge.document import DocumentKnowledgeBase
|
||||
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
|
||||
from agno.utils.log import set_log_level_to_debug
|
||||
from agno.vectordb.search import SearchType
|
||||
from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate
|
||||
|
||||
embedder = SentenceTransformerEmbedder()
|
||||
|
||||
vector_db = Weaviate(
|
||||
collection="recipes",
|
||||
search_type=SearchType.hybrid,
|
||||
vector_index=VectorIndex.HNSW,
|
||||
distance=Distance.COSINE,
|
||||
embedder=embedder,
|
||||
local=True, # Set to False if using Weaviate Cloud and True if using local instance
|
||||
)
|
||||
# Create knowledge base
|
||||
knowledge_base = PDFUrlKnowledgeBase(
|
||||
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
vector_db.drop()
|
||||
set_log_level_to_debug()
|
||||
|
||||
knowledge_base.load(recreate=False, upsert=True)
|
||||
|
||||
print(
|
||||
"Knowledge base loaded with PDF content. Loading the same data again will not recreate it."
|
||||
)
|
||||
knowledge_base.load(recreate=False, upsert=True)
|
||||
|
||||
print("First example finished. Now dropping the knowledge base.")
|
||||
vector_db.drop()
|
||||
|
||||
doc1 = Document(content="my first content", name="doc1")
|
||||
doc1_modified = Document(content="my first content corrected", name="doc1")
|
||||
doc2 = Document(content="my second content", name="doc2")
|
||||
|
||||
knowledge_base = DocumentKnowledgeBase(
|
||||
documents=[doc1, doc2],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
knowledge_base_changed = DocumentKnowledgeBase(
|
||||
documents=[doc1_modified, doc2],
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
print("\n\nStart second example. Load initial data...")
|
||||
knowledge_base.load(recreate=False, upsert=True)
|
||||
print("\nNow uploading the changed data...")
|
||||
knowledge_base_changed.load(recreate=False, upsert=True)
|
||||
print("Example finished. Now dropping the knowledge base.")
|
||||
vector_db.drop()
|
||||
@@ -1,28 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.website import WebsiteKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the seed URLs
|
||||
knowledge_base = WebsiteKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
# Number of links to follow from the seed URLs
|
||||
max_links=10,
|
||||
# Table name: ai.website_documents
|
||||
vector_db=PgVector(
|
||||
table_name="website_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
agent.print_response("How does agno work?")
|
||||
@@ -1,29 +0,0 @@
|
||||
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")
|
||||
|
||||
|
||||
# Create a knowledge base with the seed URLs
|
||||
knowledge_base = WebsiteKnowledgeBase(
|
||||
urls=["https://docs.agno.com/introduction"],
|
||||
# Number of links to follow from the seed URLs
|
||||
max_links=5,
|
||||
# Table name: ai.website_documents
|
||||
vector_db=vector_db,
|
||||
)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(knowledge=knowledge_base, search_knowledge=True, debug_mode=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(agent.aprint_response("How does agno work?", markdown=True))
|
||||
@@ -1,28 +0,0 @@
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.wikipedia import WikipediaKnowledgeBase
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
|
||||
|
||||
# Create a knowledge base with the PDFs from the data/pdfs directory
|
||||
knowledge_base = WikipediaKnowledgeBase(
|
||||
topics=["Manchester United", "Real Madrid"],
|
||||
# Table name: ai.wikipedia_documents
|
||||
vector_db=PgVector(
|
||||
table_name="wikipedia_documents",
|
||||
db_url=db_url,
|
||||
),
|
||||
)
|
||||
# Load the knowledge base
|
||||
knowledge_base.load(recreate=False)
|
||||
|
||||
# Create an agent with the knowledge base
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
# Ask the agent about the knowledge base
|
||||
agent.print_response(
|
||||
"Which team is objectively better, Manchester United or Real Madrid?"
|
||||
)
|
||||
@@ -1,26 +0,0 @@
|
||||
from os import getenv
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.youtube import YouTubeKnowledgeBase, YouTubeReader
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
api_key = getenv("QDRANT_API_KEY")
|
||||
qdrant_url = getenv("QDRANT_URL")
|
||||
|
||||
vector_db = Qdrant(collection="youtube-agno", url=qdrant_url, api_key=api_key)
|
||||
|
||||
knowledge_base = YouTubeKnowledgeBase(
|
||||
urls=["https://www.youtube.com/watch?v=CDC3GOuJyZ0"],
|
||||
vector_db=vector_db,
|
||||
reader=YouTubeReader(chunk=True),
|
||||
)
|
||||
knowledge_base.load(recreate=False) # only once, comment it out after first run
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
agent.print_response(
|
||||
"What is the major focus of the knowledge provided?", markdown=True
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from agno.agent import Agent
|
||||
from agno.knowledge.youtube import YouTubeKnowledgeBase, YouTubeReader
|
||||
from agno.vectordb.qdrant import Qdrant
|
||||
|
||||
COLLECTION_NAME = "youtube-reader"
|
||||
|
||||
vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
|
||||
|
||||
knowledge_base = YouTubeKnowledgeBase(
|
||||
urls=[
|
||||
"https://www.youtube.com/watch?v=CDC3GOuJyZ0",
|
||||
"https://www.youtube.com/watch?v=JbF_8g1EXj4",
|
||||
],
|
||||
vector_db=vector_db,
|
||||
reader=YouTubeReader(chunk=True),
|
||||
)
|
||||
|
||||
agent = Agent(
|
||||
knowledge=knowledge_base,
|
||||
search_knowledge=True,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Comment out after first run
|
||||
asyncio.run(knowledge_base.aload(recreate=False))
|
||||
|
||||
# Create and use the agent
|
||||
asyncio.run(
|
||||
agent.aprint_response(
|
||||
"What is the major focus of the knowledge provided in both the videos, explain briefly.",
|
||||
markdown=True,
|
||||
)
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user