|
| 1 | +import asyncio |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from agno.agent import Agent |
| 5 | +from agno.knowledge.combined import CombinedKnowledgeBase |
| 6 | +from agno.knowledge.csv import CSVKnowledgeBase |
| 7 | +from agno.knowledge.pdf import PDFKnowledgeBase |
| 8 | +from agno.knowledge.pdf_url import PDFUrlKnowledgeBase |
| 9 | +from agno.knowledge.website import WebsiteKnowledgeBase |
| 10 | +from agno.vectordb.pgvector import PgVector |
| 11 | + |
| 12 | +db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai" |
| 13 | + |
| 14 | +# Create CSV knowledge base |
| 15 | +csv_kb = CSVKnowledgeBase( |
| 16 | + path=Path("data/csvs"), |
| 17 | + vector_db=PgVector( |
| 18 | + table_name="csv_documents", |
| 19 | + db_url=db_url, |
| 20 | + ), |
| 21 | +) |
| 22 | + |
| 23 | +# Create PDF URL knowledge base |
| 24 | +pdf_url_kb = PDFUrlKnowledgeBase( |
| 25 | + urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], |
| 26 | + vector_db=PgVector( |
| 27 | + table_name="pdf_documents", |
| 28 | + db_url=db_url, |
| 29 | + ), |
| 30 | +) |
| 31 | + |
| 32 | +# Create Website knowledge base |
| 33 | +website_kb = WebsiteKnowledgeBase( |
| 34 | + urls=["https://docs.agno.com/introduction"], |
| 35 | + max_links=10, |
| 36 | + vector_db=PgVector( |
| 37 | + table_name="website_documents", |
| 38 | + db_url=db_url, |
| 39 | + ), |
| 40 | +) |
| 41 | + |
| 42 | +# Create Local PDF knowledge base |
| 43 | +local_pdf_kb = PDFKnowledgeBase( |
| 44 | + path="data/pdfs", |
| 45 | + vector_db=PgVector( |
| 46 | + table_name="pdf_documents", |
| 47 | + db_url=db_url, |
| 48 | + ), |
| 49 | +) |
| 50 | + |
| 51 | +# Combine knowledge bases |
| 52 | +knowledge_base = CombinedKnowledgeBase( |
| 53 | + sources=[ |
| 54 | + csv_kb, |
| 55 | + pdf_url_kb, |
| 56 | + website_kb, |
| 57 | + local_pdf_kb, |
| 58 | + ], |
| 59 | + vector_db=PgVector( |
| 60 | + table_name="combined_documents", |
| 61 | + db_url=db_url, |
| 62 | + ), |
| 63 | +) |
| 64 | + |
| 65 | +# Initialize the Agent with the combined knowledge base |
| 66 | +agent = Agent( |
| 67 | + knowledge=knowledge_base, |
| 68 | + search_knowledge=True, |
| 69 | +) |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + # Comment out after first run |
| 73 | + asyncio.run(knowledge_base.aload(recreate=False)) |
| 74 | + |
| 75 | + # Create and use the agent |
| 76 | + asyncio.run( |
| 77 | + agent.aprint_response( |
| 78 | + "Ask me about something from the knowledge base", markdown=True |
| 79 | + ) |
| 80 | + ) |
0 commit comments