-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/phidatahq/phidata
- Loading branch information
Showing
22 changed files
with
722 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Close Stale Issues | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
close_stale_issues: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
|
||
steps: | ||
- name: Close stale issues | ||
uses: actions/stale@v5 | ||
with: | ||
stale-issue-message: > | ||
This issue has been marked as stale because it has been inactive | ||
for more than 14 days. Please update this issue or it will be | ||
automatically closed. | ||
days-before-issue-stale: 14 | ||
days-before-issue-close: 0 | ||
stale-issue-label: stale | ||
|
||
# Disable PR processing | ||
days-before-pr-stale: -1 | ||
days-before-pr-close: -1 | ||
|
||
# Only process issues, not PRs | ||
only-issue-labels: "*" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pathlib import Path | ||
|
||
from phi.agent import Agent | ||
from phi.knowledge.csv import CSVKnowledgeBase | ||
from phi.knowledge.pdf import PDFKnowledgeBase, PDFUrlKnowledgeBase | ||
from phi.knowledge.website import WebsiteKnowledgeBase | ||
from phi.knowledge.combined import CombinedKnowledgeBase | ||
from phi.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://phi-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.phidata.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_base=knowledge_base, | ||
add_references_to_prompt=True, | ||
) | ||
|
||
knowledge_base.load(recreate=False) | ||
|
||
# Use the agent | ||
agent.print_response("Ask me about something from the knowledge base", markdown=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pathlib import Path | ||
|
||
from phi.agent import Agent | ||
from phi.knowledge.csv import CSVKnowledgeBase | ||
from phi.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_base=knowledge_base, | ||
add_references_to_prompt=True, | ||
) | ||
|
||
# Use the agent | ||
agent.print_response("Ask me about something from the knowledge base", markdown=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pathlib import Path | ||
|
||
from phi.agent import Agent | ||
from phi.vectordb.pgvector import PgVector | ||
from phi.knowledge.docx import DocxKnowledgeBase | ||
|
||
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("data/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_base=knowledge_base, | ||
add_references_to_prompt=True, | ||
) | ||
|
||
# Ask the agent about the knowledge base | ||
agent.print_response("Ask me about something from the knowledge base", markdown=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Agentic RAG | ||
|
||
**RAG:** is a technique that allows an Agent to search for information to improve its responses. This directory contains a series of cookbooks that demonstrate how to build a RAG 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 openai sqlalchemy "psycopg[binary]" pgvector lancedb tantivy pypdf sqlalchemy "fastapi[standard]" phidata | ||
``` | ||
|
||
### 3. Run 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 \ | ||
phidata/pgvector:16 | ||
``` | ||
|
||
### 4. Run the Traditional RAG with PgVector | ||
|
||
```shell | ||
python cookbook/rag/01_traditional_rag_pgvector.py | ||
``` | ||
|
||
### 5. Run the Agentic RAG with PgVector | ||
|
||
```shell | ||
python cookbook/rag/02_agentic_rag_pgvector.py | ||
``` | ||
|
||
### 6. Run the Traditional RAG with LanceDB | ||
|
||
```shell | ||
python cookbook/rag/03_traditional_rag_lancedb.py | ||
``` | ||
|
||
### 7. Run the Agentic RAG with LanceDB | ||
|
||
```shell | ||
python cookbook/rag/04_agentic_rag_lancedb.py | ||
``` | ||
|
||
### 8. Run the Agentic RAG on Agent UI | ||
|
||
```shell | ||
python cookbook/rag/05_agentic_rag_agent_ui.py | ||
``` |
Oops, something went wrong.