The knowledge system provides sophisticated document processing and semantic search capabilities, enabling agents to access and utilise information from various sources.
When used with agents, knowledge automatically integrates with memory:
Copy
agent = Agent( name="Research Assistant", knowledge=["papers/"], # Directory of papers knowledge_config=config, memory=True # Enable memory integration)# Knowledge is automatically searched during conversationsresponse = agent.chat("What does the research say about transformers?")
# Find related conceptsresults = kb.search_graph( "What concepts are related to transformers?", user_id="user123")# Explore connectionsresults = kb.search_graph( "How is attention mechanism connected to BERT?", user_id="user123")
from praisonaiagents import Agentfrom praisonaiagents.knowledge import Knowledge# Configure knowledge baseknowledge_config = { "vector_store": { "provider": "chroma", "config": { "collection_name": "research_papers", "path": "./knowledge_db" } }, "chunker": { "name": "semantic", "threshold": 0.7 }, "embedder": { "provider": "openai", "config": { "model": "text-embedding-3-small" } }, "reranker": { "enabled": True }}# Create research assistantresearch_agent = Agent( name="Research Assistant", instructions="""You are an expert research assistant. Use the knowledge base to provide accurate, well-sourced answers. Always cite the specific documents you reference.""", knowledge=[ "papers/ai_safety.pdf", "papers/llm_alignment.pdf", "https://arxiv.org/pdf/2301.00234.pdf" ], knowledge_config=knowledge_config, knowledge_sources=["research_papers"], # Named source markdown=True)# Use the assistantresponse = research_agent.chat( "What are the main approaches to AI alignment?")# Direct knowledge querieskb = research_agent.knowledge_instancepapers = kb.search("alignment techniques", limit=5)for paper in papers: print(f"- {paper['text'][:100]}...") print(f" Source: {paper.get('metadata', {}).get('source')}")