The knowledge stack provides a modular, protocol-based architecture for building RAG (Retrieval-Augmented Generation) applications. Each component follows a protocol pattern with registries for extensibility.
from praisonaiagents.knowledge import QueryResultresult = QueryResult( answer="The answer based on context", sources=[{"text": "Source 1", "score": 0.9}], sub_questions=["What is X?", "What is Y?"], metadata={"mode": "sub_question"})
from praisonaiagents.knowledge import get_vector_store_registryregistry = get_vector_store_registry()# List available storesstores = registry.list_stores() # ['memory']# Get a storestore = registry.get("memory")# Register custom storeregistry.register("custom", MyCustomStore)
from praisonaiagents.knowledge.rerankers import SimpleRerankerreranker = SimpleReranker()results = reranker.rerank( query="Python programming", documents=["Python is great", "Java is different", "Python tutorial"], top_k=2)for r in results: print(f"{r.text}: {r.score}")
from praisonaiagents.knowledge.query_engine import SimpleQueryEngineengine = SimpleQueryEngine()result = engine.query( "What is Python?", context=["Python is a programming language."])print(result.answer)print(result.sources)
from praisonaiagents.knowledge.query_engine import SubQuestionEngineengine = SubQuestionEngine()result = engine.query( "What is Python and how to install it?", context=["Python is a language.", "Install with pip."])print(result.sub_questions) # ['What is Python?', 'How to install Python?']print(result.answer)
from praisonaiagents.knowledge.query_engine import decompose_questionquestions = decompose_question("What is X and what is Y?")# ['What is X?', 'What is Y?']