RAG Query • AI Agent SDK

rag_query: Query knowledge using RAG pipeline with citations.

rag_query

Method

</div>

This is a method of the Agent class in the agent module.

Query knowledge using RAG pipeline with citations.

This is the recommended way to get answers with citations from an agent’s knowledge.

Signature

python
def rag_query(question: str) -> 'RAGResult'

Parameters

ParamField str

The question to answer **kwargs: Additional arguments passed to RAG.query()

Returns

ResponseField 'RAGResult'

RAGResult with answer, citations, context_used, and metadata

Exceptions

ValueError

If no knowledge sources are configured

ImportError

If RAG module is not available

Usage

python
agent = Agent(knowledge=["doc.pdf"], rag_config={"include_citations": True})
    result = agent.rag_query("What is the main finding?")
    print(result.answer)
    for citation in result.citations:
        print(f"[{citation.id}] {citation.source}: {citation.text[:100]}")

Uses

  • ValueError
  • ImportError
  • kwargs.setdefault
  • query

Source

View on GitHub

praisonaiagents/agent/agent.py at line 6895


Related Documentation