Mini-project: Evaluated multi-document knowledge assistant
Index multiple documents, cite sources, refuse unknowns, and score faithfulness
Combine every lesson in the RAG course into one verifiable assistant: index 3 company docs, answer in-scope questions with citations, short-circuit out-of-scope questions with 'Not in the docs', and assert 100% pass rate on your test suite.
Example
from praisonai import Agent
from praisonai.knowledge import KeywordIndex
idx = KeywordIndex()
idx.add_documents([
'[SEC-1] API keys rotate every 90 days via Security Portal.',
'[BILL-2] Annual plans receive a 20% discount paid upfront.',
])
assistant = Agent(instructions='Answer strictly from Source in one sentence with its [TAG].', output='silent')
def ask(question: str) -> str:
hits = [h for h in idx.query(question, top_k=1) if h.get('score', 0) > 0.5]
if not hits:
return 'Not in the docs.'
return assistant.start(f"Source: {hits[0]['text']}\nQuestion: {question}")
print('In-scope :', ask('How often do API keys rotate?'))
print('Out-scope:', ask('CEO favorite espresso brand?'))Example explained
- if not hits: return 'Not in the docs.' — Deterministic short-circuit that makes hallucinating out-of-scope answers impossible.
- assert '[SEC-1]' in a1 — Automated faithfulness check verifying real citation grounding.
Next course: Memory
RAG answers from shared documents. Head to Memory next to teach your agents how to remember per-user preferences, compact long histories, and restore session checkpoints.
Reference: documentation