1-line Knowledge, citations, and AutoRagAgent
Attach knowledge in one line and require source citations
PraisonAI wires retrieval straight into Agent(knowledge=[…]) or KnowledgeConfig. Instructing the agent to cite [doc_id] next to every claim lets users verify answers in one click and immediately exposes hallucinations.
Example
from praisonai import Agent
from praisonai.knowledge import KeywordIndex
idx = KeywordIndex()
idx.add_documents([
'[DOC-1] Enterprise SLA guarantees 99.95% monthly uptime.',
'[DOC-2] Standard support responds within 1 business day.',
])
hit = idx.query('uptime SLA', top_k=1)[0]['text']
cited = Agent(instructions='Answer using ONLY the provided Source and include its [DOC-x] tag.', output='silent')
print(cited.start(f'Source: {hit}\nQuestion: What is the uptime SLA?'))Example explained
- [DOC-1] citation tag — Forces verifiable source attribution on every factual claim.
- Agent(knowledge=['handbook.pdf']) — One-line production shorthand that chunks, embeds, and attaches files automatically.
AutoRagAgent for adaptive retrieval
When questions vary wildly in difficulty, AutoRagAgent automatically rewrites queries, tunes retrieval depth, and synthesizes multi-chunk answers without manual retrieval plumbing.
Example
from praisonai import Agent, AutoRagAgent
base = Agent(name='DocsExpert', instructions='Answer using retrieved documents only.')
rag_agent = AutoRagAgent(agent=base)
# Run locally once your knowledge base folder is indexed:
# print(rag_agent.chat('What is our uptime SLA?'))Example explained
- AutoRagAgent — Combines query rewriting, retrieval, and grounded synthesis in one specialized class.
Common pitfall: showing citations that weren't in retrieved chunks
In Python, verify every [DOC-x] tag in the agent's reply actually exists in the retrieved chunk list before showing it to users.
Reference: documentation