-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
combined_kb.py
72 lines (62 loc) · 1.7 KB
/
combined_kb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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=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)