Skip to main content

query

Method
This is a method of the Agent class in the agent module.
Query knowledge and get a structured answer with citations. This is the recommended method for getting answers with source citations. Returns a structured result with answer, citations, context used, and metadata.

Signature

def query(question: str) -> 'RAGResult'

Parameters

question
str
required
The question to answer **kwargs: Additional arguments (top_k, rerank, etc.)

Returns

Returns
'RAGResult'
RAGResult with answer, citations, context_used, and metadata

Exceptions

If no knowledge is configured
If RAG module is not available

Usage

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